def __init__(self): """ Creates the main window. """ # Attributes self.current_show = None self.current_season = None self.config = Config() self.marks = SList(MARKS_FILE) self.favorites = SList(FAVORITES_FILE) self.accounts = ACCOUNTS self.settings_dialog = SettingsDialog(self) # Gtk builder self.builder = gtk.Builder() self.builder.add_from_file(MAIN_GUI_FILE) self.builder.connect_signals(self) # Getting the used widgets glade_objects = [ "main_window", "statusbar_label", "progress_box", "progress", "progress_label", "name_filter", "name_filter_clear", "name_list", "name_list_model", "file_viewer", "file_viewer_model", "mode_combo", "search_entry", "search_button", "search_clear", "sidebar", "sidebar_vbox", "path_label", "info_window", "info_title", "info_label", "info_image", "file_viewer_menu", "error_label", "error_dialog", "header_hbox", "main_hpaned", "about_dialog", ] for glade_object in glade_objects: setattr(self, glade_object, self.builder.get_object(glade_object)) # Set up the filter for the show list self.name_list_model_filter = self.name_list_model.filter_new() self.name_list_model_filter.set_visible_func(generic_visible_func, (self.name_filter, NAME_LIST_COLUMN_TEXT)) self.name_list.set_model(self.name_list_model_filter) # Now we show the window self.main_window.show_all() # Start on last mode try: last_mode = self.config.get_key("last_mode") getattr(self, "set_mode_%s" % last_mode.lower().replace(" ", "_"))() self.mode_combo.set_active(MODES.index(last_mode)) except: self.set_mode_shows() # Login self.background_task(self.login_accounts, freeze=False)
class GuiManager(object): """ Main class, loads the gui and handles all events. """ def __init__(self): """ Creates the main window. """ # Attributes self.current_show = None self.current_season = None self.config = Config() self.marks = SList(MARKS_FILE) self.favorites = SList(FAVORITES_FILE) self.accounts = ACCOUNTS self.settings_dialog = SettingsDialog(self) # Gtk builder self.builder = gtk.Builder() self.builder.add_from_file(MAIN_GUI_FILE) self.builder.connect_signals(self) # Getting the used widgets glade_objects = [ "main_window", "statusbar_label", "progress_box", "progress", "progress_label", "name_filter", "name_filter_clear", "name_list", "name_list_model", "file_viewer", "file_viewer_model", "mode_combo", "search_entry", "search_button", "search_clear", "sidebar", "sidebar_vbox", "path_label", "info_window", "info_title", "info_label", "info_image", "file_viewer_menu", "error_label", "error_dialog", "header_hbox", "main_hpaned", "about_dialog", ] for glade_object in glade_objects: setattr(self, glade_object, self.builder.get_object(glade_object)) # Set up the filter for the show list self.name_list_model_filter = self.name_list_model.filter_new() self.name_list_model_filter.set_visible_func(generic_visible_func, (self.name_filter, NAME_LIST_COLUMN_TEXT)) self.name_list.set_model(self.name_list_model_filter) # Now we show the window self.main_window.show_all() # Start on last mode try: last_mode = self.config.get_key("last_mode") getattr(self, "set_mode_%s" % last_mode.lower().replace(" ", "_"))() self.mode_combo.set_active(MODES.index(last_mode)) except: self.set_mode_shows() # Login self.background_task(self.login_accounts, freeze=False) def login_accounts(self): accounts = self.config.get_key("accounts") for account in accounts: account_name = account[0] username = account[1]["username"] password = base64.b64decode(account[1]["password"]) try: account_obj = ACCOUNTS[account_name] except KeyError: print "Warning: account not recognized: %s" % account_name continue if username and password: account_obj.login(username, password) def freeze(self, status_message="Loading..."): """ Freezes the gui so the user can't interact with it. """ self.header_hbox.set_sensitive(False) self.main_hpaned.set_sensitive(False) self.set_status_message(status_message) def unfreeze(self): """ Sets the widgets to be usable. """ self.header_hbox.set_sensitive(True) self.main_hpaned.set_sensitive(True) self.set_status_message("") def background_task(self, func, callback=None, *args, **kwargs): """ Freezes the gui, starts a thread with func. When it's done, unfreezes the gui and calls callback with the result. The results it's a tuple (is_error, result) with a boolean if an error has ocurred and the exception, or the result if there was no errors. """ status_message = "Loading..." freeze = True if "status_message" in kwargs: status_message = kwargs["status_message"] del kwargs["status_message"] if "freeze" in kwargs: freeze = kwargs["freeze"] del kwargs["freeze"] if freeze: self.freeze(status_message) else: kwargs["unfreeze"] = False if "unfreeze" in kwargs and not kwargs["unfreeze"]: real_callback = callback del kwargs["unfreeze"] else: def real_callback(result): self.unfreeze() callback(result) if callback == None: def real_callback((is_error, result)): if is_error: print "Error: %s" % result GtkThreadRunner(real_callback, func, *args, **kwargs) def set_status_message(self, message): """ Sets the message shown in the statusbar. """ self.statusbar_label.set_label(message) def set_mode_shows(self, *args): """ Sets the current mode to shows. """ self.sidebar.show() self.search_entry.set_text("") self.name_filter.set_text("") self.path_label.set_text("") self.name_list_model.clear() self.background_task(pycavane.api.Show.search, self.display_shows, status_message="Obtaining shows list") def set_mode_movies(self): """ Sets the current mode to movies. """ self.name_list_model.clear() self.search_entry.grab_focus() self.sidebar.hide() self.path_label.set_text("") self.name_filter.set_text("") def set_mode_favorites(self): """ Sets the current mode to favorites. """ self.sidebar.show() self.search_entry.set_text("") self.path_label.set_text("") self.name_filter.set_text("") self.name_list_model.clear() for favorite in self.favorites.get_all(): show = pycavane.api.Show.search(favorite).next() self.name_list_model.append([show.name, show]) def set_mode_latest_movies(self): """ Sets the curret mode to latest movies. """ self.sidebar.hide() self.background_task( pycavane.api.Movie.get_latest, self.display_movies, status_message="Loading latest movies..." ) def set_mode_recomended_movies(self): """ Sets the curret mode to recomended movies. """ self.sidebar.hide() self.background_task( pycavane.api.Movie.get_recomended, self.display_movies, status_message="Loading recomended movies..." ) def update_favorites(self, favorites): for fav_name in favorites: if fav_name not in self.favorites.get_all(): self.favorites.add(fav_name) if self.get_mode() == MODE_FAVORITES: self.set_mode_favorites() def get_mode(self): """ Returns the current mode. i.e the value of the mode combobox. The result will be the constant MODE_* (see constants definitions). """ model = self.mode_combo.get_model() active = self.mode_combo.get_active() mode_text = model[active][0] # Poscondition assert mode_text in MODES return mode_text def report_error(self, message): """ Shows up an error dialog to the user. """ self.error_label.set_label(message) self.error_dialog.show_all() self.set_status_message("") self.unfreeze() def display_shows(self, (is_error, result)): """ Displays the shows. """ self.name_list_model.clear() self.file_viewer_model.clear() if is_error: message = "Problem fetching shows, " message += "please try again in a few minutes." self.report_error(message) return for show in result: self.name_list_model.append([show.name, show])
class GuiManager(object): """ Main class, loads the gui and handles all events. """ def __init__(self): """ Creates the main window. """ # Attributes self.avaliable_modes = [] self.current_show = None self.current_season = None is_first_time = not os.path.exists(CONFIG_FILE) self.config = Config.get() # API try: self.api = getattr(Hosts, self.config.get_key("site")).api except Exception, error: self.api = Hosts.AVALIABLE_APIS[0] self.marks = SList(MARKS_FILE) self.favorites = SList(FAVORITES_FILE) self.accounts = ACCOUNTS self.settings_dialog = SettingsDialog(self) # Gtk builder self.builder = gtk.Builder() self.builder.add_from_file(MAIN_GUI_FILE) self.builder.connect_signals(self) # Getting the used widgets glade_objects = [ "main_window", "statusbar_label", "progress_box", "progress", "progress_label", "name_filter", "name_filter_clear", "name_list", "name_list_model", "file_viewer", "file_viewer_model", "mode_combo", "mode_liststore", "site_combo", "search_button", "search_clear", "search_entry", "search_hbox", "sidebar", "sidebar_vbox", "path_label", "info_window", "info_title", "info_label", "info_image", "file_viewer_menu", "error_label", "error_dialog", "header_hbox", "main_hpaned", "about_dialog", "site_liststore", ] for glade_object in glade_objects: setattr(self, glade_object, self.builder.get_object(glade_object)) # Set up the filter for the show list self.name_list_model_filter = self.name_list_model.filter_new() self.name_list_model_filter.set_visible_func( generic_visible_func, (self.name_filter, NAME_LIST_COLUMN_TEXT)) self.name_list.set_model(self.name_list_model_filter) # Get last mode, needs to be before the filling combo functions last_mode = self.config.get_key("last_mode") # Fill combobox self.fill_sites_combobox() self.fill_mode_combobox() # Set last window position and size last_x, last_y = self.config.get_key("last_window_pos") last_width, last_height = self.config.get_key("last_window_size") self.main_window.move(last_x, last_y) self.main_window.resize(last_width, last_height) # Now we show the window self.main_window.show_all() # Start on last mode try: self.mode_combo.set_active(self.avaliable_modes.index(last_mode)) except: self.set_mode_shows() # Login self.background_task(self.login_accounts, freeze=False) if is_first_time: wizard = Wizard(self.main_window) wizard.show()
# run linked lists from SList import SList from SLNode import SLNode sll = SList() sll.head = SLNode('Alice') sll.head.next = SLNode('Bob') sll.head.next.next = SLNode('Person') sll.print_all_vals() sll.insert_after('Bob', 'Stacy') sll.delete('Bob') sll.print_all_vals() sll.delete('Stacy') sll.print_all_vals() sll.prepend('The First!').prepend("the most first") sll.print_all_vals() sll.append('The Last!').append('The Most Last!') sll.print_all_vals()