Commit e246826c authored by jetrii's avatar jetrii
Browse files

Initial commit of Coherence-Config, a cross-platform GUI frontend.

[[
This repository was converted from Subversion to Git on 2013-08-10 by
Hartmut Goebel <h.goebel@crazy-compilers.com>. Here and elsewhere,
conversion notes are enclosed in double square brackets.

The original Coherence multi-project repository has carefully been
split into separate repositories for each sub-project.
]]
parents
import sys
from subprocess import check_call, PIPE, CalledProcessError, STDOUT
#Check dependencies
if sys.platform == "linux2":
try:
from PyQt4 import QtGui,QtCore
except:
print "\nError: You do not have the required dependencies installed on your system."
print "*Missing dependency: PyQt*"
print "Check the included documentation for more information"
sys.exit(1)
try:
output = check_call(["daemon"], stdout=PIPE, stderr=STDOUT)
except CalledProcessError:
pass #installed
except OSError:
print "\nError: You do not have the required dependencies installed on your system."
print "*Missing dependency: Daemon*"
print "Check the included documentation for more information"
sys.exit(1)
from UI.ConfigWindow import ConfigWindow
app = QtGui.QApplication(sys.argv)
window = ConfigWindow()
window.show()
sys.exit(app.exec_())
from subprocess import call, check_call, Popen, PIPE, CalledProcessError
import sys
from PyQt4 import QtGui
#Windows code is in my flash drive... Back home... Will be updated within a few days
class OSHandle:
def __init__(self):
if sys.platform == "linux2":
self.onLinux = True
def isCoherenceRunning(self):
if(self.onLinux):
output = Popen(["ps", "-C", "coherence"], stdout=PIPE).communicate()[0]
result = output.find("coherence")
if result > 0:
return True
else:
return False
def startCoherence(self):
if(self.onLinux):
if not self.isCoherenceRunning():
Popen(["daemon", "coherence"])
def stopCoherence(self):
if(self.onLinux):
if self.isCoherenceRunning():
try:
check_call(["killall", "coherence"])
except CalledProcessError:
QtGui.QMessageBox.critical(None, "Error", "Unable to stop Coherence. The operation is not permitted")
import sys, random
from PyQt4 import QtGui, QtCore
from MediaConfigPanel import MediaConfigPanel
from XMLDirector import XMLDirector
from SettingsConfigPanel import SettingsConfigPanel
from HomeConfigPanel import HomeConfigPanel
from ServicesConfigPanel import ServicesConfigPanel
from DeviceConfigPanel import DeviceConfigPanel
class ConfigWindow(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
#Load XML configuration
self.configManager = XMLDirector()
self.configManager.loadXMLConfiguration()
#setup main window
self.setWindowTitle("Coherence Config")
self.resize(650,350)
self.setMinimumSize(650,350)
screen = QtGui.QDesktopWidget().screenGeometry()
self.move((screen.width()-self.width())/2, (screen.height()-self.height())/2)
self.setWindowIcon(QtGui.QIcon("Icons/AppIcon.png"))
#Category label
self.categoryLabel = QtGui.QLabel("Category", self)
labelFont = QtGui.QFont()
labelFont.setFamily("DejaVu Sans")
labelFont.setPointSize(14)
labelFont.setWeight(75)
labelFont.setBold(True)
self.categoryLabel.setFont(labelFont)
self.categoryLabel.setStyleSheet("color: rgb(114, 159, 207);")
self.categoryLabel.move(10,10)
#Navigation Buttons
#Local Content
self.lcButton = QtGui.QCommandLinkButton("Local Content", self)
self.lcButton.setGeometry(5,40,150,30)
self.lcButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.lcButton.setIcon(QtGui.QIcon("Icons/house.png"))
self.connect(self.lcButton, QtCore.SIGNAL("clicked()"), self.showLocalContentPanel)
#Home content
self.hcButton = QtGui.QCommandLinkButton("Home Content", self)
self.hcButton.setGeometry(5,80,150,30)
self.hcButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.hcButton.setIcon(QtGui.QIcon("Icons/transmit.png"))
self.connect(self.hcButton, QtCore.SIGNAL("clicked()"), self.showHomeContentPanel)
self.hide()
#Home Devices
self.hdButton = QtGui.QCommandLinkButton("Home Devices", self)
self.hdButton.setGeometry(5,120,150,30)
self.hdButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.hdButton.setIcon(QtGui.QIcon("Icons/devices.png"))
self.connect(self.hdButton, QtCore.SIGNAL("clicked()"), self.showDeviceConfigPanel)
#On-line services
self.osButton = QtGui.QCommandLinkButton("Online Services", self)
self.osButton.setGeometry(5,160,150,30)
self.osButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.osButton.setIcon(QtGui.QIcon("Icons/services.png"))
self.connect(self.osButton, QtCore.SIGNAL("clicked()"), self.showServicesConfigPanel)
#settings button
self.settingsButton = QtGui.QCommandLinkButton("Edit Settings", self)
self.settingsButton.setGeometry(5,200,150,30)
self.settingsButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.settingsButton.setIcon(QtGui.QIcon("Icons/cog.png"))
self.connect(self.settingsButton, QtCore.SIGNAL("clicked()"), self.showSettingsConfigPanel)
#close button
self.closeButton = QtGui.QPushButton("Close Window", self)
self.closeButton.setGeometry(5,self.height()-40,150,30)
self.closeButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.closeButton.setIcon(QtGui.QIcon("Icons/cross.png"))
self.connect(self.closeButton, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('close()'))
#Local Content Panel
self.localContentPanel = MediaConfigPanel(self)
self.localContentPanel.setGeometry(160,0,self.width()-160,self.height())
folderList, isActive = self.configManager.getLocalContentlist()
self.localContentPanel.initializeState(folderList, isActive)
#Home Content Panel
self.homeContentPanel = HomeConfigPanel(self)
self.homeContentPanel.setGeometry(160,0,self.width()-160,self.height())
#Device config panel
self.deviceConfigPanel = DeviceConfigPanel(self)
self.deviceConfigPanel.setGeometry(160,0,self.width()-160,self.height())
#Online services
self.servicesConfigPanel = ServicesConfigPanel(self)
self.servicesConfigPanel.setGeometry(160,0,self.width()-160,self.height())
#Settings config panel
self.settingsConfigPanel = SettingsConfigPanel(self)
self.settingsConfigPanel.setGeometry(160,0,self.width()-160,self.height())
settings = self.configManager.getSettingsConfig()
self.settingsConfigPanel.initializeSettings(settings)
self.showLocalContentPanel()
#Resize the components
def resizeEvent(self,event):
self.localContentPanel.setGeometry(160,0,self.width()-160,self.height())
self.homeContentPanel.setGeometry(160,0,self.width()-160,self.height())
self.deviceConfigPanel.setGeometry(160,0,self.width()-160,self.height())
self.servicesConfigPanel.setGeometry(160,0,self.width()-160,self.height())
self.settingsConfigPanel.setGeometry(160,0,self.width()-160,self.height())
self.closeButton.move(5,self.height()-40)
#called by local content button
def showLocalContentPanel(self):
self.hideAllPanels()
self.localContentPanel.show()
self.localContentPanel.moveComponents()
def showHomeContentPanel(self):
self.hideAllPanels()
self.homeContentPanel.show()
self.homeContentPanel.moveComponents()
def showDeviceConfigPanel(self):
self.hideAllPanels()
self.deviceConfigPanel.show()
self.deviceConfigPanel.moveComponents()
def showServicesConfigPanel(self):
self.hideAllPanels()
self.servicesConfigPanel.show()
self.servicesConfigPanel.moveComponents()
def showSettingsConfigPanel(self):
self.hideAllPanels()
self.settingsConfigPanel.moveComponents()
self.settingsConfigPanel.show()
def hideAllPanels(self):
self.localContentPanel.hide()
self.homeContentPanel.hide()
self.deviceConfigPanel.hide()
self.servicesConfigPanel.hide()
self.settingsConfigPanel.hide()
def closeEvent(self, event):
result = QtGui.QMessageBox.question(self, "Exit?", "Do you want to exit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if result == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
from PyQt4 import QtGui, QtCore
class DeviceConfigPanel(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
#Status
self.errorMessage = QtGui.QCommandLinkButton("The Device browser has not been fully implemented yet.", self)
self.errorMessage.resize(500,60)
self.errorMessage.setIcon(QtGui.QIcon("Icons/cross.png"))
self.errorMessage.setEnabled(False)
def resizeEvent(self,event):
self.moveComponents()
def moveComponents(self):
self.errorMessage.move(self.width()/2-240, self.height()/2-30)
def paintEvent(self, event):
paint = QtGui.QPainter()
paint.begin(self)
size = self.size()
w = size.width()
h = size.height()
paint.setPen(QtGui.QColor(200,200, 200))
paint.setBrush(QtGui.QColor(235, 235, 235))
paint.drawRect(0,0,w,h)
paint.end()
from PyQt4 import QtGui, QtCore
class HomeConfigPanel(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
#Status
self.errorMessage = QtGui.QCommandLinkButton("The Home Content browser has not been fully implemented yet.", self)
self.errorMessage.resize(500,60)
self.errorMessage.setIcon(QtGui.QIcon("Icons/cross.png"))
self.errorMessage.setEnabled(False)
def resizeEvent(self,event):
self.moveComponents()
def moveComponents(self):
self.errorMessage.move(self.width()/2-240, self.height()/2-30)
def paintEvent(self, event):
paint = QtGui.QPainter()
paint.begin(self)
size = self.size()
w = size.width()
h = size.height()
paint.setPen(QtGui.QColor(200,200, 200))
paint.setBrush(QtGui.QColor(235, 235, 235))
paint.drawRect(0,0,w,h)
paint.end()
import sys
from PyQt4 import QtGui, QtCore
from XMLDirector import XMLDirector
class MediaConfigPanel(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
#default size = 490 x 350
#Sharing checkbox
self.enabledCheckbox = QtGui.QCheckBox("Enable Local Content", self)
self.enabledCheckbox.setChecked(True)
self.enabledCheckbox.setFocusPolicy(QtCore.Qt.NoFocus)
#media List
self.mediaList = QtGui.QListWidget(self)
self.mediaList.resize(400, 200)
self.mediaList.setViewMode(self.mediaList.IconMode)
self.mediaList.setDragEnabled(0)
self.mediaList.setSpacing(22)
self.mediaList.iconSize().setHeight(32)
self.mediaList.iconSize().setWidth(32)
#Apply button
self.applyButton = QtGui.QPushButton("Apply", self)
self.applyButton.setIcon(QtGui.QIcon("Icons/apply.png"))
self.applyButton.resize(150,30)
self.connect(self.applyButton, QtCore.SIGNAL("clicked()"), self.saveChanges)
self.applyButton.setEnabled(False)
#Add Button
self.addButton = QtGui.QPushButton("Add Folder", self)
self.addButton.setIcon(QtGui.QIcon("Icons/add.png"))
self.addButton.resize(130,25)
self.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addFolder)
#remove Button
self.removeButton = QtGui.QPushButton("Remove Folder", self)
self.removeButton.setIcon(QtGui.QIcon("Icons/cross.png"))
self.removeButton.resize(130, 25)
self.connect(self.removeButton, QtCore.SIGNAL("clicked()"), self.removeFolder)
#Update Ui state
def initializeState(self, folderList, isActive):
self.enabledCheckbox.setChecked(isActive)
#setup the content
for i in folderList:
exactFolderName = i.split("/")[-1]
itemIcon = self.getFolderIcon(str(exactFolderName))
item = QtGui.QListWidgetItem(itemIcon, exactFolderName)
item.setToolTip("<b>Location:</b>" + i)
self.mediaList.addItem(item)
def removeFolder(self):
if self.mediaList.currentItem() == None:
return
question = "Do you want to remove "+self.mediaList.currentItem().toolTip()
confirm = QtGui.QMessageBox.question(self, "Delete Item?", question, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if confirm == QtGui.QMessageBox.Yes:
item = self.mediaList.takeItem(self.mediaList.currentRow())
item = None
self.applyButton.setEnabled(True)
def addFolder(self):
fileDialog = QtGui.QFileDialog()
fileDialog.setFileMode(fileDialog.DirectoryOnly)
directoryName = fileDialog.getExistingDirectory(self, 'Select Directory','/')
if len(directoryName) <= 0:
return
exactFolderName = directoryName.split("/")[-1]
self.getFolderIcon(str(exactFolderName))
itemIcon = self.getFolderIcon(str(exactFolderName))
item = QtGui.QListWidgetItem(itemIcon, exactFolderName)
item.setToolTip("<b>Location:</b>" + directoryName)
self.mediaList.addItem(item)
self.applyButton.setEnabled(True)
def saveChanges(self):
configManager = XMLDirector()
configManager.loadXMLConfiguration()
folders = []
#get the folder paths and remove <b>location:<b> junk
for i in range(0, self.mediaList.count()):
item = self.mediaList.item(i)
path = item.toolTip()[16:]
folders.append(path)
if self.enabledCheckbox.isChecked():
isActive = "yes"
else:
isActive = "no"
configManager.writeLocalContentList(folders, isActive)
self.applyButton.setEnabled(False)
def resizeEvent(self,event):
self.moveComponents()
#Repositon UI components.
def moveComponents(self):
self.enabledCheckbox.move((self.width() - self.enabledCheckbox.width())/2, 10)
self.mediaList.setGeometry(45,40, self.width()-90,self.height() * 0.57)
buttonY = self.mediaList.x() + self.mediaList.height()+5
self.addButton.move(self.mediaList.x()+(self.mediaList.width()/2)-self.addButton.width() -5,buttonY)
self.removeButton.move(self.mediaList.x()+(self.mediaList.width()/2) +5,buttonY)
self.applyButton.move(self.width()-160, self.height()-40)
def paintEvent(self, event):
paint = QtGui.QPainter()
paint.begin(self)
size = self.size()
w = size.width()
h = size.height()
paint.setPen(QtGui.QColor(200,200, 200))
paint.setBrush(QtGui.QColor(235, 235, 235))
paint.drawRect(0,0,w,h)
paint.end()
def getFolderIcon(self, name):
#Attempt to assign every folder a proper icon or default to empty folder
icon = "folder"
name = name.lower()
videoList = ("movie", "vid", "celluloid", "cine", "film", "rip", "dvd", "show", "tv", "divx", "avi", "mpg", "mpeg",
"season", "imdb")
musicList = ("music", "sound", "song", "audio", "noise", "acoustic", "intrumental", "sing", "tune", "radio",
"mp4", "mp3")
imageList = ("pic", "image", "photo", "art", "draw", "illustration", "paint", "sketch", "flickr", "gif", "png", "jpg",
"jpeg", "portrait")
if icon == "folder":
for i in videoList:
if i in name:
icon = "film"
if icon == "folder":
for i in musicList:
if i in name:
icon = "music"
if icon == "folder":
for i in imageList:
if i in name:
icon = "picture"
return QtGui.QIcon("Icons/"+icon+".png")
from PyQt4 import QtGui, QtCore
class ServicesConfigPanel(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
#Status
self.errorMessage = QtGui.QCommandLinkButton("The Online Services browser has not been fully implemented yet.", self)
self.errorMessage.resize(500,60)
self.errorMessage.setIcon(QtGui.QIcon("Icons/cross.png"))
self.errorMessage.setEnabled(False)
def resizeEvent(self,event):
self.moveComponents()
def moveComponents(self):
self.errorMessage.move(self.width()/2-240, self.height()/2-30)
def paintEvent(self, event):
paint = QtGui.QPainter()
paint.begin(self)
size = self.size()
w = size.width()
h = size.height()
paint.setPen(QtGui.QColor(200,200, 200))
paint.setBrush(QtGui.QColor(235, 235, 235))
paint.drawRect(0,0,w,h)
paint.end()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment