class BaseGabberWindow: def __init__(self, widget_name): self.__xml = XML(ENV_VARS.pkgdatadir + widget_name + ".glade", widget_name) self.window = self.__xml.get_widget(widget_name) self.window.connect("delete-event", self.on_delete_event) def __del__(self): del self.window del self.__xml def show(self): self.window.show() def hide(self): self.window.hide() def get_widget(self, name): return self.__xml.get_widget(name) ## XXX this seems icky def close(self): self.hide() del self def on_delete_event(self, win, event): self.close()
class GtkUI(GtkPluginBase): def enable(self): log.debug("Stats plugin enable called") self.config = deluge.configmanager.ConfigManager( "stats.gtkui.conf", DEFAULT_CONF) self.glade = XML(common.get_resource("config.glade")) component.get("Preferences").add_page( "Stats", self.glade.get_widget("prefs_box")) component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(common.get_resource("tabs.glade")), self.config['colors']) self.torrent_details = component.get('TorrentDetails') self.torrent_details.add_tab(self.graphs_tab) def disable(self): component.get("Preferences").remove_page("Stats") component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs) self.torrent_details.remove_tab(self.graphs_tab.get_name()) def on_apply_prefs(self): log.debug("applying prefs for Stats") gtkconf = {} for graph, colors in self.config['colors'].items(): gtkconf[graph] = {} for value, color in colors.items(): try: color_btn = self.glade.get_widget("%s_%s_color" % (graph, value)) gtkconf[graph][value] = str(color_btn.get_color()) except: gtkconf[graph][value] = DEFAULT_CONF['colors'][graph][ value] self.config['colors'] = gtkconf self.graphs_tab.set_colors(self.config['colors']) config = {} client.stats.set_config(config) def on_show_prefs(self): for graph, colors in self.config['colors'].items(): for value, color in colors.items(): try: color_btn = self.glade.get_widget("%s_%s_color" % (graph, value)) color_btn.set_color(gtk.gdk.Color(color)) except: log.debug("Unable to set %s %s %s" % (graph, value, color)) client.stats.get_config().addCallback(self.cb_get_config) def cb_get_config(self, config): "callback for on show_prefs" pass
def __init_attributes(self, editor): self.__editor = editor self.__manager = None from os.path import join folder = editor.get_current_folder(globals()) file_ = join(folder, "GUI", "FindBar.glade") from gtk.glade import XML self.__glade = XML(file_, "BarWindow", "scribes") self.__mglade = XML(file_, "MenuWindow", "scribes") return
def load_glade_file_get_widgets_and_connect_signals( glade_file, root_widget, widget_holder=None, signal_recipient=None ): glade_xml = XML(glade_file, root_widget) if signal_recipient != None: glade_xml.signal_autoconnect( signal_recipient ) for widget in glade_xml.get_widget_prefix(""): if isinstance(widget_holder, dict): widget_holder[get_widget_name(widget)] = widget else: setattr( widget_holder, get_widget_name(widget), widget )
def enable(self): log.debug("Stats plugin enable called") self.config = deluge.configmanager.ConfigManager("stats.gtkui.conf", DEFAULT_CONF) self.glade = XML(common.get_resource("config.glade")) component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box")) component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(common.get_resource("tabs.glade")), self.config['colors']) self.torrent_details = component.get('TorrentDetails') self.torrent_details.add_tab(self.graphs_tab)
class GtkUI(GtkPluginBase): def enable(self): log.debug("Stats plugin enable called") self.config = deluge.configmanager.ConfigManager("stats.gtkui.conf", DEFAULT_CONF) self.glade = XML(common.get_resource("config.glade")) component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box")) component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(common.get_resource("tabs.glade")), self.config["colors"]) self.torrent_details = component.get("TorrentDetails") self.torrent_details.add_tab(self.graphs_tab) def disable(self): component.get("Preferences").remove_page("Stats") component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs) self.torrent_details.remove_tab(self.graphs_tab.get_name()) def on_apply_prefs(self): log.debug("applying prefs for Stats") gtkconf = {} for graph, colors in self.config["colors"].items(): gtkconf[graph] = {} for value, color in colors.items(): try: color_btn = self.glade.get_widget("%s_%s_color" % (graph, value)) gtkconf[graph][value] = str(color_btn.get_color()) except: gtkconf[graph][value] = DEFAULT_CONF["colors"][graph][value] self.config["colors"] = gtkconf self.graphs_tab.set_colors(self.config["colors"]) config = {} client.stats.set_config(config) def on_show_prefs(self): for graph, colors in self.config["colors"].items(): for value, color in colors.items(): try: color_btn = self.glade.get_widget("%s_%s_color" % (graph, value)) color_btn.set_color(gtk.gdk.Color(color)) except: log.debug("Unable to set %s %s %s" % (graph, value, color)) client.stats.get_config().addCallback(self.cb_get_config) def cb_get_config(self, config): "callback for on show_prefs" pass
def __init__(self, parent=None): try: assert self.glade_file filepath = os.path.join(self.glade_dir, self.glade_file) if self.glade_typedict: wtree = XML(filepath, typedict=self.glade_typedict, domain='pitivi') else: # pygtk 2.4 doesn't like typedict={} ? wtree = XML(filepath, domain='pitivi') except RuntimeError, e: raise RuntimeError('Failed to load file %s from directory %s: %s' % (self.glade_file, self.glade_dir, e))
def __init_attributes(self, editor): self.__editor = editor pwd = editor.get_current_folder(globals()) self.__oglade = editor.get_gui_object(globals(), "OpenDialogGUI/GUI/GUI.glade") from os.path import join from gtk.glade import XML file_ = join(pwd, "NewFileDialogGUI/NewFileDialog.glade") self.__nglade = XML(file_, "Window", "scribes") file_ = join(pwd, "RemoteDialogGUI/RemoteDialog.glade") self.__rglade = XML(file_, "Window", "scribes") self.__open_manager = None self.__remote_manager = None self.__newfile_manager = None return False
def __init_attributes(self, editor): self.__editor = editor from os.path import join glade_file = join(editor.data_folder, "Editor.glade") from gtk.glade import XML self.__glade = XML(glade_file, "Window", "scribes") return
def __init_attributes(self, editor): self.__editor = editor from os.path import join, split current_folder = split(globals()["__file__"])[0] glade_file = join(current_folder, "DocumentBrowser.glade") from gtk.glade import XML self.__glade = XML(glade_file, "Window", "scribes") return
def _attach_widgets(self): # Attach widgets in the widgetlist to the view specified, so # widgets = [label1, button1] -> view.label1, view.button1 for w in self._widgets: widget = XML.get_widget(self, w) if widget is not None: setattr(self._view, w, widget) else: log.warn("Widget %s was not found in glade widget tree." % w)
def get_widget(self, name): """Retrieves the named widget from the View (or glade tree)""" name = name.replace('.', '_') widget = XML.get_widget(self, name) if widget is None: raise AttributeError( "Widget %s not found in view %s" % (name, self._view)) return widget
def get_widget(self, name): """Retrieves the named widget from the View (or glade tree)""" name = name.replace('.', '_') widget = XML.get_widget(self, name) if widget is None: raise AttributeError("Widget %s not found in view %s" % (name, self._view)) return widget
def _setup_popup_menu(self, fname): self.popup_gld = XML(fname, "popup_menu", "gtkpacman") popup_h_dict = { "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "search": self.search } self.popup_gld.signal_autoconnect(popup_h_dict) self.popup = self.popup_gld.get_widget("popup_menu")
def __init__(self, parent=None): try: assert self.glade_file if 'pitivi.exe' in __file__.lower(): from pitivi.configure import WIN32_LIBDIR filepath = os.path.join(self.glade_dir, WIN32_LIBDIR + self.glade_file) else: filepath = os.path.join(self.glade_dir, self.glade_file) if self.glade_typedict: wtree = XML(filepath, typedict=self.glade_typedict, domain='pitivi') else: # pygtk 2.4 doesn't like typedict={} ? wtree = XML(filepath, domain='pitivi') except RuntimeError, e: raise RuntimeError('Failed to load file %s from directory %s: %s' % (self.glade_file, self.glade_dir, e))
def enable(self): self.glade = XML(self.get_resource("config.glade")) self.plugin.add_preferences_page("Stats", self.glade.get_widget("prefs_box")) self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade"))) self.torrent_details = component.get('TorrentDetails') self.torrent_details.notebook.append_page(self.graphs_tab.window, self.graphs_tab.label)
def get_glade_object(self, globals_, basepath, object_name): #FIXME: This function will soon be deprecated. It uses glade. # GTKBUILDER should be use instead.get_gui_object uses # GTKBUILDER. from os.path import join folder = self.get_current_folder(globals_) file_ = join(folder, basepath) from gtk.glade import XML glade = XML(file_, object_name, "scribes") # glade = XML(file_) return glade
def enable(self): log.debug("Stats plugin enable called") self.config = deluge.configmanager.ConfigManager("stats.gtkui.conf", DEFAULT_CONF) self.glade = XML(common.get_resource("config.glade")) component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box")) component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(common.get_resource("tabs.glade")), self.config["colors"]) self.torrent_details = component.get("TorrentDetails") self.torrent_details.add_tab(self.graphs_tab)
class Base: __widget = None __first_item = None def __init__(self, name): self.__xml = XML(ENV_VARS.pkgdatadir + name + ".glade", name) self.__widget = self.__xml.get_widget(name) self.__widget.show() def getItem(self, name): return self.__xml.get_widget(name) def addItem(self, mi): mi.show() self.__first_item = mi self.__widget.prepend(mi) def activate(self): if self.__first_item: self.__first_item.activate() def popup(self, *args): self.__widget.popup(*args)
class GtkUI(object): def __init__(self, plugin_api, plugin_name): log.debug("Calling Stats UI init") self.plugin = plugin_api def enable(self): self.glade = XML(self.get_resource("config.glade")) self.plugin.add_preferences_page("Stats", self.glade.get_widget("prefs_box")) self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade"))) self.torrent_details = component.get('TorrentDetails') self.torrent_details.notebook.append_page(self.graphs_tab.window, self.graphs_tab.label) def disable(self): self.plugin.remove_preferences_page("Stats") self.plugin.deregister_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.deregister_hook("on_show_prefs", self.on_show_prefs) def on_apply_prefs(self): log.debug("applying prefs for Stats") config = { "test":self.glade.get_widget("txt_test").get_text() } aclient.stats_set_config(None, config) def on_show_prefs(self): aclient.stats_get_config(self.cb_get_config) def cb_get_config(self, config): "callback for on show_prefs" self.glade.get_widget("txt_test").set_text(config["test"]) def get_resource(self, filename): import pkg_resources, os return pkg_resources.resource_filename("stats", os.path.join("data", filename))
def __init__(self, fname, database, uid, icon): # Setup the main gui: read glade file, connect signals self.gld = XML(fname, "main_win", "gtkpacman") self.gld.get_widget("main_win").set_icon(pixbuf_new_from_file(icon)) h_dict = {"quit": self.quit, "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "execute": self.execute, "up_sys": self.upgrade_system, "refr_db": self.refresh_database, "add_local": self.add_from_local_file, "clear_cache": self.clear_cache, "empty_cache": self.empty_cache, "search_pac": self.search, "show_popup": self.show_popup, "about": self.about, "pacs_changed": self.pacs_changed, "repo_changed": self.repo_changed, "make_pkg": self.make_package, "sum_txt_on_motion": self.sum_txt_on_motion} self.gld.signal_autoconnect(h_dict) self.uid = uid self.fname = fname self.icon = icon self.database = database self.queues = {"add": [], "remove": []} self.search_iter = None #Setup secondary gui elements self._setup_popup_menu(fname) self._setup_repos_tree() self._setup_pacs_models() self._setup_combobox() self._setup_pacs_tree() self._setup_files_tree() self._setup_log() #Deactivate some widgets self.gld.get_widget("makepkg").set_sensitive(False) # Restore size self._setup_size() #Check pacman version self._pacman_ver_check() self._statusbar('Ready for your command')
def __init__(self, fname, database, uid, icon): # Setup the main gui: read glade file, connect signals self.gld = XML(fname, "main_win", "gtkpacman") self.gld.get_widget("main_win").set_icon(pixbuf_new_from_file(icon)) h_dict = {"quit": self.quit, "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "execute": self.execute, "up_sys": self.upgrade_system, "refr_db": self.refresh_database, "add_local": self.add_from_local_file, "clear_cache": self.clear_cache, "empty_cache": self.empty_cache, "search_pac": self.search, "show_popup": self.show_popup, "about": self.about, "pacs_changed": self.pacs_changed, "repo_changed": self.repo_changed} self.gld.signal_autoconnect(h_dict) self.fname = fname self.icon = icon self.database = database self.queues = {"add": [], "remove": []} self.search_iter = None #Setup secondary gui elements self._setup_popup_menu(fname) self._setup_repos_tree() self._setup_pacs_models() self._setup_pacs_tree() self._setup_files_tree() #Setup statusbar stat_bar = self.gld.get_widget("statusbar") self.stat_id = stat_bar.get_context_id("stat") stat_bar.push(self.stat_id, _("Done.")) #Check if root, else notufy it and deactivate some widgets if uid: self._setup_avaible_actions() dlg = non_root_dialog(icon) dlg.run() dlg.destroy()
def __init_attributes(self, editor): self.__editor = editor from os.path import join, split current_folder = split(globals()["__file__"])[0] glade_file = join(current_folder, "SymbolBrowser.glade") from gtk.gdk import pixbuf_new_from_file class_pixbuf = join(current_folder, "class.png") self.__class_pixbuf = pixbuf_new_from_file(class_pixbuf) function_pixbuf = join(current_folder, "function.png") self.__function_pixbuf = pixbuf_new_from_file(function_pixbuf) method_pixbuf = join(current_folder, "method.png") self.__method_pixbuf = pixbuf_new_from_file(method_pixbuf) from gtk.glade import XML self.__glade = XML(glade_file, "Window", "scribes") return
def __init__(self, widget_name): self.__xml = XML(ENV_VARS.pkgdatadir + widget_name + ".glade", widget_name) self.window = self.__xml.get_widget(widget_name) self.window.connect("delete-event", self.on_delete_event)
def __init__(self, name): self.__xml = XML(ENV_VARS.pkgdatadir + name + ".glade", name) self.__widget = self.__xml.get_widget(name) self.__widget.show()
def __init__(self, view, gladefile, domain=None): self._view = view self._gladefile = gladefile XML.__init__(self, gladefile, domain) self._widgets = [w.get_name() for w in self.get_widget_prefix('')] self._attach_widgets()
class gui: def __init__(self, fname, database, uid, icon): # Setup the main gui: read glade file, connect signals self.gld = XML(fname, "main_win", "gtkpacman") self.gld.get_widget("main_win").set_icon(pixbuf_new_from_file(icon)) h_dict = {"quit": self.quit, "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "execute": self.execute, "up_sys": self.upgrade_system, "refr_db": self.refresh_database, "add_local": self.add_from_local_file, "clear_cache": self.clear_cache, "empty_cache": self.empty_cache, "search_pac": self.search, "show_popup": self.show_popup, "about": self.about, "pacs_changed": self.pacs_changed, "repo_changed": self.repo_changed, "make_pkg": self.make_package, "sum_txt_on_motion": self.sum_txt_on_motion} self.gld.signal_autoconnect(h_dict) self.uid = uid self.fname = fname self.icon = icon self.database = database self.queues = {"add": [], "remove": []} self.search_iter = None #Setup secondary gui elements self._setup_popup_menu(fname) self._setup_repos_tree() self._setup_pacs_models() self._setup_combobox() self._setup_pacs_tree() self._setup_files_tree() self._setup_log() #Deactivate some widgets self.gld.get_widget("makepkg").set_sensitive(False) # Restore size self._setup_size() #Check pacman version self._pacman_ver_check() self._statusbar('Ready for your command') def _setup_size(self, state=False): user_home_dir = getpwuid(geteuid())[-2] #state = bool, True = save, False = restore if state: # Save state if exists(user_home_dir): gtkpacman_conf_f = open( "%s/.gtkpacman" %user_home_dir, 'w') main_win_size = self.gld.get_widget("main_win").get_size() hp_position = self.gld.get_widget("hpaned").get_position() vp_position = self.gld.get_widget("vpaned").get_position() print main_win_size, hp_position, vp_position gtkpacman_conf_f.write("%s %s %s %s" %(main_win_size[0], main_win_size[1], hp_position, vp_position)) gtkpacman_conf_f.close() else: # Restore state if exists(user_home_dir + "/.gtkpacman"): # Get sizes form file ~/.gtkpacman if exists gtkpacman_conf_f = open( "%s/.gtkpacman" %user_home_dir, 'r' ) size = gtkpacman_conf_f.readline().split(" ") gtkpacman_conf_f.close() self.gld.get_widget("main_win").resize(int(size[0]), int(size[1])) self.gld.get_widget("hpaned").set_position(int(size[2])) self.gld.get_widget("vpaned").set_position(int(size[3])) else: # else ~/.gtkpacman don't exists, set delault size self.gld.get_widget("main_win").resize(690, 490) self.gld.get_widget("main_win").show_all() def _setup_pacs_tree(self): pacs_tree = self.gld.get_widget("pacs_tree") repos_tree = self.gld.get_widget("repos_tree") pacs_tree.set_reorderable(False) pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=0) pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=1) pacs_tree.insert_column_with_attributes(-1, _("Package"), CellRendererText(), text=2) pacs_tree.insert_column_with_attributes(-1, _("Installed Version"), CellRendererText(), text=3) self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Avaible Version"), CellRendererText(), text=4 ) self.repo_col = pacs_tree.insert_column_with_attributes( -1, _("Repo"), CellRendererText(), text=5 ) sort_id = 0 for col in pacs_tree.get_columns(): col.set_reorderable(True) col.set_sort_column_id(sort_id) col.set_clickable(True) col.set_resizable(True) sort_id += 1 col.set_visible(False) col_4 = pacs_tree.get_column(4) col_4.set_max_width(105) # Select first repo in repos_tree repos_tree.set_cursor_on_cell(0) def _setup_popup_menu(self, fname): self.popup_gld = XML(fname, "popup_menu", "gtkpacman") popup_h_dict = { "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "search": self.search } self.popup_gld.signal_autoconnect(popup_h_dict) self.popup = self.popup_gld.get_widget("popup_menu") def _setup_repos_tree(self): repos_tree = self.gld.get_widget("repos_tree") repos_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) repos_tree.set_model(self._make_repos_model()) return def _setup_files_tree(self): file_tree = self.gld.get_widget("files") file_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) return def _setup_pacs_models(self): self.models = {} try: self.models[_("foreigners")] = installed_list(self.database["foreigners"]) except KeyError: self.database["foreigners"] = [] self.models[_("foreigners")] = installed_list(self.database["foreigners"]) for repo in self.database.keys(): if repo == _("foreigners") or repo == "local": continue self.models[repo] = {} all_mod = all_list(self.database[repo]) inst_mod = installed_list(self.database[repo]) self.models[repo][_("all")] = all_mod if repo != 'local': self.models[repo][_("installed")] = inst_mod return def _setup_combobox(self): combo_list = ListStore(str) combo_box = self.gld.get_widget("combo_box_options") combo_box.set_model(combo_list) combo_box.append_text("all") combo_box.append_text("installed") combo_box.append_text("explicitly installed") combo_box.set_active(0) combo_box.connect("changed", self.combobox_options_changed) def _setup_log(self): log_text_view = self.gld.get_widget("log") text_buffer = TextBuffer() iter = text_buffer.get_start_iter() log_file = self.database.log.values()[0] while log_file: text_buffer.insert(iter, log_file.pop()) log_text_view.set_buffer(text_buffer) def _make_repos_model (self): repos_model = TreeStore(str) repos = sorted( self.database.repos.keys() ) for repo in repos: if repo == "foreigners" or repo == "local": continue repo_it = repos_model.append(None, [repo]) repos_model.append(None, [_("foreigners")]) repos_model.append(None, [_("orphans")]) return repos_model #------------------------ Refresh: database, models, trees, repos ------------# def _refresh_trees_and_queues(self, widget=None, pacs_queues=None): selected_pac_before = str() selected_pac_after = str() selected_pac_path = None selected_repo_path = None repos_tree = self.gld.get_widget("repos_tree") pacs_tree = self.gld.get_widget("pacs_tree") repos_model, repo_iter = repos_tree.get_selection().get_selected() # Need to be sure that repository was selected before fetching it's name if repo_iter: selected_repo_path = repos_model.get_path(repo_iter) selected_repo = repos_model.get_value(repo_iter, 0) pacs_model, pac_iter = pacs_tree.get_selection().get_selected() # Need to be sure that package was selected before fetching packages name if pac_iter: selected_pac_before = pacs_model.get_value(pac_iter, 2) selected_pac_path = pacs_model.get_path(pac_iter) # Refresh database, packages models, repositories models self.database.refresh() self._setup_pacs_models() repos_tree.set_model(self._make_repos_model()) # Check if repo was selected if type(selected_repo_path) == tuple: repos_tree.set_cursor(selected_repo_path) pacs_model = pacs_tree.get_model() else: repos_tree.set_cursor_on_cell(0) # Check if selected pac path is tuple, otherwise it wasn't selected and we skip this moment if type(selected_pac_path) == tuple: try: pac_iter = pacs_model.get_iter(selected_pac_path) selected_pac_after = pacs_model.get_value(pac_iter, 2) except ValueError: pass # Compare pacs after refreshing, if match then select both repository and package if (selected_pac_before and selected_pac_before == selected_pac_after and selected_repo != 'orphans'): pacs_tree.scroll_to_cell(selected_pac_path) pacs_tree.set_cursor(selected_pac_path) else: summary_buffer = self.gld.get_widget("summary").get_buffer() file_tree = self.gld.get_widget("files") summary_buffer.set_text('') file_model = file_tree.get_model() if file_model: file_model.clear() file_tree.set_model(file_model) del(pacs_queues) self.queues["add"] = [] self.queues["remove"] = [] self._setup_log() self._pacman_ver_check() self.gld.get_widget("main_win").set_sensitive(True) #----------------------------- Refresh End ---------------------------# #----------------------------- Callbacks ------------------------------# def show_popup(self, widget, event, data=None): if event.button == 3: self.popup.popup(None, None, None, event.button, event.time) else: self.popup.popdown() def combobox_options_changed(self, widget, data=None): repos_tree = self.gld.get_widget("repos_tree") pacs_tree = self.gld.get_widget("pacs_tree") combo_box_options = self.gld.get_widget("combo_box_options") # Clear summary and files summary_buffer = self.gld.get_widget("summary").get_buffer() file_tree = self.gld.get_widget("files") summary_buffer.set_text('') file_model = file_tree.get_model() if file_model: file_model.clear() file_tree.set_model(file_model) repos_model, tree_iter = repos_tree.get_selection().get_selected() selected_repo = repos_model.get_value(tree_iter, 0) selected_option = combo_box_options.get_active_text() if selected_option == 'explicitly installed': try: pacs_model = self.models[ selected_repo ][ selected_option ] except KeyError: self.database.set_reason(selected_repo) self.models[ selected_repo ]['explicitly installed' ] = explicitly_list(self.database[ selected_repo ]) pacs_model = self.models[ selected_repo ][ selected_option ] pacs_tree.set_model(pacs_model) stat = (len(pacs_model), selected_repo, self.database.repos.get( selected_repo )) self._statusbar(stat) def repo_changed(self, widget, data=None): def _setup_status(pacs_model, ext_msg=True): # ext_msg = extended message pacs_tree.set_model(pacs_model) # pass more info to statusbar if repo isn't: orphans, foreigners or Search... if ext_msg: stat = (len(pacs_model), selected_repo, self.database.repos.get( selected_repo )) self._statusbar(stat) else: stat = (len(pacs_model), selected_repo) self._statusbar(stat) def _setup_orphans_fork(): self.database.set_orphans() self.models['orphans'] = orphan_list( self.database['local'] ) parent_iter = repos_model.iter_parent(tree_iter) _setup_status( self.models['orphans'], False ) col_5.set_visible(True) main_win.window.set_cursor(None) repos_tree = self.gld.get_widget("repos_tree") pacs_tree = self.gld.get_widget("pacs_tree") combo_box_options = self.gld.get_widget("combo_box_options") # Hide last column 'Repo' if it's visible col_5 = pacs_tree.get_column(5) col_5.set_visible(False) repos_model, tree_iter = repos_tree.get_selection().get_selected() # Need to be sure that repo was selected if tree_iter: selected_repo = repos_model.get_value(tree_iter, 0) # If it wasn't than we select first repo available and return else: repos_tree.set_cursor_on_cell(0) return # When clicking on repo we unselect any selected pac and clear summary and files pacs_tree.get_selection().unselect_all() summary_buffer = self.gld.get_widget("summary").get_buffer() file_tree = self.gld.get_widget("files") summary_buffer.set_text('') file_model = file_tree.get_model() if file_model: file_model.clear() file_tree.set_model(file_model) # Fetch orphans packages if selected_repo == 'orphans': combo_box_options.set_sensitive(False) try: _setup_status( self.models['orphans'], False ) col_5.set_visible(True) except KeyError: main_win = self.gld.get_widget("main_win") main_win.window.set_cursor(Cursor(WATCH)) self._statusbar('Searching for orphans Please wait...') gobject.idle_add(_setup_orphans_fork) # If selected repo is: foreigners, orphans or search then we deactivate combo_box_options elif selected_repo == 'foreigners' or selected_repo.startswith('Search'): combo_box_options.set_sensitive(False) # Fetch search model if selected_repo.startswith('Search'): col_5.set_visible(True) pacs_model = self.models["search"] # Jump in if selected repo is foreigners else: pacs_model = self.models[ selected_repo ] pacs_tree.set_model(pacs_model) _setup_status(pacs_model, False) # Otherwise we check selected option from combo_box_options and # fetch model appropriate to selected option else: combo_box_options.set_sensitive(True) selected_option = combo_box_options.get_active_text() if selected_option == 'explicitly installed': try: pacs_model = self.models[ selected_repo ][ selected_option ] except KeyError: self.database.set_reason(selected_repo) self.models[ selected_repo ][ 'explicitly installed' ] = explicitly_list(self.database[ selected_repo ]) pacs_model = self.models[ selected_repo ][ selected_option ] _setup_status(pacs_model) def pacs_changed(self, widget, data=None): def _fork(): pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) self._set_pac_summary(pac) file_model = file_list(pac.filelist) file_tree.set_model(file_model) self._statusbar() main_win.window.set_cursor(None) main_win = self.gld.get_widget("main_win") sum_txt = self.gld.get_widget("summary") file_tree = self.gld.get_widget("files") sum_buf = sum_txt.get_buffer() model, t_iter = widget.get_selection().get_selected() name = model.get_value(t_iter, 2) gobject.idle_add(_fork) main_win.window.set_cursor(Cursor(WATCH)) self._statusbar("Please Wait...") def add_from_local_file(self, widget, data=None): main_win = self.gld.get_widget("main_win") dlg = local_install_fchooser_dialog(main_win, self.icon) if dlg.run() == RESPONSE_ACCEPT: main_win.set_sensitive(False) fname = dlg.get_filename() dlg.destroy() else: dlg.destroy() return self._statusbar(_("Installing %s" %fname)) deps, conflicts = self.database.get_local_file_deps(fname) install = [] remove = [] for dep in deps: if dep.count(">="): dep = dep.split(">=")[0] dep_pkg = self.database.get_by_name(dep) if dep_pkg and not dep_pkg.installed: install.append(dep_pkg) continue for conflict in conflicts: try: conflict_pkg = self.database.get_by_name(conflict) if conflict_pkg: remove.append(conflict_pkg) except NameError: pass continue pacs_queues = { "add": install, "remove": remove } local_install_dlg = local_install_dialog( main_win, self.icon, pacs_queues, fname ) local_install_dlg.connect("destroy", self._refresh_trees_and_queues) retcode = local_install_dlg.run() if retcode == RESPONSE_YES: self._statusbar(_("Installing...")) local_install_dlg.set_sensitive(False) if self._passwd_dlg_init(local_install_dlg): local_install_dlg.install() local_install_dlg.set_sensitive(True) else: local_install_dlg.destroy() self._statusbar(_("Installation canceled")) else: local_install_dlg.destroy() def add_to_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if name in self.queues["add"]: return image = model.get_value(l_iter, 0) if name in self.queues["remove"]: self.queues["remove"].remove(name) self.queues["add"].append(name) if image == "red": model.set_value(l_iter, 1, STOCK_ADD) else: model.set_value(l_iter, 1, STOCK_GO_UP) return def remove_from_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if not (name in self.queues["add"]): return self.queues["add"].remove(name) model.set_value(l_iter, 1, None) return def add_to_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if name in self.queues["remove"]: return image = model.get_value(l_iter, 0) if image == "red": return if name in self.queues["add"]: self.queues["add"].remove(name) self.queues["remove"].append(name) model.set_value(l_iter, 1, STOCK_REMOVE) return def remove_from_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if not (name in self.queues["remove"]): return self.queues["remove"].remove(name) model.set_value(l_iter, 1, None) return def refresh_database(self, widget, data=None): main_window = self.gld.get_widget("main_win") main_window.set_sensitive(False) self._statusbar(_("Refreshing database...")) command_dlg = command_dialog(main_window, self.icon) command_dlg.connect("destroy", self._refresh_trees_and_queues) if self._passwd_dlg_init(command_dlg): command_dlg.install('Sy') else: command_dlg.destroy() def upgrade_system(self, widget, data=None): to_upgrade = [] for repo in self.database.values(): for pac in repo: if pac.isold: to_upgrade.append(pac) continue continue # Jump in if there are packages to upgrade if to_upgrade: self.gld.get_widget("main_win").set_sensitive(False) b_list = self._blacklist( to_upgrade, 0x01) if b_list: dlg = ignorepkg_dialog( b_list, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_NO: self._done(None) return upgrade_dlg = upgrade_dialog( self.gld.get_widget("main_win"), self.icon, to_upgrade) upgrade_dlg.connect("destroy", self._refresh_trees_and_queues) resp = upgrade_dlg.run() if resp == RESPONSE_YES: self._statusbar(_("Refreshing database...")) upgrade_dlg.set_sensitive(False) if self._passwd_dlg_init(upgrade_dlg): upgrade_dlg.install() upgrade_dlg.set_sensitive(True) else: upgrade_dlg.destroy() self._statusbar(_("Upgrade canceled")) self.gld.get_widget("main_win").set_sensitive(True) elif resp == RESPONSE_NO: upgrade_dlg.destroy() self._statusbar(_("Upgrade canceled")) self.gld.get_widget("main_win").set_sensitive(True) else: print 'else' # Else nothing to upgrade else: self._statusbar(_("There are no packages to upgrade")) self.gld.get_widget("main_win").set_sensitive(True) return def clear_cache(self, wid, data=None): main_window = self.gld.get_widget("main_win") main_window.set_sensitive(False) self._statusbar(msg=_("Clearing cache...")) command_dlg = command_dialog(main_window, self.icon) command_dlg.connect("destroy", self._done) if self._passwd_dlg_init(command_dlg): command_dlg.install('Sc') else: command_dlg.destroy() def empty_cache(self, wid, data=None): main_window = self.gld.get_widget("main_win") main_window.set_sensitive(False) self._statusbar(_("Emptying cache...")) command_dlg = command_dialog(main_window, self.icon) command_dlg.connect("destroy", self._done) if self._passwd_dlg_init(command_dlg): command_dlg.install('Scc') else: command_dlg.destroy() def make_package(self, widget): from os.path import dirname, abspath dlg = choose_pkgbuild_dialog(self.gld.get_widget("main_win"), self.icon) fname = dlg.run() dlg.destroy() try: dname = dirname(fname) except: self.gld.get_widget("main_win").set_sensitive(True) return self.gld.get_widget("main_win").set_sensitive(False) pwd = abspath(curdir) chdir(dname) command_dlg = command_dialog(self.gld.get_widget("main_win"), self.icon) command_dlg.connect("destroy", self._done) if geteuid() == 0: dlg = change_user_dialog(self.gld.get_widget("main_win"), self.icon) user = dlg.run() dlg.destroy() if user == "root": command_dlg.install("makepkg --asroot -si \n", False) elif user == "reject": pass else: command_dlg.install("su %s -c 'makepkg -si' \n" %user, False) #command_dlg.destroy() else: if self._passwd_dlg_init(command_dlg): usr_name = getpwuid(geteuid())[0] command_dlg.install("su %s -c 'makepkg -si' \n" %usr_name, False) else: command_dlg.destroy() #command_dlg.install("makepkg -s \n", False) #command_dlg.destroy() chdir(pwd) def search(self, widget, data=None): main_win = self.gld.get_widget("main_win") dlg = search_dialog(main_win, self.icon) def _fork(): repos_tree = self.gld.get_widget("repos_tree") repos_model = repos_tree.get_model() pacs = self.database.get_by_keywords(keywords.lower()) if self.search_iter: repos_model.remove(self.search_iter) self.search_iter = repos_model.append(None, [_("Search for '%s'") %keywords]) self.models["search"] = search_list(pacs) path = repos_model.get_path(self.search_iter) repos_tree.set_cursor_on_cell(path) dlg.destroy() main_win.window.set_cursor(None) if dlg.run() == RESPONSE_ACCEPT: keywords = dlg.entry.get_text() if keywords: dlg.vbox.set_sensitive(False) self._statusbar(_("Searching for %s..." %keywords)) main_win.window.set_cursor(Cursor(WATCH)) dlg.window.set_cursor(Cursor(WATCH)) gobject.idle_add(_fork) else: dlg.destroy() error_dlg = error_dialog(None, _("You should insert at least one keyword to search for"), self.icon) error_dlg.run() error_dlg.destroy() else: dlg.destroy() def about(self, widget, data=None): dlg = about_dialog(self.gld.get_widget("main_win"), self.icon) dlg.run() dlg.destroy() return def quit(self, widget, data=None): self._setup_size(True) main_quit() return True def sum_txt_on_motion(self, widget, event, data=None): """ Change cursor when hovering over hyperlink """ x, y = widget.window_to_buffer_coords(TEXT_WINDOW_WIDGET, int(event.x), int(event.y)) buffer = widget.get_buffer() iter = widget.get_iter_at_location(x, y) tags = iter.get_tags() for tag in tags: url = tag.get_data("url") if url: widget.get_window(TEXT_WINDOW_TEXT).set_cursor(Cursor(HAND2)) else: widget.get_window(TEXT_WINDOW_TEXT).set_cursor(Cursor(XTERM)) return False def execute(self, widget=None, data=None): pacs_queues = { "add": [], "remove": [] } deps = [] req_pacs = [] if self.queues['add']: pacs_queues['add'] = self._execute_queue_add() # Check if packages are listed as ignorePkg b_list = self._blacklist( pacs_queues['add'], 0x01) if b_list: dlg = ignorepkg_dialog( b_list, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_NO: self._done(None) return if self.queues['remove']: pacs_queues['remove'], req_pacs = self._execute_queue_remove() #pacs_queues["remove"] = self._execute_queue_remove() # Check if packages are listed as holdPkg b_list = self._blacklist( pacs_queues['remove'], 0x02) if b_list: dlg = holdpkg_dialog( b_list, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_NO: self._done(None) return if not (pacs_queues["add"] or pacs_queues["remove"]): self._refresh_trees_and_queues() return self.gld.get_widget("main_win").set_sensitive(False) if req_pacs: dlg = warning_dialog(self.gld.get_widget("main_win"), req_pacs, self.icon) if dlg.run() == RESPONSE_YES: pacs_queues["remove"].extend(req_pacs) dlg.destroy() else: dlg.destroy() # Open new dialog and execute commands ie. install/remove packages do_dlg = do_dialog( self.gld.get_widget("main_win"), self.icon, pacs_queues) do_dlg.connect("destroy", self._refresh_trees_and_queues) resp = do_dlg.run() if resp == RESPONSE_YES: self._statusbar(_("Executing queued operations...")) do_dlg.set_sensitive(False) if self._passwd_dlg_init(do_dlg): do_dlg.install() do_dlg.set_sensitive(True) # User clicked cancel else: do_dlg.destroy() self.queues["add"] = [] self.queues["remove"] = [] self._statusbar(_("Upgrade canceled")) self.gld.get_widget("main_win").set_sensitive(True) elif resp == RESPONSE_NO: do_dlg.destroy() self.queues["add"] = [] self.queues["remove"] = [] self._statusbar(_("Upgrade canceled")) self.gld.get_widget("main_win").set_sensitive(True) #------------------------- Callbacks End -----------------------------# def _execute_queue_add(self): """ We convert names to pac (dict). Then we check if there are packages that need to be installed for our selected packages (dependecies). """ # queue is list of pacs objects and will be returned, # while queue_pac_name is only used for pac.name # to know what has been added in queue def add_to_install_queue(): done_pac.flag = 11 queue.append(done_pac) queue_pacs_names.append(done_pac.name) deps_todo_list.extend(queue_todo) if done_pac.conflict: conflicts[done_pac.name] = done_pac.conflict queue = [] queue_pacs_names = [] conflicts = {} # 1. we fetching pacs object for name in self.queues["add"]: pac = self.database.get_by_name(name) pac.flag = 0x12 self.database.set_pac_properties(pac) pac.flag = None queue.append(pac) queue_pacs_names.append(pac.name) # 2. iterate over pacs object for pac in queue: if pac.dependencies: deps_todo_list = [] deps_black_list = [] deps_todo_list.extend( pac.dependencies.split(",") ) while deps_todo_list: dep = deps_todo_list.pop(0) if not dep: continue # Split string if separator found if dep.count('>='): dep_name, dep_sep, dep_ver = dep.partition('>=') elif dep.count('<='): dep_name, dep_sep, dep_ver = dep.partition('<=') elif dep.count('<'): dep_name, dep_sep, dep_ver = dep.partition('<') elif dep.count('>'): dep_name, dep_sep, dep_ver = dep.partition('>') elif dep.count('='): dep_name, dep_sep, dep_ver = dep.partition('=') else: dep_name, dep_sep = dep, None dep_name = dep_name.strip() if ( dep_name not in self.queues["add"] and dep_name not in queue_pacs_names and dep_name not in deps_black_list ): done_pac, queue_todo = self._execute_dep_check(dep_name, "dep") if done_pac: # if separator found then compare versions if dep_sep: # compare versions if dep_sep == '>=' and dep_ver > done_pac.inst_ver or len(dep_ver) > len(done_pac.inst_ver): add_to_install_queue() elif dep_sep == '=': if not done_pac.inst_ver == dep_ver or not dep.installed: add_to_install_queue() elif (dep_sep == '>' and dep_ver > done_pac.inst_ver or len(dep_ver) > len(done_pac.inst_ver) ): add_to_install_queue() elif dep_sep == '<' and dep_ver < done_pac.inst_ver: print '!!!!!!!!<!!!!!!' else: if not done_pac.installed: add_to_install_queue() else: continue if not done_pac.installed and queue_todo: deps_todo_list.extend(queue_todo) deps_black_list.append(done_pac.name) # Resolve conflicts if conflicts: pacs = [] for pac in map( self.database.get_by_name, conflicts.itervalues() ): if pac and pac.installed and pac.name not in self.queues["remove"]: pacs.append(pac) if pacs: self.gld.get_widget("main_win").set_sensitive(False) dlg = warning_dialog(self.gld.get_widget("main_win"), pacs, self.icon, True) # Add pacs to remove queue if clicket on Yes button if dlg.run() == RESPONSE_YES: for pac in pacs: self.queues["remove"].append(pac.name) dlg.destroy() # Otherwise Cancel whole process else: self.queues['add'] = [] self.queues['remove'] = [] dlg.destroy() return return queue def _execute_queue_remove(self): """ Prepare pacs for removal """ queue = [] req_pacs = [] queue_pacs_names = [] for name in self.queues["remove"]: pac = self.database.get_by_name(name) self.database.set_pac_properties(pac) queue.append(pac) queue_pacs_names.append(pac.name) if pac.req_by: req_todo_list = [] req_todo_list.extend( pac.req_by.split(",") ) while req_todo_list: req_name = req_todo_list.pop(0).strip() if req_name.count('>='): req_name = req_name.partition('>=')[0] elif req_name.count('<='): req_name = req_name.partition('<=')[0] elif req_name.count('<'): req_name = req_name.partition('<')[0] elif req_name.count('>'): req_name = req_name.partition('>')[0] elif req_name.count('='): req_name = req_name.partition('=')[0] if ( req_name not in self.queues["remove"] and req_name not in queue_pacs_names ): done_pac, queue_todo = self._execute_dep_check(req_name, "req") if ( done_pac and done_pac.name not in queue_pacs_names ): req_pacs.append(done_pac) queue_pacs_names.append(done_pac.name) if queue_todo: req_todo_list.extend(queue_todo) return queue, req_pacs def _execute_dep_check(self, to_check, flag): to_do = [] pac = self.database.get_by_name(to_check) if not pac: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(pkg)s is not in the database.\n%(pkg)s is required by one of your package(s).")%{"pkg": to_check}, self.icon) #This maybe either an error in %(pkg)s packaging or a gtkpacman's bug.")%{"pkg": to_check}, self.icon)#\n \ #If you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{"pkg": to_check}, self.icon) dlg.run() dlg.destroy() return '','' if flag == "req": self.database.set_pac_properties(pac) for req in pac.req_by.split(","): if len(req) >= 1: to_do.append(req) else: pac.flag = 0x12 self.database.set_pac_properties(pac) pac.flag = None for dep in pac.dependencies.split(","): to_do.append(dep) return pac, to_do def _passwd_dlg_init(self, dlg): """ We check if gtkpacman was started by root. If not then we run password_dialog """ warning_ison = False # Jump in if program was not started by root if self.uid: dlg.run_su() passwd_dlg = password_dialog(self.gld.get_widget("main_win"), self.icon) # When password is less then 1 we show 'error' message. # Until passwd is less than one and unverified we keep password_dialog runing. while passwd_dlg.run() == RESPONSE_ACCEPT: user_passwd = passwd_dlg.password_entry.get_text() if not len(user_passwd) > 0: # We don't want to show same message everytime user click on OK button if not warning_ison: passwd_dlg.show_warning() warning_ison = True # Return with valid password else: dlg.run_login(user_passwd) del user_passwd passwd_dlg.destroy() return True # Destroy dialog and return False when user click on Cancel passwd_dlg.destroy() return False # We return if program was started by root else: return True def _blacklist(self, pacs, key=None): """ Here we check if packages are not in hold or ignore list. If they are then we return them. """ blacklist = [] if pacs and key == 0x01: for bp in self.database.ignorePkg: for p in pacs: if p.name == bp: blacklist.append(p.name) elif pacs and key == 0x02: for bp in self.database.holdPkg: for p in pacs: if p.name == bp: blacklist.append(p.name) else: return None return blacklist def _done(self, widget, data=None): self.gld.get_widget("main_win").set_sensitive(True) self._statusbar() def _pacman_ver_check(self): """Check pacman version. """ pacman_ver = self.gld.get_widget('pacman_ver_status') ver_inst = self.gld.get_widget('ver_inst_label') ver_avail = self.gld.get_widget('ver_avail_label') for pac in self.database['core']: # Print pacmans installed and avaible version if pac.name == 'pacman': if pac.isold == False: pacman_ver.hide() return elif (pac.name == 'pacman' and ( pac.isold == True and pac.installed == True )): pacman_ver.show() ver_inst.set_text(pac.inst_ver) ver_avail.set_text(pac.version) return # If pacman is found but 'installed == False' then we print warning else: pacman_ver.show() ver_inst.set_text('WARNING') ver_avail.set_text('WARNING') print "?? WARNING: Found pacman but it's not installed" return # If can't find pacman in core repo then print warning pacman_ver.show() ver_inst.set_text('WARNING') ver_avail.set_text('WARNING') print "!! WARNING: Can't find pacman in 'core' repo" def _statusbar(self, msg=None): stat_bar = self.gld.get_widget("statusbar") if type(msg) == tuple and len(msg) == 3: str = _("%s packages in [ %s ] - server last synchronized [ %s ]") %(msg[0], msg[1], msg[2]) elif type(msg) == tuple and len(msg) == 2: str = _("%s packages in [ %s ]") %(msg[0], msg[1]) elif msg == None: str = _("Done") else: str = "%s " %msg stat_bar.push(-1, str) def _set_pac_summary(self, pac): sum_txt = self.gld.get_widget("summary") file_tree = self.gld.get_widget("files") def list_tag(tag, widget, event, iter): if event.type == BUTTON_RELEASE: buff = widget.get_buffer() url = tag.get_data("url") if url: webbrowser.open_new_tab(url) text_buffer = TextBuffer() tag_table = text_buffer.get_tag_table() heading_tag = TextTag("heading") heading_tag.set_property("weight", pango.WEIGHT_BOLD) heading_tag.set_property("foreground", "grey") link_tag = TextTag('link') link_tag.set_property("foreground", 'brown') link_tag.set_property('underline', pango.UNDERLINE_SINGLE) link_tag.set_data("url", pac.url) link_tag.connect("event", list_tag) center_tag = TextTag("center") #center_tag.set_property("indent", 800) center_tag.set_property("foreground", "blue") #center_tag.set_property("left-margin", 90) tag_table.add(heading_tag) tag_table.add(center_tag) tag_table.add(link_tag) iter = text_buffer.get_start_iter() if pac.installed: text_buffer.insert_with_tags_by_name(iter, "Description\n", 'heading') text_buffer.insert(iter, pac.description[0] + "\n") text_buffer.insert_with_tags_by_name(iter, "Size\n", 'heading') text_buffer.insert(iter, pac.size + "\n") text_buffer.insert_with_tags_by_name(iter, "URL\n", 'heading') text_buffer.insert_with_tags_by_name(iter, pac.url, 'link') text_buffer.insert(iter, "\n") text_buffer.insert_with_tags_by_name(iter, "Install Date\n", 'heading') text_buffer.insert(iter, pac.dates[0] + "\n") text_buffer.insert_with_tags_by_name(iter, "Install Reason\n", 'heading') text_buffer.insert(iter, pac.explicitly[0] + "\n") text_buffer.insert_with_tags_by_name(iter, "Required By\n", 'heading') text_buffer.insert(iter, pac.req_by + "\n") text_buffer.insert_with_tags_by_name(iter, "Depends On\n", 'heading') text_buffer.insert(iter, pac.dependencies + "\n") text_buffer.insert_with_tags_by_name(iter, "Packager\n", 'heading') text_buffer.insert(iter, pac.description[1] + "\n") text_buffer.insert_with_tags_by_name(iter, "Build Date\n", 'heading') text_buffer.insert(iter, pac.dates[1]) sum_txt.set_buffer(text_buffer) else: text_buffer.insert_with_tags_by_name(iter, "Description\n", "heading") text_buffer.insert(iter, pac.description[0] + "\n") text_buffer.insert_with_tags_by_name(iter, "Size (compressed)\n", "heading") text_buffer.insert(iter, pac.size + "\n") text_buffer.insert_with_tags_by_name(iter, "URL\n", 'heading') text_buffer.insert_with_tags_by_name(iter, pac.url, 'link') text_buffer.insert(iter, "\n") text_buffer.insert_with_tags_by_name(iter, "Depends On\n", "heading") text_buffer.insert(iter, pac.dependencies, ) sum_txt.set_buffer(text_buffer)
class gui: def __init__(self, fname, database, uid, icon): # Setup the main gui: read glade file, connect signals self.gld = XML(fname, "main_win", "gtkpacman") self.gld.get_widget("main_win").set_icon(pixbuf_new_from_file(icon)) h_dict = {"quit": self.quit, "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "execute": self.execute, "up_sys": self.upgrade_system, "refr_db": self.refresh_database, "add_local": self.add_from_local_file, "clear_cache": self.clear_cache, "empty_cache": self.empty_cache, "search_pac": self.search, "show_popup": self.show_popup, "about": self.about, "pacs_changed": self.pacs_changed, "repo_changed": self.repo_changed} self.gld.signal_autoconnect(h_dict) self.fname = fname self.icon = icon self.database = database self.queues = {"add": [], "remove": []} self.search_iter = None #Setup secondary gui elements self._setup_popup_menu(fname) self._setup_repos_tree() self._setup_pacs_models() self._setup_pacs_tree() self._setup_files_tree() #Setup statusbar stat_bar = self.gld.get_widget("statusbar") self.stat_id = stat_bar.get_context_id("stat") stat_bar.push(self.stat_id, _("Done.")) #Check if root, else notufy it and deactivate some widgets if uid: self._setup_avaible_actions() dlg = non_root_dialog(icon) dlg.run() dlg.destroy() def _setup_avaible_actions(self): #Deactivate some widgets. Called if not root self.gld.get_widget("queue").set_sensitive(False) self.gld.get_widget("immediate").set_sensitive(False) self.gld.get_widget("add_install").set_sensitive(False) self.gld.get_widget("remove_install").set_sensitive(False) self.gld.get_widget("add_remove").set_sensitive(False) self.gld.get_widget("remove_remove").set_sensitive(False) self.gld.get_widget("execute").set_sensitive(False) self.gld.get_widget("up_sys").set_sensitive(False) self.gld.get_widget("up_db").set_sensitive(False) self.popup_gld.get_widget("popup_add_install").set_sensitive(False) self.popup_gld.get_widget("popup_remove_install").set_sensitive(False) self.popup_gld.get_widget("popup_add_remove").set_sensitive(False) self.popup_gld.get_widget("popup_remove_remove").set_sensitive(False) def _adjust_queues (self): for name in self.queues["add"]: if name == "x-server": ind = self.queues["add"].index("x-server") self.queues["add"][ind] = "x-org" elif ">=" in name: ind = self.queues["add"].index(name) name = name.split(">=")[0] self.queues["add"][ind] = name continue def _adjust_names(self, names): for ind in range(len(names)): if names[ind] == "x-server": names[ind] = "xorg-server" elif ">=" in names[ind]: name = names[ind].split(">=")[0] names[ind] = name continue return names def _setup_pacs_tree(self): pacs_tree = self.gld.get_widget("pacs_tree") pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=0) pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=1) pacs_tree.insert_column_with_attributes(-1, _("Package"), CellRendererText(), text=2) pacs_tree.insert_column_with_attributes(-1, _("Installed Version"), CellRendererText(), text=3) self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Avaible Version"), CellRendererText(), text=4 ) self.repo_col = pacs_tree.insert_column_with_attributes( -1, _("Repo"), CellRendererText(), text=5 ) pacs_tree.set_model(self.models[_("All")]) sort_id = 0 for col in pacs_tree.get_columns(): col.set_reorderable(True) col.set_sort_column_id(sort_id) col.set_clickable(True) col.set_resizable(True) sort_id += 1 continue return def _setup_popup_menu(self, fname): self.popup_gld = XML(fname, "popup_menu", "gtkpacman") popup_h_dict = { "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "search": self.search } self.popup_gld.signal_autoconnect(popup_h_dict) self.popup = self.popup_gld.get_widget("popup_menu") def _setup_repos_tree(self): repos_tree = self.gld.get_widget("repos_tree") repos_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) repos_tree.set_model(self._make_repos_model()) return def _make_repos_model (self): repos_model = TreeStore(str) all_it = repos_model.append(None, [_("All")]) for repo in self.database.repos: if repo == "foreigners": continue repo_it = repos_model.append(all_it, [repo]) repos_model.append(repo_it, [_("all")]) repos_model.append(repo_it, [_("installed")]) continue repos_model.append(all_it, [_("foreigners")]) return repos_model def _refresh_repos_tree (self): self.gld.get_widget("repos_tree").set_model(self._make_repos_model()) return def _setup_files_tree(self): file_tree = self.gld.get_widget("files") file_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) return def _setup_pacs_models(self): self.models = {} self.models[_("All")] = whole_list(self.database.values()) try: self.models[_("foreigners")] = installed_list(self.database["foreigners"]) except KeyError: self.database["foreigners"] = [] self.models[_("foreigners")] = installed_list(self.database["foreigners"]) for repo in self.database.repos: if repo == _("foreigners"): continue self.models[repo] = {} all_mod = all_list(self.database[repo]) inst_mod = installed_list(self.database[repo]) self.models[repo][_("all")] = all_mod self.models[repo][_("installed")] = inst_mod continue return def _refresh_trees(self): for model in self.models.keys(): if model == _("All") or model == _("foreigners"): self._refresh_model(model) else: try: for mod in self.models[model].keys(): self._refresh_model(model, mod) continue except AttributeError: pass continue return def _refresh_model(self, model, submodel=None): if submodel: liststore = self.models[model][submodel] else: liststore = self.models[model] for row in liststore: row[1] = None if row[2] in self.queues["add"]: row[0] = "green" row[3] = row[4] elif row[2] in self.queues["remove"]: row[0] = "red" row[3] = "-" continue return def quit(self, widget, data=None): main_quit() return def repo_changed(self, widget, data=None): repos_tree = self.gld.get_widget("repos_tree") pacs_tree = self.gld.get_widget("pacs_tree") repos_model, tree_iter = repos_tree.get_selection().get_selected() selected = repos_model.get_value(tree_iter, 0) if not repos_model.iter_depth(tree_iter): if selected.count(_("Search")): pacs_model = self.models["search"] else: pacs_model = self.models[_("All")] if not self.repo_col: self.repo_col = pacs_tree.insert_column_with_attributes( -1, "", CellRendererText(), text=5 ) if not self.inst_ver_col: self.inst_ver_col = pacs_tree.insert_column_with_atrributes( -1, "", CellRendererText(), text=4 ) elif selected == _("foreigners"): if self.repo_col: pacs_tree.remove_column(self.repo_col) self.repo_col = None if self.inst_ver_col: pacs_tree.remove_column(self.inst_ver_col) self.inst_ver_col = None pacs_model = self.models[selected] else: if selected == _("all") or selected == _("installed"): parent_iter = repos_model.iter_parent(tree_iter) parent = repos_model.get_value(parent_iter, 0) pacs_model = self.models[parent][selected] else: pacs_model = self.models[selected][_("all")] if self.repo_col: pacs_tree.remove_column(self.repo_col) self.repo_col = None if not self.inst_ver_col: self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Avaible Version"), CellRendererText(), text=4) pacs_tree.set_model(pacs_model) return def pacs_changed(self, widget, data=None): sum_txt = self.gld.get_widget("summary") sum_buf = sum_txt.get_buffer() file_tree = self.gld.get_widget("files") model, t_iter = widget.get_selection().get_selected() name = model.get_value(t_iter, 2) pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) sum_buf.set_text(pac.summary) file_model = file_list(pac.filelist) file_tree.set_model(file_model) return def add_to_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() name = model.get_value(l_iter, 2) if name in self.queues["add"]: return if name in self.database.holdPkg: dlg = holdpkg_dialog(name, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_OK: pacs_queues = { "add": [self.database.get_by_name(name)], "remove": [] } retcode = self._confirm(pacs_queues) if retcode: stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Executing queued operations")) dlg = do_dialog(pacs_queues, self.icon) dlg.run() return if name in self.database.ignorePkg: dlg = ignorepkg_dialog(name, self.icon) res = dlg.run() dlg.destroy() if res is RESPONSE_NO: return if name in self.queues["remove"]: self.queues["remove"].remove(name) self.queues["add"].append(name) image = model.get_value(l_iter, 0) if image == "red": model.set_value(l_iter, 1, STOCK_ADD) else: model.set_value(l_iter, 1, STOCK_GO_UP) return def remove_from_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() name = model.get_value(l_iter, 2) if not (name in self.queues["add"]): return self.queues["add"].remove(name) model.set_value(l_iter, 1, None) return def add_to_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() name = model.get_value(l_iter, 2) if name in self.queues["remove"]: return image = model.get_value(l_iter, 0) if image == "red": return if name in self.queues["add"]: self.queues["add"].remove(name) self.queues["remove"].append(name) model.set_value(l_iter, 1, STOCK_REMOVE) return def remove_from_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() name = model.get_value(l_iter, 2) if not (name in self.queues["remove"]): return self.queues["remove"].remove(name) model.set_value(l_iter, 1, None) return def execute(self, widget=None, data=None): pacs_queues = { "add": [], "remove": [] } for name in self.queues["add"]: try: pac = self.database.get_by_name(name) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%s is not in the database.\nThis is probably a bug in gtkpacman. If you think it's so, please send me a bug report.") %name, self.icon) dlg.run() dlg.destroy() continue if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["add"].append(pac) deps = pac.dependencies.split(", ") for dep in deps: if dep.count(">="): dep = dep.split(">=")[0] try: dep_pac = self.database.get_by_name(dep) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(dep)s is not in the database. %(dep)s is required by %(pkg)s.\nThis maybe either an error in %(pkg)s packaging or a gtkpacman's bug.\nIf you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{'dep': dep, "pkg": name}, self.icon) dlg.run() dlg.destroy() pacs_queues["add"].remove(pac) self.queues["add"].remove(name) break if not dep_pac.installed: pacs_queues["add"].append(dep_pac) continue for name in self.queues["remove"]: pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["remove"].append(pac) if pac.req_by: req_pacs = [] for req in pac.req_by.split(", "): if not (req in self.queues["remove"]): req_pac = self.database.get_by_name(req) req_pacs.append(req_pac) if req_pacs: dlg = warning_dialog(self.gld.get_widget("main_win"), req_pacs, self.icon) if dlg.run() == RESPONSE_YES: pacs_queues["remove"].extend(req_pacs) else: self.queues["remove"].remove(name) pacs_queues["remove"].remove(pac) dlg.destroy() continue if not (pacs_queues["add"] or pacs_queues["remove"]): self._refresh_trees_and_queues() return retcode = self._confirm(pacs_queues) if retcode: stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Executing queued operations")) dlg = do_dialog(pacs_queues, self.icon) dlg.connect("destroy", self._refresh_trees_and_queues, pacs_queues) dlg.run() else: self.queues["add"] = [] self.queues["remove"] = [] self._refresh_trees_and_queues() return def _confirm(self, pacs_queues): dlg = confirm_dialog(self.gld.get_widget("main_win"), pacs_queues, self.icon) retcode = dlg.run() return retcode def _refresh_trees_and_queues(self, widget=None, pacs_queues=None): self.database.refresh() self._refresh_repos_tree() self._refresh_trees() self.queues["add"] = [] self.queues["remove"] = [] for pac in pacs_queues["add"]: pac.installed = True self.database.set_pac_properties(pac) continue for pac in pacs_queues["remove"]: pac.installed = False self.database.set_pac_properties(pac) continue del(pacs_queues) stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Done.")) return def about(self, widget, data=None): dlg = about_dialog(self.icon) dlg.run() dlg.destroy() return def show_popup(self, widget, event, data=None): if event.button == 3: self.popup.popup(None, None, None, event.button, event.time) else: self.popup.popdown() def search(self, widget, data=None): dlg = search_dialog(self.gld.get_widget("main_win"), self.icon) if dlg.run() == RESPONSE_ACCEPT: keywords = dlg.entry.get_text() dlg.destroy() pacs = self.database.get_by_keywords(keywords) repos_model = self.gld.get_widget("repos_tree").get_model() if self.search_iter: repos_model.remove(self.search_iter) self.search_iter = repos_model.append(None, [_("Search results for '%s'") %keywords]) self.models["search"] = search_list(pacs) def add_from_local_file(self, widget, data=None): dlg = local_install_fchooser_dialog(self.gld.get_widget("main_win"), self.icon) if dlg.run() == RESPONSE_ACCEPT: fname = dlg.get_filename() dlg.destroy() else: dlg.destroy() return stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Installing %s") %fname) deps, conflicts = self.database.get_local_file_deps(fname) install = [] remove = [] for dep in deps: dep_pkg = self.database.get_by_name(dep) if not dep_pkg.installed: install.append(dep_pkg) continue for conflict in conflicts: try: conflict_pkg = self.database.get_by_name(conflict) remove.append(conflict_pkg) except NameError: pass continue pacs_queues = { "add": install, "remove": remove } retcode = self._local_confirm(fname, pacs_queues) if retcode: i_dlg = local_install_dialog(fname, pacs_queues, self.icon) i_dlg.connect("destroy", self._after_local_install) i_dlg.run() def _after_local_install(self, wid, data=None): self.database.refresh() self.models["foreigners"] = installed_list(self.database["foreigners"]) stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Done.")) def _local_confirm(self, fname, pacs_queue): dlg = local_confirm_dialog(self.gld.get_widget("main_win"), fname, pacs_queue, self.icon) if dlg.run(): retcode = True else: retcode = False return retcode def clear_cache(self, wid, data=None): stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Clearing cache...")) dlg = command_dialog(self.icon) dlg.connect("destroy", self._done) dlg.run("Sc") return def empty_cache(self, wid, data=None): stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Emptying cache...")) dlg = command_dialog() dlg.connect("destroy", self._done) dlg.run("Scc") return def _done(self, widget, data=None): stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Done.")) def upgrade_system(self, widget, data=None): to_upgrade = [] for repo in self.database.values(): for pac in repo: if pac.isold: to_upgrade.append(pac) continue continue if to_upgrade: confirm = self._upgrade_confirm(to_upgrade) if confirm: stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Refreshing database")) dlg = upgrade_dialog(to_upgrade, self.icon) dlg.connect("destroy", self._done_upgrade) dlg.run() else: stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("There isn't any packages to upgrade")) return def _upgrade_confirm(self, to_upgrade): dlg = upgrade_confirm_dialog(self.gld.get_widget("main_win"), to_upgrade, self.icon) retcode = dlg.run() return retcode def refresh_database(self, widget, data=None): stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Refreshing database")) dlg = command_dialog(self.icon) dlg.connect("destroy", self._done_upgrade) dlg.run("Sy") return def _done_upgrade(self, widget, data=None): self.database.refresh() self._refresh_repos_tree() self._setup_pacs_models() stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Done."))
class gui: def __init__(self, fname, database, uid, icon): # Setup the main gui: read glade file, connect signals self.gld = XML(fname, "main_win", "gtkpacman") self.gld.get_widget("main_win").set_icon(pixbuf_new_from_file(icon)) h_dict = {"quit": self.quit, "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "execute": self.execute, "up_sys": self.upgrade_system, "refr_db": self.refresh_database, "add_local": self.add_from_local_file, "clear_cache": self.clear_cache, "empty_cache": self.empty_cache, "search_pac": self.search, "show_popup": self.show_popup, "about": self.about, "pacs_changed": self.pacs_changed, "repo_changed": self.repo_changed, "make_pkg": self.make_package} self.gld.signal_autoconnect(h_dict) self.fname = fname self.icon = icon self.database = database self.queues = {"add": [], "remove": []} self.search_iter = None #Setup secondary gui elements self._setup_popup_menu(fname) self._setup_repos_tree() self._setup_pacs_models() self._setup_pacs_tree() self._setup_files_tree() #Setup statusbar self._statusbar() #Check if root, else notufy it and deactivate some widgets if uid: self._setup_avaible_actions() dlg = non_root_dialog(icon) dlg.run() dlg.destroy() def _setup_avaible_actions(self): #Deactivate some widgets. Called if not root self.gld.get_widget("queue").set_sensitive(False) self.gld.get_widget("immediate").set_sensitive(False) self.gld.get_widget("add_install").set_sensitive(False) self.gld.get_widget("remove_install").set_sensitive(False) self.gld.get_widget("add_remove").set_sensitive(False) self.gld.get_widget("remove_remove").set_sensitive(False) self.gld.get_widget("execute").set_sensitive(False) self.gld.get_widget("up_sys").set_sensitive(False) self.gld.get_widget("up_db").set_sensitive(False) self.popup_gld.get_widget("popup_add_install").set_sensitive(False) self.popup_gld.get_widget("popup_remove_install").set_sensitive(False) self.popup_gld.get_widget("popup_add_remove").set_sensitive(False) self.popup_gld.get_widget("popup_remove_remove").set_sensitive(False) def _adjust_queues (self): for name in self.queues["add"]: if name == "x-server": ind = self.queues["add"].index("x-server") self.queues["add"][ind] = "x-org" elif ">=" in name: ind = self.queues["add"].index(name) name = name.split(">=")[0] self.queues["add"][ind] = name continue def _adjust_names(self, names): for ind in range(len(names)): if names[ind] == "x-server": names[ind] = "xorg-server" elif ">=" in names[ind]: name = names[ind].split(">=")[0] names[ind] = name continue return names def _setup_pacs_tree(self): pacs_tree = self.gld.get_widget("pacs_tree") pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=0) pacs_tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(), stock_id=1) pacs_tree.insert_column_with_attributes(-1, _("Package"), CellRendererText(), text=2) pacs_tree.insert_column_with_attributes(-1, _("Installed Version"), CellRendererText(), text=3) self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Avaible Version"), CellRendererText(), text=4 ) self.repo_col = pacs_tree.insert_column_with_attributes( -1, _("Repo"), CellRendererText(), text=5 ) pacs_tree.set_model(self.models[_("All")]) sort_id = 0 for col in pacs_tree.get_columns(): col.set_reorderable(True) col.set_sort_column_id(sort_id) col.set_clickable(True) col.set_resizable(True) sort_id += 1 continue return def _setup_popup_menu(self, fname): self.popup_gld = XML(fname, "popup_menu", "gtkpacman") popup_h_dict = { "add_install": self.add_to_install_queue, "remove_install": self.remove_from_install_queue, "add_remove": self.add_to_remove_queue, "remove_remove": self.remove_from_remove_queue, "search": self.search } self.popup_gld.signal_autoconnect(popup_h_dict) self.popup = self.popup_gld.get_widget("popup_menu") def _setup_repos_tree(self): repos_tree = self.gld.get_widget("repos_tree") repos_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) repos_tree.set_model(self._make_repos_model()) return def _make_repos_model (self): repos_model = TreeStore(str) all_it = repos_model.append(None, [_("All")]) for repo in self.database.repos: if repo == "foreigners": continue repo_it = repos_model.append(all_it, [repo]) repos_model.append(repo_it, [_("all")]) repos_model.append(repo_it, [_("installed")]) continue repos_model.append(all_it, [_("foreigners")]) return repos_model def _pacs_tree_exp_check(self): expanded= [] def expander_check(model, path, iter): is_expanded = repos_tree.row_expanded(path) if is_expanded: expanded.append(path) repos_tree = self.gld.get_widget("repos_tree") model = repos_tree.get_model() iter = model.get_iter_root() path = model.get_path(iter) model.foreach(expander_check) return expanded def _refresh_repos_tree (self): expanded = self._pacs_tree_exp_check() repos_tree = self.gld.get_widget("repos_tree") repos_tree.set_model(self._make_repos_model()) for row in expanded: repos_tree.expand_row(row, False) return def _setup_files_tree(self): file_tree = self.gld.get_widget("files") file_tree.insert_column_with_attributes(-1, "", CellRendererText(), text=0) return def _setup_pacs_models(self): self.models = {} self.models[_("All")] = whole_list(self.database.values()) try: self.models[_("foreigners")] = installed_list(self.database["foreigners"]) except KeyError: self.database["foreigners"] = [] self.models[_("foreigners")] = installed_list(self.database["foreigners"]) for repo in self.database.keys(): if repo == _("foreigners"): continue self.models[repo] = {} all_mod = all_list(self.database[repo]) inst_mod = installed_list(self.database[repo]) self.models[repo][_("all")] = all_mod self.models[repo][_("installed")] = inst_mod continue return def _refresh_trees(self): for model in self.models.keys(): if model == _("All") or model == _("foreigners") or model == _("search"): self._refresh_model(model) else: try: for mod in self.models[model].keys(): self._refresh_model(model, mod) continue except AttributeError: pass continue return def _refresh_model(self, model, submodel=None): if submodel: liststore = self.models[model][submodel] else: liststore = self.models[model] for row in liststore: row[1] = None check = row[2][:] if check in self.queues["remove"] and model == _("foreigners"): nr = 0 for rm in liststore: nr += 1 if check == rm[2]: del liststore[nr -1] elif check in self.queues["remove"] and submodel == _("installed"): nr = 0 for rm in liststore: nr += 1 if check == rm[2]: del liststore[nr -1] elif row[2] in self.queues["add"] and submodel =="all": row[0] = "green" row[3] = row[4] self.models[model]["installed"].append(row) elif row[2] in self.queues["add"]: row[0] = "green" row[3] = row[4] elif row[2] in self.queues["remove"]: row[0] = "red" row[3] = "-" continue return def quit(self, widget, data=None): main_quit() return def repo_changed(self, widget, data=None): repos_tree = self.gld.get_widget("repos_tree") pacs_tree = self.gld.get_widget("pacs_tree") repos_model, tree_iter = repos_tree.get_selection().get_selected() selected = repos_model.get_value(tree_iter, 0) if not repos_model.iter_depth(tree_iter): if selected.count(_("Search")): pacs_model = self.models["search"] else: pacs_model = self.models[_("All")] if not self.repo_col: self.repo_col = pacs_tree.insert_column_with_attributes( -1, _("Repo"), CellRendererText(), text=5 ) if not self.inst_ver_col: self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Available Version"), CellRendererText(), text=4 ) elif selected == _("foreigners"): if self.repo_col: pacs_tree.remove_column(self.repo_col) self.repo_col = None if self.inst_ver_col: pacs_tree.remove_column(self.inst_ver_col) self.inst_ver_col = None pacs_model = self.models[selected] else: if selected == _("all") or selected == _("installed"): parent_iter = repos_model.iter_parent(tree_iter) parent = repos_model.get_value(parent_iter, 0) pacs_model = self.models[parent][selected] else: pacs_model = self.models[selected][_("all")] if self.repo_col: pacs_tree.remove_column(self.repo_col) self.repo_col = None if not self.inst_ver_col: self.inst_ver_col = pacs_tree.insert_column_with_attributes( -1, _("Avaible Version"), CellRendererText(), text=4) pacs_tree.set_model(pacs_model) stat = (len(pacs_model), selected) self._statusbar(stat) def pacs_changed(self, widget, data=None): sum_txt = self.gld.get_widget("summary") sum_buf = sum_txt.get_buffer() file_tree = self.gld.get_widget("files") model, t_iter = widget.get_selection().get_selected() name = model.get_value(t_iter, 2) pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) sum_buf.set_text(pac.summary) file_model = file_list(pac.filelist) file_tree.set_model(file_model) return def add_to_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if name in self.queues["add"]: return image = model.get_value(l_iter, 0) if name in self.database.ignorePkg and image == 'green': dlg = ignorepkg_dialog(name, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_NO: return if name in self.queues["remove"]: self.queues["remove"].remove(name) self.queues["add"].append(name) if image == "red": model.set_value(l_iter, 1, STOCK_ADD) else: model.set_value(l_iter, 1, STOCK_GO_UP) return def remove_from_install_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if not (name in self.queues["add"]): return self.queues["add"].remove(name) model.set_value(l_iter, 1, None) return def add_to_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if name in self.queues["remove"]: return image = model.get_value(l_iter, 0) if name in self.database.holdPkg: dlg = holdpkg_dialog(name, self.icon) res = dlg.run() dlg.destroy() if res == RESPONSE_NO: return if image == "red": return if name in self.queues["add"]: self.queues["add"].remove(name) self.queues["remove"].append(name) model.set_value(l_iter, 1, STOCK_REMOVE) return def remove_from_remove_queue(self, widget, data=None): tree = self.gld.get_widget("pacs_tree") model, l_iter = tree.get_selection().get_selected() try: name = model.get_value(l_iter, 2) except TypeError: return if not (name in self.queues["remove"]): return self.queues["remove"].remove(name) model.set_value(l_iter, 1, None) return def execute(self, widget=None, data=None): def _req_pac_check(to_check, flag): to_do = [] try: pac = self.database.get_by_name(to_check) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(dep)s is not in the database. %(dep)s is required by %(pkg)s.\nThis maybe either an error in %(pkg)s packaging or a gtkpacman's bug.\nIf you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{'dep': dep, "pkg": name}, self.icon) dlg.run() dlg.destroy() pacs_queues["add"].remove(pac) self.queues["add"].remove(name) return try: if not pac.prop_setted: self.database.set_pac_properties(pac) except: return pac, to_do if flag == "req": for req in pac.req_by.split(", "): if len(req) >= 1: to_do.append(req) else: if not pac.installed: for dep in pac.dependencies.split(", "): if len(dep) >= 1: to_do.append(dep) else: pac = None return pac, to_do pac = None return pac, to_do pacs_queues = { "add": [], "remove": [] } deps = [] for name in self.queues["add"]: try: pac = self.database.get_by_name(name) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%s is not in the database.\nThis is probably a bug in gtkpacman. If you think it's so, please send me a bug report.") %name, self.icon) dlg.run() dlg.destroy() continue if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["add"].append(pac) if pac.dependencies: dep_todo_list = [] dep_black_list = [] deps = pac.dependencies.split(", ") for dep in deps: if not dep in self.queues["add"]: dep_todo_list.append(dep) while dep_todo_list: dep = dep_todo_list.pop(0) if dep.count(">="): dep = dep.split(">=")[0] if not (dep in self.queues["add"]): done, to_do = _req_pac_check(dep, "dep") if done and not done in pacs_queues["add"]: pacs_queues["add"].append(done) for add in to_do: if not add in dep_black_list: dep_todo_list.append(add) dep_black_list.append(add) for name in self.queues["remove"]: pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["remove"].append(pac) if pac.req_by: req_pacs = [] req_todo_list = [] req_black_list = [] for req in pac.req_by.split(", "): if not (req in self.queues["remove"]): req_todo_list.append(req) while req_todo_list: req = req_todo_list.pop(0) if not (req in self.queues["remove"]): done, to_do = _req_pac_check(req, "req") if done and not done in req_pacs: req_pacs.append(done) for add in to_do: if not add in req_black_list: req_todo_list.append(add) req_black_list.append(add) continue if req_pacs: dlg = warning_dialog(self.gld.get_widget("main_win"), req_pacs, self.icon) if dlg.run() == RESPONSE_YES: pacs_queues["remove"].extend(req_pacs) else: self.queues["remove"].remove(name) pacs_queues["remove"].remove(pac) dlg.destroy() continue if not (pacs_queues["add"] or pacs_queues["remove"]): self._refresh_trees_and_queues() return retcode = self._confirm(pacs_queues) if retcode: self._statusbar(_("Executing queued operations...")) dlg = do_dialog(pacs_queues, self.icon) dlg.connect("destroy", self._refresh_trees_and_queues, pacs_queues) dlg.run() else: self.queues["add"] = [] self.queues["remove"] = [] self._refresh_trees_and_queues() return def _confirm(self, pacs_queues): dlg = confirm_dialog(self.gld.get_widget("main_win"), pacs_queues, self.icon) retcode = dlg.run() return retcode def _refresh_trees_and_queues(self, widget=None, pacs_queues=None): self.database.refresh() self._refresh_repos_tree() if pacs_queues: for pac in pacs_queues["add"]: if not pac.name in self.queues["add"]: self.queues["add"].append(pac.name) self._refresh_trees() self.queues["add"] = [] self.queues["remove"] = [] if pacs_queues: for pac in pacs_queues["add"]: pac.installed = True pac.inst_ver = pac.version self.database.set_pac_properties(pac) continue for pac in pacs_queues["remove"]: pac.installed = False if pac.repo == 'foreigners': del pac continue self.database.set_pac_properties(pac) continue sum_txt = self.gld.get_widget("summary") file_tree = self.gld.get_widget("files") sum_buf = sum_txt.get_buffer() tree = file_tree.get_model() try: sum_buf.set_text(pac.summary) file_model = file_list(pac.filelist) file_tree.set_model(file_model) except: col = file_tree.get_columns() tree.clear() sum_buf.set_text('') del(pacs_queues) self._statusbar() def about(self, widget, data=None): dlg = about_dialog(self.icon) dlg.run() dlg.destroy() return def show_popup(self, widget, event, data=None): if event.button == 3: self.popup.popup(None, None, None, event.button, event.time) else: self.popup.popdown() def search(self, widget, data=None): win = self.gld.get_widget("main_win") wait_cursor = Cursor(WATCH) dlg = search_dialog(self.gld.get_widget("main_win"), self.icon) def _fork(): repos_tree = self.gld.get_widget("repos_tree") repos_model = repos_tree.get_model() pacs = self.database.get_by_keywords(keywords) if self.search_iter: repos_model.remove(self.search_iter) self.search_iter = repos_model.append(None, [_("Search results for '%s'") %keywords]) self.models["search"] = search_list(pacs) repos_tree.set_cursor_on_cell((1)) dlg.destroy() win.window.set_cursor(None) if dlg.run() == RESPONSE_ACCEPT: keywords = dlg.entry.get_text() if keywords: dlg.vbox.set_sensitive(False) self._statusbar(_("Searching for %s..." %keywords)) win.window.set_cursor(wait_cursor) dlg.window.set_cursor(wait_cursor) gobject.idle_add(_fork) else: dlg.destroy() error_dlg = error_dialog(None, _("You should insert at least one keyword to search for"), self.icon) error_dlg.run() error_dlg.destroy() else: dlg.destroy() def add_from_local_file(self, widget, data=None): dlg = local_install_fchooser_dialog(self.gld.get_widget("main_win"), self.icon) if dlg.run() == RESPONSE_ACCEPT: fname = dlg.get_filename() dlg.destroy() else: dlg.destroy() return self._statusbar(_("Installing %s" %fname)) deps, conflicts = self.database.get_local_file_deps(fname) install = [] remove = [] for dep in deps: dep_pkg = self.database.get_by_name(dep) if not dep_pkg.installed: install.append(dep_pkg) continue for conflict in conflicts: try: conflict_pkg = self.database.get_by_name(conflict) remove.append(conflict_pkg) except NameError: pass continue pacs_queues = { "add": install, "remove": remove } retcode = self._local_confirm(fname, pacs_queues) if retcode: i_dlg = local_install_dialog(fname, pacs_queues, self.icon) i_dlg.connect("destroy", self._after_local_install) i_dlg.run() def _after_local_install(self, wid, data=None): self.database.refresh() self.models["foreigners"] = installed_list(self.database["foreigners"]) self._statusbar() def _local_confirm(self, fname, pacs_queue): dlg = local_confirm_dialog(self.gld.get_widget("main_win"), fname, pacs_queue, self.icon) if dlg.run(): retcode = True else: retcode = False return retcode def clear_cache(self, wid, data=None): self._statusbar(msg=_("Clearing cache...")) dlg = command_dialog(self.icon) dlg.connect("destroy", self._done) dlg.run("Sc") return def empty_cache(self, wid, data=None): self._statusbar(_("Emptying cache...")) dlg = command_dialog(self.icon) dlg.connect("destroy", self._done) dlg.run("Scc") return def _done(self, widget, data=None): self._statusbar() def upgrade_system(self, widget, data=None): to_upgrade = [] for repo in self.database.values(): for pac in repo: if pac.isold: to_upgrade.append(pac) continue continue if to_upgrade: confirm = self._upgrade_confirm(to_upgrade) if confirm: self._statusbar(_("Refreshing database...")) dlg = upgrade_dialog(to_upgrade, self.icon) dlg.connect("destroy", self._done_upgrade) dlg.run() else: self._statusbar(_("There isn't any packages to upgrade")) return def _upgrade_confirm(self, to_upgrade): dlg = upgrade_confirm_dialog(self.gld.get_widget("main_win"), to_upgrade, self.icon) retcode = dlg.run() return retcode def refresh_database(self, widget, data=None): self._statusbar(_("Refreshing database...")) dlg = command_dialog(self.icon) dlg.connect("destroy", self._done_upgrade) dlg.run("Sy") return def _done_upgrade(self, widget, data=None): self.database.refresh() self._refresh_repos_tree() self._setup_pacs_models() self._statusbar(_("Updating compleated")) def make_package(self, widget): from os import chdir, geteuid, curdir from os.path import dirname, abspath dlg = choose_pkgbuild_dialog(self.gld.get_widget("main_win"), self.icon) fname = dlg.run() dlg.destroy() try: dname = dirname(fname) except: return pwd = abspath(curdir) chdir(dname) cdlg = command_dialog(self.icon) if geteuid() == 0: dlg = change_user_dialog(self.gld.get_widget("main_win"), self.icon) user = dlg.run() if user == "root": cdlg.run("makepkg --asroot -si") elif user == "reject": pass else: cdlg.run("su %s -c 'makepkg -si'" %user, False) dlg.destroy() else: cdlg.run("makepkg -si", False) chdir(pwd) def _statusbar(self, msg=None): stat_bar = self.gld.get_widget("statusbar") if type(msg) == type(()): str = _("%s packages in [ %s ]") %(msg[0], msg[1]) elif msg == None: str = _("Done") else: str = "%s " %msg stat_bar.push(-1, str)
def __init__(self): """ Set up the preferences window Find the glade file as it was installed, or search for custom DESTDIR or check if not installed at all. """ glade_filename = "preferences.glade" glade_file = path.normpath(path.join(glade_directory, glade_filename)) if not path.exists(glade_file): # Try to find if installed with DESTDIR from utils import guess_destdir while glade_file[0] == "/": glade_file = glade_file[1:] destdir = guess_destdir() if destdir: glade_file = path.join(destdir, glade_file) print_debug(glade_file) if not path.exists(glade_file): # try to find if not installed from sys import argv prog_location = path.abspath(argv[0]) (head, tail) = path.split(prog_location) glade_file = path.join(head, "data", glade_filename) print_debug(glade_file) print_debug("Loading %s" % glade_file) try: self.ui = XML(glade_file) except: from utils import print_error print_error("Failed to load UI file for preferences window!") print_error("File: %s" % glade_file) self.win = None return self.win = self.ui.get_widget("prefswindow") self.check_stick = self.ui.get_widget("check_stick") self.check_open = self.ui.get_widget("check_open") self.check_remove = self.ui.get_widget("check_remove") # signals from .glade file signals = { "on_check_stick_toggled" : self.cb_stick_toggled, "on_check_open_toggled" : self.cb_open_toggled, "on_close_clicked" : self.cb_close_clicked, "on_check_remove_toggled" : self.cb_remove_toggled, "on_prefswindow_delete_event" : self.cb_delete_event, } # connect signals self.ui.signal_autoconnect(signals) # Set check boxes to prefs values stick = preferences.get_bool("stick", if_none=True) self.check_stick.set_active(stick) open = preferences.get_bool("open", if_none=False) self.check_open.set_active(open) remove = preferences.get_bool("remove", if_none=False) self.check_remove.set_active(remove) # set window icon from gtk import STOCK_DND_MULTIPLE, ICON_SIZE_DIALOG pixbuf = self.win.render_icon(STOCK_DND_MULTIPLE, ICON_SIZE_DIALOG) self.win.set_icon(pixbuf) # hide window -- only show it if asked for self.win.hide()