Commit 8f0f9345 authored by jetrii's avatar jetrii
Browse files

Finished settings UI and polished XMLDirector's code

parent 3fa003f7
from subprocess import call, check_call, Popen, PIPE, CalledProcessError
import sys
from PyQt4 import QtGui
from PyQt4 import QtGui, QtCore
#Windows code is in my flash drive... Back home... Will be updated within a few days
#Handles OS <---> Coherence interactions
class OSHandle:
def __init__(self):
if sys.platform == "linux2":
self.onLinux = True
self.tempTimer = QtCore.QTimer()
def isCoherenceRunning(self):
if(self.onLinux):
output = Popen(["ps", "-C", "coherence"], stdout=PIPE).communicate()[0]
......@@ -30,4 +33,13 @@ class OSHandle:
except CalledProcessError:
QtGui.QMessageBox.critical(None, "Error", "Unable to stop Coherence. The operation is not permitted")
def warnAboutRestart(self):
if self.isCoherenceRunning():
message = "Your Changes will not take effect until Coherence is restarted."
QtGui.QMessageBox.question(None, "Coherence is currently running", message)
......@@ -83,8 +83,8 @@ class ConfigWindow(QtGui.QWidget):
#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)
settings = self.configManager.getLocalContentlist()
self.localContentPanel.initializeState(settings)
#Home Content Panel
self.homeContentPanel = HomeConfigPanel(self)
......@@ -105,9 +105,6 @@ class ConfigWindow(QtGui.QWidget):
self.settingsConfigPanel.initializeSettings(settings)
self.showLocalContentPanel()
#Resize the components
......
......@@ -8,7 +8,6 @@ class MediaConfigPanel(QtGui.QWidget):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
#default size = 490 x 350
#Sharing checkbox
......@@ -30,7 +29,6 @@ class MediaConfigPanel(QtGui.QWidget):
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)
......@@ -46,10 +44,11 @@ class MediaConfigPanel(QtGui.QWidget):
#Update Ui state
def initializeState(self, folderList, isActive):
def initializeState(self, settings):
self.enabledCheckbox.setChecked(isActive)
self.enabledCheckbox.setChecked(settings['isActive'])
folderList = settings['contentList']
#setup the content
for i in folderList:
exactFolderName = i.split("/")[-1]
......@@ -69,8 +68,6 @@ class MediaConfigPanel(QtGui.QWidget):
if confirm == QtGui.QMessageBox.Yes:
item = self.mediaList.takeItem(self.mediaList.currentRow())
item = None
self.applyButton.setEnabled(True)
def addFolder(self):
......@@ -88,29 +85,25 @@ class MediaConfigPanel(QtGui.QWidget):
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 = []
contentList = []
#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)
contentList.append(path)
if self.enabledCheckbox.isChecked():
isActive = "yes"
else:
isActive = "no"
configManager.writeLocalContentList(folders, isActive)
self.applyButton.setEnabled(False)
isActive= "yes" if self.enabledCheckbox.isChecked() else "no"
settings = {'contentList':contentList, 'isActive':isActive}
configManager.writeLocalContentList(settings)
#Warn about required restart
osHandle = OSHandle()
......@@ -143,6 +136,9 @@ class MediaConfigPanel(QtGui.QWidget):
paint.end()
def enableApplyButton(self):
self.applyButton.setEnabled(True)
def getFolderIcon(self, name):
#Attempt to assign every folder a proper icon or default to empty folder
icon = "folder"
......
......@@ -11,8 +11,7 @@ class SettingsConfigPanel(QtGui.QWidget):
self.timer = QtCore.QTimer()
#Status
#Status Label
self.coherenceStatus = QtGui.QCommandLinkButton("Coherence Status", self)
self.coherenceStatus.resize(260,40)
self.coherenceStatus.setIcon(QtGui.QIcon("Icons/cross.png"))
......@@ -42,7 +41,40 @@ class SettingsConfigPanel(QtGui.QWidget):
self.featureGroup.setLayout(self.featureLayout)
self.featureGroup.show()
#settings group
#Finer details
#Server Port
self.portLabel = QtGui.QCommandLinkButton("Server Port:")
self.portLabel.setIcon(QtGui.QIcon("Icons/cog.png"))
self.portLabel.setEnabled(False)
self.portLabel.resize(140,40)
self.serverPortInput = QtGui.QLineEdit("31240")
self.serverPortInput.setMaxLength(5)
self.serverPortInput.setInputMask("99999")
#Interface
self.interfaceLabel = QtGui.QCommandLinkButton("Interface:")
self.interfaceLabel.setIcon(QtGui.QIcon("Icons/cog.png"))
self.interfaceLabel.setEnabled(False)
self.interfaceLabel.resize(140,40)
self.interfaceCheckBox = QtGui.QCheckBox("Enable")
self.interfaceInput = QtGui.QLineEdit("eth0")
#Add to Layout and groupbox
self.finerDetailLayout = QtGui.QGridLayout()
self.finerDetailLayout.addWidget(self.portLabel,0,0)
self.finerDetailLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding),0,1)
self.finerDetailLayout.addWidget(self.serverPortInput, 0,2)
self.finerDetailLayout.addWidget(self.interfaceLabel,1,0)
self.finerDetailLayout.addWidget(self.interfaceCheckBox,1,1)
self.finerDetailLayout.addWidget(self.interfaceInput,1,2)
self.FinerDetailsGroup = QtGui.QGroupBox(self)
self.FinerDetailsGroup.setTitle("Finer Details")
self.FinerDetailsGroup.setLayout(self.finerDetailLayout)
self.FinerDetailsGroup.show()
#Apply button
self.applyButton = QtGui.QPushButton("Apply", self)
......@@ -69,6 +101,7 @@ class SettingsConfigPanel(QtGui.QWidget):
self.startButton.move(self.width()/2+50,20)
self.stopButton.move(self.width()/2+145,20)
self.featureGroup.setGeometry(10,60,self.width()-20,60)
self.FinerDetailsGroup.setGeometry(10,130,self.width()-20,120)
self.applyButton.move(self.width()-160, self.height()-40)
self.refreshButton.move(self.width()-320, self.height()-40)
......@@ -102,9 +135,12 @@ class SettingsConfigPanel(QtGui.QWidget):
configManager = XMLDirector()
configManager.loadXMLConfiguration()
serverPort = str(self.serverPortInput.text()).lstrip()
interfaceName = str(self.interfaceInput.text()).lstrip()
settings = {'dbus': self.dbusCheckBox.isChecked(), 'webui': self.webuiCheckBox.isChecked(),
'control':self.cntrlCheckBox.isChecked()}
'control':self.cntrlCheckBox.isChecked(), 'serverport': serverPort,
'interfaceActive': self.interfaceCheckBox.isChecked(), 'interfaceName':interfaceName}
configManager.writeSettingConfig(settings)
......@@ -115,6 +151,9 @@ class SettingsConfigPanel(QtGui.QWidget):
self.dbusCheckBox.setChecked(settings['dbus'])
self.webuiCheckBox.setChecked(settings['webui'])
self.cntrlCheckBox.setChecked(settings['control'])
self.serverPortInput.setText(settings['serverport'])
self.interfaceCheckBox.setChecked(settings['interfaceActive'])
self.interfaceInput.setText(settings['interfaceName'])
def paintEvent(self, event):
......
import ConfigWindow
import ConfigWindow
\ No newline at end of file
......@@ -23,7 +23,7 @@ class XMLDirector:
self.tree = ET.parse(self.configFileLocation)
except ExpatError:
message = "The Coherence configuration file located in your home folder is not valid.\
Would you like to replace it with a valid configuration?"
\nWould you like to replace it with a valid configuration?"
action = QtGui.QMessageBox.critical(None, "Invalid XML Configuration", message, QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
......@@ -49,23 +49,20 @@ class XMLDirector:
folders = []
contents = self.getBackendElement("FSStore")
if contents.get("active") == "yes":
isActive = True
else:
isActive = False
isActive = True if contents.get("active") == "yes" else False
for i in contents:
if i.tag == "content":
folders.append(i.text)
return folders, isActive
return {'contentList':folders, 'isActive':isActive}
def writeLocalContentList(self, contentList, isActive):
def writeLocalContentList(self, settings):
#find the FSStore content -- Store in external list to prevent looping quirks, re
contents = self.getBackendElement("FSStore")
ContentToRemove = []
contents.set("active", isActive)
contents.set("active", settings['isActive'])
#Queue the <content> to remove
for i in contents:
......@@ -77,6 +74,7 @@ class XMLDirector:
contents.remove(i)
#Add the new content list to the XML
contentList = settings['contentList']
for i in contentList:
tempE = ET.fromstring("<content>"+str(i)+"</content>")
contents.insert(0,tempE)
......@@ -89,10 +87,18 @@ class XMLDirector:
dBusElement = self.tree.find(".//use_dbus")
webUIElement = self.tree.find(".//web-ui")
controlElement = self.tree.find(".//controlpoint")
serverPortElement = self.tree.find(".//serverport")
interfaceElement = self.tree.find(".//interface")
dBusElement.text="yes" if settings['dbus'] else "no"
webUIElement.text="yes" if settings['webui'] else "no"
controlElement.text="yes" if settings['control'] else "no"
dBusElement.text= "yes" if settings['dbus'] else "no"
webUIElement.text= "yes" if settings['webui'] else "no"
controlElement.text= "yes" if settings['control'] else "no"
serverPortElement.text= settings['serverport']
interfaceElement.set("active","yes" if settings['interfaceActive'] else "no")
interfaceElement.text= settings['interfaceName']
self.tree.write(self.configFileLocation)
......@@ -100,12 +106,19 @@ class XMLDirector:
dBusElement = self.tree.find(".//use_dbus")
webUIElement = self.tree.find(".//web-ui")
controlElement = self.tree.find(".//controlpoint")
serverPortElement = self.tree.find(".//serverport")
interfaceElement = self.tree.find(".//interface")
dbus = True if dBusElement.text=="yes" else False
webui = True if webUIElement.text=="yes" else False
control = True if controlElement.text=="yes" else False
serverport = serverPortElement.text
interfaceActive = True if interfaceElement.get("active") == "yes" else False
interfaceName = interfaceElement.text
settings = {'dbus':dbus, 'webui':webui, 'control':control}
settings = {'dbus':dbus, 'webui':webui, 'control':control, 'serverport':serverport,
'interfaceActive': interfaceActive, 'interfaceName': interfaceName}
return settings
def generateXMLConfiguration(self):
......
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