added gui configurator
This commit is contained in:
parent
44c81d8fdc
commit
34d7b112b1
@ -123,24 +123,6 @@ class MPCConfigurationGetter(ConfigurationGetter):
|
|||||||
raise InvalidConfigValue('Path to mpc is not valid')
|
raise InvalidConfigValue('Path to mpc is not valid')
|
||||||
self._config.set(section_name, 'mpc_path', self._args.mpc_path)
|
self._config.set(section_name, 'mpc_path', self._args.mpc_path)
|
||||||
|
|
||||||
def _tryToFillUpMpcPath(self):
|
|
||||||
if(self._args.mpc_path == None):
|
|
||||||
paths = ["C:\Program Files (x86)\MPC-HC\mpc-hc.exe",
|
|
||||||
"C:\Program Files\MPC-HC\mpc-hc.exe",
|
|
||||||
"C:\Program Files\MPC-HC\mpc-hc64.exe",
|
|
||||||
"C:\Program Files\Media Player Classic - Home Cinema\mpc-hc.exe",
|
|
||||||
"C:\Program Files\Media Player Classic - Home Cinema\mpc-hc64.exe",
|
|
||||||
"C:\Program Files (x86)\Media Player Classic - Home Cinema\mpc-hc.exe",
|
|
||||||
"C:\Program Files (x86)\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe",
|
|
||||||
"C:\Program Files\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe",
|
|
||||||
"C:\Program Files (x86)\Combined Community Codec Pack\MPC\mpc-hc.exe",
|
|
||||||
"C:\Program Files\MPC HomeCinema (x64)\mpc-hc64.exe",
|
|
||||||
]
|
|
||||||
for path in paths:
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
self._args.mpc_path = path
|
|
||||||
return
|
|
||||||
|
|
||||||
def mpc_pathValid(self):
|
def mpc_pathValid(self):
|
||||||
if(os.path.isfile(self._args.mpc_path)):
|
if(os.path.isfile(self._args.mpc_path)):
|
||||||
if(self._args.mpc_path[-10:] == 'mpc-hc.exe' or self._args.mpc_path[-12:] == 'mpc-hc64.exe'):
|
if(self._args.mpc_path[-10:] == 'mpc-hc.exe' or self._args.mpc_path[-12:] == 'mpc-hc64.exe'):
|
||||||
@ -158,7 +140,6 @@ class MPCConfigurationGetter(ConfigurationGetter):
|
|||||||
def getConfiguration(self):
|
def getConfiguration(self):
|
||||||
ConfigurationGetter.getConfiguration(self)
|
ConfigurationGetter.getConfiguration(self)
|
||||||
self.__addSpecialMPCFlags()
|
self.__addSpecialMPCFlags()
|
||||||
self._tryToFillUpMpcPath()
|
|
||||||
return self._args
|
return self._args
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from syncplay.client import SyncplayClientManager
|
|||||||
|
|
||||||
from syncplay.players import mpc
|
from syncplay.players import mpc
|
||||||
from syncplay.ConfigurationGetter import MPCConfigurationGetter
|
from syncplay.ConfigurationGetter import MPCConfigurationGetter
|
||||||
|
from syncplay.ui.GuiConfiguration import GuiConfigurationForMPC
|
||||||
|
|
||||||
class SyncplayMPC(SyncplayClient):
|
class SyncplayMPC(SyncplayClient):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -17,6 +17,9 @@ class SyncplayMPC(SyncplayClient):
|
|||||||
self.argsGetter = MPCConfigurationGetter()
|
self.argsGetter = MPCConfigurationGetter()
|
||||||
self.args = self.argsGetter.getConfiguration()
|
self.args = self.argsGetter.getConfiguration()
|
||||||
|
|
||||||
|
def _guiPromptForMissingArguments(self):
|
||||||
|
self.args = GuiConfigurationForMPC(self.args).getProcessedConfiguration()
|
||||||
|
|
||||||
def _promptForMissingArguments(self):
|
def _promptForMissingArguments(self):
|
||||||
SyncplayClient._promptForMissingArguments(self)
|
SyncplayClient._promptForMissingArguments(self)
|
||||||
if (self.args.mpc_path == None):
|
if (self.args.mpc_path == None):
|
||||||
|
|||||||
@ -210,7 +210,7 @@ class SyncplayClientManager(object):
|
|||||||
def __init__(self, name, make_player, ui, debug, room, password = None):
|
def __init__(self, name, make_player, ui, debug, room, password = None):
|
||||||
self.users = self.UserList()
|
self.users = self.UserList()
|
||||||
self.users.currentUser.name = name
|
self.users.currentUser.name = name
|
||||||
if(room == None):
|
if(room == None or room == ''):
|
||||||
room = 'default'
|
room = 'default'
|
||||||
self.users.currentUser.room = room
|
self.users.currentUser.room = room
|
||||||
if(password):
|
if(password):
|
||||||
@ -526,21 +526,34 @@ class SyncplayClientManager(object):
|
|||||||
|
|
||||||
from syncplay import ui
|
from syncplay import ui
|
||||||
from syncplay.ConfigurationGetter import ConfigurationGetter
|
from syncplay.ConfigurationGetter import ConfigurationGetter
|
||||||
|
from syncplay.ui.GuiConfiguration import GuiConfiguration
|
||||||
|
|
||||||
|
|
||||||
class SyncplayClient(object):
|
class SyncplayClient(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._prepareArguments()
|
self._prepareArguments()
|
||||||
self.interface = ui.getUi(graphical = not self.args.no_gui)
|
self.interface = ui.getUi(graphical = not self.args.no_gui)
|
||||||
self._promptForMissingArguments()
|
self._checkAndSaveConfiguration()
|
||||||
self.argsGetter.saveValuesIntoConfigFile()
|
|
||||||
|
def _checkAndSaveConfiguration(self):
|
||||||
|
try:
|
||||||
|
self._promptForMissingArguments()
|
||||||
|
self.argsGetter.saveValuesIntoConfigFile()
|
||||||
|
except:
|
||||||
|
self._checkAndSaveConfiguration()
|
||||||
|
|
||||||
def _prepareArguments(self):
|
def _prepareArguments(self):
|
||||||
self.argsGetter = ConfigurationGetter()
|
self.argsGetter = ConfigurationGetter()
|
||||||
self.args = self.argsGetter.getConfiguration()
|
self.args = self.argsGetter.getConfiguration()
|
||||||
|
|
||||||
|
def _guiPromptForMissingArguments(self):
|
||||||
|
self.args = GuiConfiguration(self.args).getProcessedConfiguration()
|
||||||
|
|
||||||
def _promptForMissingArguments(self):
|
def _promptForMissingArguments(self):
|
||||||
#if(self.args.no_gui)
|
if(self.args.no_gui):
|
||||||
if (self.args.host == None):
|
if (self.args.host == None):
|
||||||
self.args.host = self.interface.promptFor(promptName = "Hostname", message = "You must supply hostname on the first run, it's easier through command line arguments.")
|
self.args.host = self.interface.promptFor(promptName = "Hostname", message = "You must supply hostname on the first run, it's easier through command line arguments.")
|
||||||
if (self.args.name == None):
|
if (self.args.name == None):
|
||||||
self.args.name = self.interface.promptFor(promptName = "Username", message = "You must supply username on the first run, it's easier through command line arguments.")
|
self.args.name = self.interface.promptFor(promptName = "Username", message = "You must supply username on the first run, it's easier through command line arguments.")
|
||||||
|
else:
|
||||||
|
self._guiPromptForMissingArguments()
|
||||||
111
syncplay/ui/GuiConfiguration.py
Normal file
111
syncplay/ui/GuiConfiguration.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import pygtk
|
||||||
|
import os
|
||||||
|
pygtk.require('2.0')
|
||||||
|
import gtk
|
||||||
|
gtk.set_interactive(False)
|
||||||
|
import cairo, gio, pango, atk, pangocairo, gobject
|
||||||
|
|
||||||
|
class GuiConfiguration:
|
||||||
|
def __init__(self, args, force = False):
|
||||||
|
self.args = args
|
||||||
|
if(args.host == None or args.name == None or force):
|
||||||
|
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
|
self.window.set_title("Syncplay Configuration")
|
||||||
|
self.window.connect("delete_event", lambda w, e: gtk.main_quit())
|
||||||
|
vbox = gtk.VBox(False, 0)
|
||||||
|
self.window.add(vbox)
|
||||||
|
vbox.show()
|
||||||
|
self._addLabeledEntries(args, vbox)
|
||||||
|
|
||||||
|
self.hostEntry.select_region(0, len(self.hostEntry.get_text()))
|
||||||
|
button = gtk.Button(stock=gtk.STOCK_SAVE)
|
||||||
|
button.connect("clicked", lambda w: self._saveDataAndLeave())
|
||||||
|
vbox.pack_start(button, True, True, 0)
|
||||||
|
button.set_flags(gtk.CAN_DEFAULT)
|
||||||
|
button.grab_default()
|
||||||
|
button.show()
|
||||||
|
self.window.show()
|
||||||
|
gtk.main()
|
||||||
|
|
||||||
|
def _addLabeledEntries(self, args, vbox):
|
||||||
|
self.hostEntry = self._addLabeledEntryToVbox('Host: ', args.host, vbox, self._focusNext)
|
||||||
|
self.userEntry = self._addLabeledEntryToVbox('Username: ', args.name, vbox, self._focusNext)
|
||||||
|
self.roomEntry = self._addLabeledEntryToVbox('Default room (optional): ', args.room, vbox, self._focusNext)
|
||||||
|
self.passEntry = self._addLabeledEntryToVbox('Server password (optional): ', args.password, vbox, self._focusNext)
|
||||||
|
|
||||||
|
def getProcessedConfiguration(self):
|
||||||
|
return self.args
|
||||||
|
|
||||||
|
def _saveDataAndLeave(self):
|
||||||
|
self.args.host = self.hostEntry.get_text()
|
||||||
|
self.args.name = self.userEntry.get_text()
|
||||||
|
self.args.room = self.roomEntry.get_text()
|
||||||
|
self.args.password = self.passEntry.get_text()
|
||||||
|
self.window.destroy()
|
||||||
|
gtk.main_quit()
|
||||||
|
|
||||||
|
def _focusNext(self, widget, entry):
|
||||||
|
self.window.get_toplevel().child_focus(gtk.DIR_TAB_FORWARD)
|
||||||
|
|
||||||
|
def _addLabeledEntryToVbox(self, label, initialEntryValue, vbox, callback):
|
||||||
|
hbox = gtk.HBox(False, 0)
|
||||||
|
hbox.set_border_width(3)
|
||||||
|
vbox.pack_start(hbox, False, False, 0)
|
||||||
|
hbox.show()
|
||||||
|
label_ = gtk.Label()
|
||||||
|
label_.set_text(label)
|
||||||
|
label_.set_alignment(xalign=0, yalign=0.5)
|
||||||
|
hbox.pack_start(label_, False, False, 0)
|
||||||
|
label_.show()
|
||||||
|
entry = gtk.Entry()
|
||||||
|
entry.connect("activate", callback, entry)
|
||||||
|
if(initialEntryValue == None):
|
||||||
|
initialEntryValue = ""
|
||||||
|
entry.set_text(initialEntryValue)
|
||||||
|
hbox.pack_end(entry, False, False, 0)
|
||||||
|
entry.set_usize(200, -1)
|
||||||
|
entry.show()
|
||||||
|
hbox = gtk.HBox(False, 0)
|
||||||
|
vbox.add(hbox)
|
||||||
|
hbox.show()
|
||||||
|
return entry
|
||||||
|
|
||||||
|
class GuiConfigurationForMPC(GuiConfiguration):
|
||||||
|
def __init__(self, args, force = False):
|
||||||
|
force = (args.mpc_path == None) or force
|
||||||
|
GuiConfiguration.__init__(self, args, force)
|
||||||
|
|
||||||
|
def _addLabeledEntries(self, args, vbox):
|
||||||
|
GuiConfiguration._addLabeledEntries(self, args, vbox)
|
||||||
|
self._tryToFillUpMpcPath()
|
||||||
|
self.mpcEntry = self._addLabeledEntryToVbox('Path to mpc-hc.exe: ', self.args.mpc_path, vbox, self._focusNext)
|
||||||
|
|
||||||
|
def _saveDataAndLeave(self):
|
||||||
|
self.args.host = self.hostEntry.get_text()
|
||||||
|
self.args.name = self.userEntry.get_text()
|
||||||
|
self.args.room = self.roomEntry.get_text()
|
||||||
|
self.args.password = self.passEntry.get_text()
|
||||||
|
self.args.mpc_path = self.mpcEntry.get_text()
|
||||||
|
self.window.destroy()
|
||||||
|
gtk.main_quit()
|
||||||
|
|
||||||
|
def _tryToFillUpMpcPath(self):
|
||||||
|
if(self.args.mpc_path == None):
|
||||||
|
paths = ["C:\Program Files (x86)\MPC-HC\mpc-hc.exe",
|
||||||
|
"C:\Program Files\MPC-HC\mpc-hc.exe",
|
||||||
|
"C:\Program Files\MPC-HC\mpc-hc64.exe",
|
||||||
|
"C:\Program Files\Media Player Classic - Home Cinema\mpc-hc.exe",
|
||||||
|
"C:\Program Files\Media Player Classic - Home Cinema\mpc-hc64.exe",
|
||||||
|
"C:\Program Files (x86)\Media Player Classic - Home Cinema\mpc-hc.exe",
|
||||||
|
"C:\Program Files (x86)\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe",
|
||||||
|
"C:\Program Files\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe",
|
||||||
|
"C:\Program Files (x86)\Combined Community Codec Pack\MPC\mpc-hc.exe",
|
||||||
|
"C:\Program Files\MPC HomeCinema (x64)\mpc-hc64.exe",
|
||||||
|
]
|
||||||
|
for path in paths:
|
||||||
|
if(os.path.isfile(path)):
|
||||||
|
self.args.mpc_path = path
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -24,8 +24,6 @@ class ConsoleUI(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = raw_input()
|
data = raw_input()
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
data = data.rstrip('\n\r')
|
data = data.rstrip('\n\r')
|
||||||
if(not self.promptMode.isSet()):
|
if(not self.promptMode.isSet()):
|
||||||
self.PromptResult = data
|
self.PromptResult = data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user