Move UI from GTK to PySide + other improvements
This commit is contained in:
parent
f979bb809a
commit
91b217685e
@ -1,136 +1,233 @@
|
|||||||
import pygtk
|
from PySide import QtCore, QtGui
|
||||||
|
from PySide.QtCore import QSettings, Qt
|
||||||
|
from PySide.QtGui import QApplication, QLineEdit, QCursor, QLabel, QCheckBox
|
||||||
|
|
||||||
import os
|
import os
|
||||||
pygtk.require('2.0')
|
import sys
|
||||||
import gtk
|
|
||||||
gtk.set_interactive(False)
|
|
||||||
import cairo, gio, pango, atk, pangocairo, gobject #@UnusedImport
|
|
||||||
from syncplay.messages import getMessage
|
from syncplay.messages import getMessage
|
||||||
|
|
||||||
class GuiConfiguration:
|
class GuiConfiguration:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self._availablePlayerPaths = []
|
self._availablePlayerPaths = []
|
||||||
self.closedAndNotSaved = False
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
self.app = QtGui.QApplication(sys.argv)
|
||||||
self.window.set_title(getMessage("en", "config-window-title"))
|
dialog = ConfigDialog(self.config, self._availablePlayerPaths)
|
||||||
self.window.connect("delete_event", lambda w, e: self._windowClosed())
|
dialog.exec_()
|
||||||
vbox = gtk.VBox(False, 0)
|
|
||||||
self.window.add(vbox)
|
def setAvailablePaths(self, paths):
|
||||||
vbox.show()
|
self._availablePlayerPaths = paths
|
||||||
self._addLabeledEntries(self.config, vbox)
|
|
||||||
self._addCheckboxEntries(self.config, vbox)
|
def getProcessedConfiguration(self):
|
||||||
self.hostEntry.select_region(0, len(self.hostEntry.get_text()))
|
return self.config
|
||||||
button = gtk.Button(stock=gtk.STOCK_SAVE)
|
|
||||||
button.connect("clicked", lambda w: self._saveDataAndLeave())
|
class WindowClosed(Exception):
|
||||||
guideLink = gtk.LinkButton("http://syncplay.pl/guide/", "Configuration Guide")
|
pass
|
||||||
guideLink.show()
|
|
||||||
vbox.add(guideLink)
|
class ConfigDialog(QtGui.QDialog):
|
||||||
vbox.pack_start(button, True, True, 0)
|
|
||||||
button.set_flags(gtk.CAN_DEFAULT)
|
pressedclosebutton = False
|
||||||
button.grab_default()
|
|
||||||
button.show()
|
malToggling = False
|
||||||
self.window.show()
|
|
||||||
gtk.main()
|
def malToggled(self):
|
||||||
|
if self.malToggling == False:
|
||||||
def _windowClosed(self):
|
self.malToggling = True
|
||||||
self.window.destroy()
|
|
||||||
gtk.main_quit()
|
if self.malenabledCheckbox.isChecked() and self.malenabledCheckbox.isVisible():
|
||||||
self.closedAndNotSaved = True
|
self.malenabledCheckbox.setChecked(False)
|
||||||
|
self.malSettingsGroup.setChecked(True)
|
||||||
|
self.malSettingsGroup.show()
|
||||||
|
self.malpasswordLabel.show()
|
||||||
|
self.malpasswordTextbox.show()
|
||||||
|
self.malusernameLabel.show()
|
||||||
|
self.malusernameTextbox.show()
|
||||||
|
self.malenabledCheckbox.hide()
|
||||||
|
else:
|
||||||
|
self.malSettingsGroup.setChecked(False)
|
||||||
|
self.malSettingsGroup.hide()
|
||||||
|
self.malpasswordLabel.hide()
|
||||||
|
self.malpasswordTextbox.hide()
|
||||||
|
self.malusernameLabel.hide()
|
||||||
|
self.malusernameTextbox.hide()
|
||||||
|
self.malenabledCheckbox.show()
|
||||||
|
|
||||||
|
self.malToggling = False
|
||||||
|
self.adjustSize()
|
||||||
|
self.setFixedSize(self.sizeHint())
|
||||||
|
|
||||||
|
def runButtonTextUpdate(self):
|
||||||
|
if (self.donotstoreCheckbox.isChecked()):
|
||||||
|
self.runButton.setText("Run Syncplay")
|
||||||
|
else:
|
||||||
|
self.runButton.setText("Store configuration and run Syncplay")
|
||||||
|
|
||||||
|
def _tryToFillPlayerPath(self, playerpath, playerpathlist):
|
||||||
|
foundpath = ""
|
||||||
|
|
||||||
def _addLabeledEntries(self, config, vbox):
|
if playerpath != None and playerpath != "" and os.path.isfile(playerpath):
|
||||||
|
foundpath = playerpath
|
||||||
|
self.executablepathCombobox.addItem(foundpath)
|
||||||
|
|
||||||
|
for path in playerpathlist:
|
||||||
|
if(os.path.isfile(path) and path.lower() != foundpath.lower()):
|
||||||
|
self.executablepathCombobox.addItem(path)
|
||||||
|
if foundpath == None:
|
||||||
|
foundpath = path
|
||||||
|
|
||||||
|
if foundpath:
|
||||||
|
return(foundpath)
|
||||||
|
else:
|
||||||
|
return("")
|
||||||
|
|
||||||
|
def browsePlayerpath(self):
|
||||||
|
options = QtGui.QFileDialog.Options()
|
||||||
|
|
||||||
|
fileName, filtr = QtGui.QFileDialog.getOpenFileName(self,
|
||||||
|
"Browse for media player executable",
|
||||||
|
"",
|
||||||
|
"Windows Executables (*.exe);;All Files (*)", "", options)
|
||||||
|
if fileName:
|
||||||
|
self.executablepathCombobox.setEditText(fileName)
|
||||||
|
|
||||||
|
def _saveDataAndLeave(self):
|
||||||
|
self.config['host'] = self.hostTextbox.text()
|
||||||
|
self.config['name'] = self.usernameTextbox.text()
|
||||||
|
self.config['room'] = self.defaultroomTextbox.text()
|
||||||
|
self.config['password'] = self.serverpassTextbox.text()
|
||||||
|
self.config['playerPath'] = self.executablepathCombobox.currentText()
|
||||||
|
if self.alwaysshowCheckbox.isChecked() == True:
|
||||||
|
self.config['forceGuiPrompt'] = True
|
||||||
|
else:
|
||||||
|
self.config['forceGuiPrompt'] = False
|
||||||
|
if self.donotstoreCheckbox.isChecked() == True:
|
||||||
|
self.config['noStore'] = True
|
||||||
|
else:
|
||||||
|
self.config['noStore'] = False
|
||||||
|
if self.slowdownCheckbox.isChecked() == True:
|
||||||
|
self.config['slowOnDesync'] = True
|
||||||
|
else:
|
||||||
|
self.config['slowOnDesync'] = False
|
||||||
|
self.config['malUsername'] = self.malusernameTextbox.text()
|
||||||
|
if self.malSettingsGroup.isChecked():
|
||||||
|
self.config['malPassword'] = self.malpasswordTextbox.text()
|
||||||
|
else:
|
||||||
|
self.config['malPassword'] = ""
|
||||||
|
self.pressedclosebutton = True
|
||||||
|
self.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
if self.pressedclosebutton == False:
|
||||||
|
sys.exit()
|
||||||
|
raise GuiConfiguration.WindowClosed
|
||||||
|
event.accept()
|
||||||
|
|
||||||
|
def __init__(self, config, playerpaths):
|
||||||
|
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
super(ConfigDialog, self).__init__()
|
||||||
|
|
||||||
|
self.setWindowTitle(getMessage("en", "config-window-title"))
|
||||||
|
|
||||||
if(config['host'] == None):
|
if(config['host'] == None):
|
||||||
host = ""
|
host = ""
|
||||||
elif(":" in config['host']):
|
elif(":" in config['host']):
|
||||||
host = config['host']
|
host = config['host']
|
||||||
else:
|
else:
|
||||||
host = config['host']+":"+str(config['port'])
|
host = config['host']+":"+str(config['port'])
|
||||||
|
|
||||||
self.hostEntry = self._addLabeledEntryToVbox(getMessage("en", "host-label"), host, vbox, lambda __, _: self._saveDataAndLeave())
|
self.connectionSettingsGroup = QtGui.QGroupBox("Connection Settings")
|
||||||
self.userEntry = self._addLabeledEntryToVbox(getMessage("en", "username-label"), config['name'], vbox, lambda __, _: self._saveDataAndLeave())
|
self.hostTextbox = QLineEdit(host, self)
|
||||||
self.roomEntry = self._addLabeledEntryToVbox(getMessage("en", "room-label"), config['room'], vbox, lambda __, _: self._saveDataAndLeave())
|
self.hostLabel = QLabel(getMessage("en", "host-label"), self)
|
||||||
self.passEntry = self._addLabeledEntryToVbox(getMessage("en", "password-label"), config['password'], vbox, lambda __, _: self._saveDataAndLeave())
|
self.usernameTextbox = QLineEdit(config['name'],self)
|
||||||
self.mpcEntry = self._addLabeledEntryToVbox(getMessage("en", "path-label"), self._tryToFillPlayerPath(config['playerPath']), vbox, lambda __, _: self._saveDataAndLeave())
|
self.serverpassLabel = QLabel(getMessage("en", "password-label"), self)
|
||||||
|
self.defaultroomTextbox = QLineEdit(config['room'],self)
|
||||||
|
self.usernameLabel = QLabel(getMessage("en", "username-label"), self)
|
||||||
|
self.serverpassTextbox = QLineEdit(config['password'],self)
|
||||||
|
self.defaultroomLabel = QLabel(getMessage("en", "room-label"), self)
|
||||||
|
self.connectionSettingsLayout = QtGui.QGridLayout()
|
||||||
|
self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0)
|
||||||
|
self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1)
|
||||||
|
self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout)
|
||||||
|
|
||||||
|
self.mediaplayerSettingsGroup = QtGui.QGroupBox("Media Player Settings")
|
||||||
|
self.executablepathCombobox = QtGui.QComboBox(self)
|
||||||
|
self.executablepathCombobox.setEditable(True)
|
||||||
|
self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'],playerpaths))
|
||||||
|
self.executablepathCombobox.setMinimumWidth(200)
|
||||||
|
self.executablepathCombobox.setMaximumWidth(200)
|
||||||
|
self.executablepathLabel = QLabel("Path to player executable:", self)
|
||||||
|
self.executablebrowseButton = QtGui.QPushButton("Browse")
|
||||||
|
self.executablebrowseButton.clicked.connect(self.browsePlayerpath)
|
||||||
|
self.slowdownCheckbox = QCheckBox("Slow down on desync")
|
||||||
|
self.mediaplayerSettingsLayout = QtGui.QGridLayout()
|
||||||
|
self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0)
|
||||||
|
self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox , 0, 1)
|
||||||
|
self.mediaplayerSettingsLayout.addWidget(self.executablebrowseButton , 0, 2)
|
||||||
|
self.mediaplayerSettingsLayout.addWidget(self.slowdownCheckbox, 1, 0)
|
||||||
|
self.mediaplayerSettingsGroup.setLayout(self.mediaplayerSettingsLayout)
|
||||||
|
if config['slowOnDesync'] == True:
|
||||||
|
self.slowdownCheckbox.setChecked(True)
|
||||||
|
|
||||||
|
self.malSettingsGroup = QtGui.QGroupBox("Enable MyAnimeList Updater (EXPERIMENTAL)")
|
||||||
def _tryToFillPlayerPath(self, playerpath):
|
self.malSettingsGroup.setCheckable(True)
|
||||||
if playerpath != None and os.path.isfile(playerpath):
|
self.malSettingsGroup.toggled.connect(self.malToggled)
|
||||||
return playerpath
|
self.malSettingsSplit = QtGui.QSplitter(self)
|
||||||
|
self.malusernameTextbox = QLineEdit(config['malUsername'],self)
|
||||||
for path in self._availablePlayerPaths:
|
self.malusernameLabel = QLabel("MAL Username:", self)
|
||||||
if(os.path.isfile(path)):
|
self.malpasswordTextbox = QLineEdit(config['malPassword'],self)
|
||||||
return path
|
self.malpasswordTextbox.setEchoMode(QtGui.QLineEdit.Password)
|
||||||
return self.config["playerPath"]
|
self.malpasswordLabel = QLabel("MAL Password:", self)
|
||||||
|
self.malSettingsLayout = QtGui.QGridLayout()
|
||||||
def getProcessedConfiguration(self):
|
self.malSettingsLayout.addWidget(self.malusernameLabel , 0, 0)
|
||||||
if(self.closedAndNotSaved):
|
self.malSettingsLayout.addWidget(self.malusernameTextbox, 0, 1)
|
||||||
raise self.WindowClosed
|
self.malSettingsLayout.addWidget(self.malpasswordLabel , 1, 0)
|
||||||
return self.config
|
self.malSettingsLayout.addWidget(self.malpasswordTextbox, 1, 1)
|
||||||
|
self.malSettingsGroup.setLayout(self.malSettingsLayout)
|
||||||
def _saveDataAndLeave(self):
|
|
||||||
self.config['host'] = self.hostEntry.get_text()
|
self.malenabledCheckbox = QCheckBox("Enable MyAnimeList Updater (EXPERIMENTAL)")
|
||||||
self.config['name'] = self.userEntry.get_text()
|
self.malenabledCheckbox.toggled.connect(self.malToggled)
|
||||||
self.config['room'] = self.roomEntry.get_text()
|
if config['malPassword'] == None or config['malPassword'] == "":
|
||||||
self.config['password'] = self.passEntry.get_text()
|
self.malenabledCheckbox.setChecked(False)
|
||||||
self.config['playerPath'] = self.mpcEntry.get_text()
|
self.malSettingsGroup.hide()
|
||||||
if self.alwaysShowCheck.get_active() == True:
|
|
||||||
self.config['forceGuiPrompt'] = True
|
|
||||||
else:
|
else:
|
||||||
self.config['forceGuiPrompt'] = False
|
self.malenabledCheckbox.hide()
|
||||||
if self.storeConfigCheck.get_active() == True:
|
|
||||||
self.config['noStore'] = True
|
self.alwaysshowCheckbox = QCheckBox("Always Show This Dialog")
|
||||||
else:
|
if config['forceGuiPrompt'] == True:
|
||||||
self.config['noStore'] = False
|
self.alwaysshowCheckbox.setChecked(True)
|
||||||
if self.slowOnDesyncCheck.get_active() == True:
|
|
||||||
self.config['slowOnDesync'] = True
|
self.donotstoreCheckbox = QCheckBox("Do Not Store This Configuration")
|
||||||
else:
|
if config['noStore'] == True:
|
||||||
self.config['slowOnDesync'] = False
|
self.donotstoreCheckbox.setChecked(True)
|
||||||
self.window.destroy()
|
|
||||||
gtk.main_quit()
|
self.runButton = QtGui.QPushButton("Store configuration and run Syncplay")
|
||||||
|
self.runButton.pressed.connect(self._saveDataAndLeave)
|
||||||
def _addLabeledEntryToVbox(self, label, initialEntryValue, vbox, callback):
|
self.runButtonTextUpdate
|
||||||
hbox = gtk.HBox(False, 0)
|
self.donotstoreCheckbox.toggled.connect(self.runButtonTextUpdate)
|
||||||
hbox.set_border_width(3)
|
|
||||||
vbox.pack_start(hbox, False, False, 0)
|
self.mainLayout = QtGui.QVBoxLayout()
|
||||||
hbox.show()
|
self.mainLayout.addWidget(self.connectionSettingsGroup)
|
||||||
label_ = gtk.Label()
|
self.mainLayout.addSpacing(12)
|
||||||
label_.set_text(label)
|
self.mainLayout.addWidget(self.mediaplayerSettingsGroup)
|
||||||
label_.set_alignment(xalign=0, yalign=0.5)
|
self.mainLayout.addSpacing(12)
|
||||||
hbox.pack_start(label_, False, False, 0)
|
self.mainLayout.addWidget(self.malenabledCheckbox)
|
||||||
label_.show()
|
self.mainLayout.addWidget(self.malSettingsGroup)
|
||||||
entry = gtk.Entry()
|
|
||||||
entry.connect("activate", callback, entry)
|
self.mainLayout.addWidget(self.alwaysshowCheckbox)
|
||||||
if(initialEntryValue == None):
|
self.mainLayout.addWidget(self.donotstoreCheckbox)
|
||||||
initialEntryValue = ""
|
self.mainLayout.addWidget(self.runButton)
|
||||||
entry.set_text(initialEntryValue)
|
|
||||||
hbox.pack_end(entry, False, False, 0)
|
self.mainLayout.addStretch(1)
|
||||||
entry.set_usize(200, -1)
|
|
||||||
entry.show()
|
self.setLayout(self.mainLayout)
|
||||||
return entry
|
self.setFixedSize(self.sizeHint())
|
||||||
|
|
||||||
def _addCheckboxEntries(self, config, vbox):
|
|
||||||
CheckVbox = gtk.VBox(False, 0)
|
|
||||||
vbox.pack_start(CheckVbox, False, False, 0)
|
|
||||||
self.alwaysShowCheck = gtk.CheckButton("Always Show This Dialog")
|
|
||||||
if self.config['forceGuiPrompt'] == True:
|
|
||||||
self.alwaysShowCheck.set_active(True)
|
|
||||||
self.alwaysShowCheck.show()
|
|
||||||
self.storeConfigCheck = gtk.CheckButton("Do Not Store This Configuration")
|
|
||||||
if self.config['noStore'] == True:
|
|
||||||
self.storeConfigCheck.set_active(True)
|
|
||||||
self.storeConfigCheck.show()
|
|
||||||
self.slowOnDesyncCheck = gtk.CheckButton("Slow Down On Desync")
|
|
||||||
if self.config['slowOnDesync'] == True:
|
|
||||||
self.slowOnDesyncCheck.set_active(True)
|
|
||||||
self.slowOnDesyncCheck.show()
|
|
||||||
CheckVbox.pack_start(self.alwaysShowCheck, False, False, 0)
|
|
||||||
CheckVbox.add(self.storeConfigCheck)
|
|
||||||
CheckVbox.add(self.slowOnDesyncCheck)
|
|
||||||
CheckVbox.show()
|
|
||||||
|
|
||||||
def setAvailablePaths(self, paths):
|
|
||||||
self._availablePlayerPaths = paths
|
|
||||||
|
|
||||||
class WindowClosed(Exception):
|
|
||||||
pass
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user