From 2b8da1deb4c0eac44a2d41c5b8eb389b3a2f2c6f Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 6 May 2016 13:31:18 +0300 Subject: [PATCH] command line argument - path to profile - added. windows qcombobox color fix --- src/main.py | 99 ++++++++++++++++++++++++-------------------- src/styles/style.qss | 2 +- src/tox.py | 7 ++-- src/util.py | 7 ++-- 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/main.py b/src/main.py index ee0f654..80cb018 100644 --- a/src/main.py +++ b/src/main.py @@ -13,9 +13,10 @@ import locale class Toxygen(object): - def __init__(self): + def __init__(self, path=None): super(Toxygen, self).__init__() self.tox = self.ms = self.init = self.mainloop = self.avloop = None + self.path = path def main(self): """ @@ -28,51 +29,57 @@ class Toxygen(object): with open(curr_directory() + '/styles/style.qss') as fl: dark_style = fl.read() app.setStyleSheet(dark_style) - - auto_profile = Settings.get_auto_profile() - if not auto_profile: - # show login screen if default profile not found - current_locale = QtCore.QLocale() - curr_lang = current_locale.languageToString(current_locale.language()) - langs = Settings.supported_languages() - if curr_lang in map(lambda x: x[0], langs): - lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1] - translator = QtCore.QTranslator() - translator.load(curr_directory() + '/translations/' + lang_path) - app.installTranslator(translator) - app.translator = translator - ls = LoginScreen() - ls.setWindowIconText("Toxygen") - profiles = ProfileHelper.find_profiles() - ls.update_select(map(lambda x: x[1], profiles)) - _login = self.Login(profiles) - ls.update_on_close(_login.login_screen_close) - ls.show() - app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) - app.exec_() - if not _login.t: - return - elif _login.t == 1: # create new profile - name = _login.name if _login.name else 'toxygen_user' - self.tox = tox_factory() - self.tox.self_set_name(_login.name if _login.name else 'Toxygen User') - self.tox.self_set_status_message('Toxing on Toxygen') - ProfileHelper.save_profile(self.tox.get_savedata(), name) - path = Settings.get_default_path() - settings = Settings(name) - else: # load existing profile - path, name = _login.get_data() - if _login.default: - Settings.set_auto_profile(path, name) - data = ProfileHelper.open_profile(path, name) - settings = Settings(name) - self.tox = tox_factory(data, settings) - else: - path, name = auto_profile - path = path.encode(locale.getpreferredencoding()) + if self.path is not None: + path = os.path.dirname(self.path.encode(locale.getpreferredencoding())) + '/' + name = os.path.basename(self.path.encode(locale.getpreferredencoding()))[:-4] data = ProfileHelper.open_profile(path, name) settings = Settings(name) self.tox = tox_factory(data, settings) + else: + auto_profile = Settings.get_auto_profile() + if not auto_profile: + # show login screen if default profile not found + current_locale = QtCore.QLocale() + curr_lang = current_locale.languageToString(current_locale.language()) + langs = Settings.supported_languages() + if curr_lang in map(lambda x: x[0], langs): + lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1] + translator = QtCore.QTranslator() + translator.load(curr_directory() + '/translations/' + lang_path) + app.installTranslator(translator) + app.translator = translator + ls = LoginScreen() + ls.setWindowIconText("Toxygen") + profiles = ProfileHelper.find_profiles() + ls.update_select(map(lambda x: x[1], profiles)) + _login = self.Login(profiles) + ls.update_on_close(_login.login_screen_close) + ls.show() + app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) + app.exec_() + if not _login.t: + return + elif _login.t == 1: # create new profile + name = _login.name if _login.name else 'toxygen_user' + self.tox = tox_factory() + self.tox.self_set_name(_login.name if _login.name else 'Toxygen User') + self.tox.self_set_status_message('Toxing on Toxygen') + ProfileHelper.save_profile(self.tox.get_savedata(), name) + path = Settings.get_default_path() + settings = Settings(name) + else: # load existing profile + path, name = _login.get_data() + if _login.default: + Settings.set_auto_profile(path, name) + data = ProfileHelper.open_profile(path, name) + settings = Settings(name) + self.tox = tox_factory(data, settings) + else: + path, name = auto_profile + path = path.encode(locale.getpreferredencoding()) + data = ProfileHelper.open_profile(path, name) + settings = Settings(name) + self.tox = tox_factory(data, settings) if ProfileHelper.is_active_profile(path, name): # profile is in use reply = QtGui.QMessageBox.question(None, @@ -252,6 +259,8 @@ class Toxygen(object): if __name__ == '__main__': - # TODO: add command line options - toxygen = Toxygen() + if len(sys.argv) == 1: + toxygen = Toxygen() + else: # path to profile + toxygen = Toxygen(sys.argv[1]) toxygen.main() diff --git a/src/styles/style.qss b/src/styles/style.qss index 379987e..aebc609 100644 --- a/src/styles/style.qss +++ b/src/styles/style.qss @@ -668,7 +668,7 @@ QComboBox QAbstractItemView background-color: #201F1F; border-radius: 2px; border: 1px solid #444; - selection-background-color: #3d8ec9; + selection-background-color: #A9A9A9; } QComboBox::drop-down diff --git a/src/tox.py b/src/tox.py index f35543b..8c1a30d 100644 --- a/src/tox.py +++ b/src/tox.py @@ -32,6 +32,7 @@ def bin_to_string(raw_id, length): class Tox(object): + libtoxcore = LibToxCore() def __init__(self, tox_options=None, tox_pointer=None): @@ -57,9 +58,9 @@ class Tox(object): raise MemoryError('The function was unable to allocate enough ' 'memory to store the internal structures for the Tox object.') elif tox_err_new == TOX_ERR_NEW['PORT_ALLOC']: - raise MemoryError('The function was unable to bind to a port. This may mean that all ports have already' - ' been bound, e.g. by other Tox instances, or it may mean a permission error. You may' - ' be able to gather more information from errno.') + raise RuntimeError('The function was unable to bind to a port. This may mean that all ports have ' + 'already been bound, e.g. by other Tox instances, or it may mean a permission error.' + ' You may be able to gather more information from errno.') elif tox_err_new == TOX_ERR_NEW['PROXY_BAD_TYPE']: raise ArgumentError('proxy_type was invalid.') elif tox_err_new == TOX_ERR_NEW['PROXY_BAD_HOST']: diff --git a/src/util.py b/src/util.py index 5e39141..aa548c1 100644 --- a/src/util.py +++ b/src/util.py @@ -27,14 +27,15 @@ def convert_time(t): return '%02d:%02d' % (h, m) +# obsolete def get_style(style): if style != 'default': return style else: - if system() == 'Linux': - return 'gtk' - elif system() == 'Windows': + if system() == 'Windows': return 'windows' + else: + return 'gtk' class Singleton(object):