diff --git a/src/app-configuration.defaults b/src/app-configuration.defaults index 8552a81a..0808d587 100644 --- a/src/app-configuration.defaults +++ b/src/app-configuration.defaults @@ -9,6 +9,7 @@ hide_gui = boolean(default=False) voice_enabled = boolean(default=False) ask_at_exit = boolean(default=True) use_invisible_keyboard_shorcuts = boolean(default=False) +log_level = string(default="error") [keymap] up = string(default="control+win+up") diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index f373023f..aad7a477 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -160,6 +160,10 @@ class baseBufferController(bufferController): self.buffer.account = account self.bind_events() + def get_formatted_message(self): + if self.type == "dm" or self.name == "sent_tweets" or self.name == "sent_direct_messages": return self.compose_function(self.get_right_tweet(), self.session.db, self.session.settings["general"]["relative_times"])[1] + return self.get_message() + def get_message(self): return " ".join(self.compose_function(self.get_right_tweet(), self.session.db, self.session.settings["general"]["relative_times"])) @@ -331,6 +335,7 @@ class eventsBufferController(bufferController): self.compose_function = compose.compose_event self.session = session self.type = self.buffer.type + self.get_formatted_message = self.get_message def get_message(self): if self.buffer.list.get_count() == 0: return _(u"Empty") diff --git a/src/controller/mainController.py b/src/controller/mainController.py index a5349b62..036bd15b 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -10,6 +10,7 @@ import output from twython import TwythonError from mysc.thread_utils import call_threaded from mysc.repeating_timer import RepeatingTimer +from mysc import restart import config import widgetUtils import pygeocoder @@ -92,9 +93,11 @@ class Controller(object): widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial) + widgetUtils.connect_event(self.view, widgetUtils.MENU, self.accountConfiguration, menuitem=self.view.account_settings) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.configuration, menuitem=self.view.prefs) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.exit, menuitem=self.view.close) if widgetUtils.toolkit == "wx": + log.debug("Binding the exit function...") widgetUtils.connectExitFunction(self.exit) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_tweet, self.view.compose) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_reply, self.view.reply) @@ -250,7 +253,18 @@ class Controller(object): d = settings.globalSettingsController() if d.response == widgetUtils.OK: d.save_configuration() + if d.needs_restart == True: + commonMessageDialogs.needs_restart() + restart.restart_program() + def accountConfiguration(self, *args, **kwargs): + buff = self.get_best_buffer() + d = settings.accountSettingsController(buff.session.settings, buff.session.db["user_name"]) +# if d.response == widgetUtils.OK: +# d.save_configuration() +# if d.needs_restart == True: +# commonMessageDialogs.needs_restart() +# restart.restart_program() def update_profile(self): pass @@ -341,12 +355,12 @@ class Controller(object): tweet = buffer.session.twitter.twitter.show_status(id=tweet_id) msg = messages.viewTweet(tweet, ) except TwythonError: - non_tweet = buffer.get_message() + non_tweet = buffer.get_formatted_message() msg = messages.viewTweet(non_tweet, False) elif buffer.type == "account" or buffer.type == "empty": return else: - non_tweet = buffer.get_message() + non_tweet = buffer.get_formatted_message() msg = messages.viewTweet(non_tweet, False) def open_timeline(self, user, timeline_tipe): @@ -485,6 +499,46 @@ class Controller(object): msg = _(u"%s. Empty") % (self.view.get_buffer_text(),) output.speak(msg) + def go_home(self): + buffer = self.get_current_buffer() + buffer.buffer.list.select_item(0) + try: + output.speak(buffer.get_message()) + except: + pass + + def go_end(self): + buffer = self.get_current_buffer() + buffer.buffer.list.select_item(buffer.buffer.list.get_count()-1) + try: + output.speak(buffer.get_message()) + except: + pass + + def go_page_up(self): + buffer = self.get_current_buffer() + if buffer.buffer.list.get_selected() <= 20: + index = 0 + else: + index = buffer.buffer.list.get_selected() - 20 + buffer.buffer.list.select_item(index) + try: + output.speak(buffer.get_message()) + except: + pass + + def go_page_down(self): + buffer = self.get_current_buffer() + if buffer.buffer.list.get_selected() >= buffer.buffer.list.get_count() - 20: + index = buffer.buffer.list.get_count()-1 + else: + index = buffer.buffer.list.get_selected() + 20 + buffer.buffer.list.select_item(index) + try: + output.speak(buffer.get_message()) + except: + pass + def url(self, *args, **kwargs): self.get_current_buffer().url() diff --git a/src/controller/settings.py b/src/controller/settings.py index 7074bb7c..21a4ebff 100644 --- a/src/controller/settings.py +++ b/src/controller/settings.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +import os +import sound_lib +import paths import widgetUtils import config import languageHandler @@ -11,6 +14,9 @@ class globalSettingsController(object): def __init__(self): super(globalSettingsController, self).__init__() self.dialog = configuration.configurationDialog() + self.create_config() + + def create_config(self): self.langs = languageHandler.getAvailableLanguages() langs = [] [langs.append(i[1]) for i in self.langs] @@ -36,4 +42,44 @@ class globalSettingsController(object): config.app["app-settings"]["use_invisible_keyboard_shorcuts"] = self.dialog.get_value("general", "use_invisible_shorcuts") pub.sendMessage("invisible-shorcuts-changed", registered=self.dialog.get_value("general", "use_invisible_shorcuts")) config.app["app-settings"]["voice_enabled"] = self.dialog.get_value("general", "disable_sapi5") - config.app["app-settings"]["hide_gui"] = self.dialog.get_value("general", "hide_gui") \ No newline at end of file + config.app["app-settings"]["hide_gui"] = self.dialog.get_value("general", "hide_gui") + config.app.write() + +class accountSettingsController(globalSettingsController): + def __init__(self, config, user_name): + self.config = config + self.user = user_name + super(accountSettingsController, self).__init__() + + def create_config(self): + self.dialog.create_general_account() + widgetUtils.connect_event(self.dialog.general.au, widgetUtils.BUTTON_PRESSED, self.manage_autocomplete) + self.dialog.set_value("general", "relative_time", self.config["general"]["relative_times"]) + self.dialog.set_value("general", "apiCalls", self.config["general"]["max_api_calls"]) + self.dialog.set_value("general", "itemsPerApiCall", self.config["general"]["max_tweets_per_call"]) + self.dialog.set_value("general", "reverse_timelines", self.config["general"]["reverse_timelines"]) + self.dialog.create_other_buffers() + self.dialog.set_value("buffers", "followers", self.config["other_buffers"]["show_followers"]) + self.dialog.set_value("buffers", "friends", self.config["other_buffers"]["show_friends"]) + self.dialog.set_value("buffers", "favs", self.config["other_buffers"]["show_favourites"]) + self.dialog.set_value("buffers", "blocks", self.config["other_buffers"]["show_blocks"]) + self.dialog.set_value("buffers", "mutes", self.config["other_buffers"]["show_muted_users"]) + self.dialog.set_value("buffers", "events", self.config["other_buffers"]["show_events"]) + self.dialog.create_ignored_clients(self.config["twitter"]["ignored_clients"]) + self.input_devices = sound_lib.input.Input.get_device_names() + self.output_devices = sound_lib.output.Output.get_device_names() + self.soundpacks = [] + [self.soundpacks.append(i) for i in os.listdir(paths.sound_path()) if os.path.isdir(paths.sound_path(i)) == True ] + self.dialog.create_sound(self.input_devices, self.output_devices, self.soundpacks) + self.dialog.set_value("sound", "volumeCtrl", self.config["sound"]["volume"]) + self.dialog.set_value("sound", "input", self.config["sound"]["input_device"]) + self.dialog.set_value("sound", "output", self.config["sound"]["output_device"]) + self.dialog.set_value("sound", "global_mute", self.config["sound"]["global_mute"]) + self.dialog.set_value("sound", "soundpack", self.config["sound"]["current_soundpack"]) + self.dialog.create_audio_services() + self.dialog.realize() + self.dialog.set_title(_(u"Account settings for %s") % (self.user,)) + self.response = self.dialog.get_response() + + def save_config(self): pass + def manage_autocomplete(self, *args, **kwargs): pass \ No newline at end of file diff --git a/src/mysc/restart.py b/src/mysc/restart.py index 2533b563..c6db1e11 100644 --- a/src/mysc/restart.py +++ b/src/mysc/restart.py @@ -1,9 +1,8 @@ # -*- coding: cp1252 -import sys, os, config +import sys, os def restart_program(): """ Function that restarts the application if is executed.""" - config.main.write() args = sys.argv[:] if not hasattr(sys, "frozen"): args.insert(0, sys.executable) diff --git a/src/widgetUtils/wxUtils.py b/src/widgetUtils/wxUtils.py index 90e56a9d..0680b083 100644 --- a/src/widgetUtils/wxUtils.py +++ b/src/widgetUtils/wxUtils.py @@ -39,4 +39,5 @@ def connect_event(parent, event, func, menuitem=None, *args, **kwargs): return getattr(parent, "Bind")(event, func, menuitem, *args, **kwargs) def connectExitFunction(exitFunction): - wx.GetApp().Bind(wx.EVT_END_SESSION, exitFunction) \ No newline at end of file + wx.GetApp().Bind(wx.EVT_QUERY_END_SESSION, exitFunction) + wx.GetApp().Bind(wx.EVT_END_SESSION, exitFunction) \ No newline at end of file diff --git a/src/wxUI/commonMessageDialogs.py b/src/wxUI/commonMessageDialogs.py index 1303e2e5..22e7cf39 100644 --- a/src/wxUI/commonMessageDialogs.py +++ b/src/wxUI/commonMessageDialogs.py @@ -9,4 +9,7 @@ def delete_tweet_dialog(parent): def exit_dialog(): dlg = wx.MessageDialog(None, _(u"Do you really want to close TW Blue?"), _(u"Exit"), wx.YES_NO|wx.ICON_QUESTION) - return dlg.ShowModal() \ No newline at end of file + return dlg.ShowModal() + +def needs_restart(): + wx.MessageDialog(None, _(u"The application requires to be restarted to save these changes. Press OK to do it now."), _("Restart TW Blue"), wx.OK).ShowModal() \ No newline at end of file diff --git a/src/wxUI/dialogs/configuration.py b/src/wxUI/dialogs/configuration.py index 27d4090d..d3d20f99 100644 --- a/src/wxUI/dialogs/configuration.py +++ b/src/wxUI/dialogs/configuration.py @@ -24,6 +24,32 @@ class general(wx.Panel, baseDialog.BaseWXDialog): sizer.Add(self.hide_gui, 0, wx.ALL, 5) self.SetSizer(sizer) +class generalAccount(wx.Panel, baseDialog.BaseWXDialog): + def __init__(self, parent): + super(generalAccount, self).__init__(parent) + sizer = wx.BoxSizer(wx.VERTICAL) + self.au = wx.Button(self, wx.NewId(), _(u"Set the autocomplete function")) + sizer.Add(self.au, 0, wx.ALL, 5) + self.relative_time = wx.CheckBox(self, wx.NewId(), _(U"Relative times")) + sizer.Add(self.relative_time, 0, wx.ALL, 5) + apiCallsBox = wx.BoxSizer(wx.HORIZONTAL) + apiCallsBox.Add(wx.StaticText(self, -1, _(u"API calls when the stream is started (One API call equals to 200 tweetts, two API calls equals 400 tweets, etc):")), 0, wx.ALL, 5) + self.apiCalls = wx.SpinCtrl(self, wx.NewId()) + self.apiCalls.SetRange(1, 10) + self.apiCalls.SetSize(self.apiCalls.GetBestSize()) + apiCallsBox.Add(self.apiCalls, 0, wx.ALL, 5) + sizer.Add(apiCallsBox, 0, wx.ALL, 5) + tweetsPerCallBox = wx.BoxSizer(wx.HORIZONTAL) + tweetsPerCallBox.Add(wx.StaticText(self, -1, _(u"Items on each API call")), 0, wx.ALL, 5) + self.itemsPerApiCall = wx.SpinCtrl(self, wx.NewId()) + self.itemsPerApiCall.SetRange(0, 200) + self.itemsPerApiCall.SetSize(self.itemsPerApiCall.GetBestSize()) + tweetsPerCallBox.Add(self.itemsPerApiCall, 0, wx.ALL, 5) + sizer.Add(tweetsPerCallBox, 0, wx.ALL, 5) + self.reverse_timelines = wx.CheckBox(self, wx.NewId(), _(u"Inverted buffers: The newest tweets will be shown at the beginning of the lists while the oldest at the end")) + sizer.Add(self.reverse_timelines, 0, wx.ALL, 5) + self.SetSizer(sizer) + class other_buffers(wx.Panel): def __init__(self, parent): super(other_buffers, self).__init__(parent) @@ -52,11 +78,11 @@ class ignoredClients(wx.Panel): clientsBox = wx.BoxSizer(wx.HORIZONTAL) clientsBox.Add(label, 0, wx.ALL, 5) clientsBox.Add(self.clients, 0, wx.ALL, 5) - add = wx.Button(self, -1, _(u"Add client")) - remove = wx.Button(self, -1, _(u"Remove client")) + self.add = wx.Button(self, -1, _(u"Add client")) + self.remove = wx.Button(self, -1, _(u"Remove client")) btnBox = wx.BoxSizer(wx.HORIZONTAL) - btnBox.Add(add, 0, wx.ALL, 5) - btnBox.Add(remove, 0, wx.ALL, 5) + btnBox.Add(self.add, 0, wx.ALL, 5) + btnBox.Add(self.remove, 0, wx.ALL, 5) sizer.Add(clientsBox, 0, wx.ALL, 5) sizer.Add(btnBox, 0, wx.ALL, 5) self.SetSizer(sizer) @@ -118,6 +144,10 @@ class audioServicesPanel(wx.Panel): self.SetSizer(mainSizer) class configurationDialog(baseDialog.BaseWXDialog): + + def set_title(self, title): + self.SetTitle(title) + def __init__(self): super(configurationDialog, self).__init__(None, -1) self.panel = wx.Panel(self) @@ -130,6 +160,11 @@ class configurationDialog(baseDialog.BaseWXDialog): self.notebook.AddPage(self.general, _(u"General")) self.general.SetFocus() + def create_general_account(self): + self.general = generalAccount(self.notebook) + self.notebook.AddPage(self.general, _(u"General")) + self.general.SetFocus() + def create_other_buffers(self): self.buffers = other_buffers(self.notebook) self.notebook.AddPage(self.buffers, _(u"Show other buffers")) diff --git a/src/wxUI/view.py b/src/wxUI/view.py index cb68649b..15b0a90d 100644 --- a/src/wxUI/view.py +++ b/src/wxUI/view.py @@ -17,7 +17,8 @@ class mainFrame(wx.Frame): self.lists = app.Append(wx.NewId(), _(u"&Lists manager")) self.sounds_tutorial = app.Append(wx.NewId(), _(u"Sounds &tutorial")) self.keystroke_editor = app.Append(wx.NewId(), _(u"&Edit keystrokes")) - self.prefs = app.Append(wx.ID_PREFERENCES, _(u"&Preferences")) + self.account_settings = app.Append(wx.NewId(), _(u"Account se&ttings")) + self.prefs = app.Append(wx.ID_PREFERENCES, _(u"&Global settings")) self.close = app.Append(wx.ID_EXIT, _(u"E&xit")) # Tweet menu