コード例 #1
0
 def on_treeview_folders_cursor_changed(self, widget):
     selected_row = get_treeview_selected_row(self.ui.treeview_folders)
     if selected_row:
         folder_name = self.model_folders.get_key(selected_row)
         # Check if the folder still exists
         # (model erased while the cursor moves through the Gtk.TreeView)
         if folder_name in self.folders:
             folder_info = self.folders[folder_name]
             # Clear any previous application icon
             self.model_applications.clear()
             # Add new application icons
             applications = folder_info.get_applications()
             for application in applications:
                 desktop_file = applications[application]
                 if desktop_file or preferences.get(
                         preferences.PREFERENCES_SHOW_MISSING):
                     application_file = applications[application]
                     application_info = ApplicationInfo(
                         application,
                         application_file.getName()
                         if desktop_file else 'Missing desktop file',
                         application_file.getComment()
                         if desktop_file else application,
                         application_file.getIcon()
                         if desktop_file else None,
                         # Always show any application, also if hidden
                         True)
                     self.model_applications.add_data(application_info)
         # Disable folder content saving
         self.ui.action_files_save.set_sensitive(False)
コード例 #2
0
 def on_treeview_folders_cursor_changed(self, widget):
     selected_row = get_treeview_selected_row(self.ui.treeview_folders)
     if selected_row:
         folder_name = self.model_folders.get_key(selected_row)
         # Check if the folder still exists
         # (model erased while the cursor moves through the Gtk.TreeView)
         if folder_name in self.folders:
             folder_info = self.folders[folder_name]
             # Clear any previous application icon
             self.model_applications.clear()
             # Add new application icons
             applications = folder_info.get_applications()
             for application in applications:
                 desktop_file = applications[application]
                 if desktop_file or preferences.get(
                         preferences.PREFERENCES_SHOW_MISSING):
                     application_file = applications[application]
                     application_info = ApplicationInfo(
                         application,
                         application_file.getName()
                         if desktop_file else 'Missing desktop file',
                         application_file.getComment()
                         if desktop_file else application,
                         application_file.getIcon()
                         if desktop_file else None,
                         # Always show any application, also if hidden
                         True)
                     self.model_applications.add_data(application_info)
         # Disable folder content saving
         self.ui.action_files_save.set_sensitive(False)
コード例 #3
0
 def loadUI(self):
     """Load the interface UI"""
     self.ui = GtkBuilderLoader(get_ui_file('main.ui'))
     self.ui.win_main.set_application(self.application)
     self.ui.win_main.set_title(APP_NAME)
     # Initialize actions
     for widget in self.ui.get_objects_by_type(Gtk.Action):
         # Connect the actions accelerators
         widget.connect_accelerator()
         # Set labels
         label = widget.get_label()
         if not label:
             label = widget.get_short_label()
         widget.set_label(text(label))
         widget.set_short_label(label)
     # Initialize labels
     for widget in self.ui.get_objects_by_type(Gtk.Label):
         widget.set_label(text(widget.get_label()))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Initialize Gtk.HeaderBar
     self.ui.header_bar.props.title = self.ui.win_main.get_title()
     self.ui.win_main.set_titlebar(self.ui.header_bar)
     for button in (self.ui.button_folder_new, self.ui.button_folder_remove,
                    self.ui.button_folder_properties,
                    self.ui.button_files_add, self.ui.button_files_remove,
                    self.ui.button_files_save, self.ui.button_about, ):
         action = button.get_related_action()
         icon_name = action.get_icon_name()
         if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
             icon_name += '-symbolic'
         # Get desired icon size
         icon_size = (Gtk.IconSize.BUTTON
                      if preferences.get(preferences.HEADERBARS_SMALL_ICONS)
                      else Gtk.IconSize.LARGE_TOOLBAR)
         button.set_image(Gtk.Image.new_from_icon_name(icon_name,
                                                       icon_size))
         # Remove the button label
         button.props.label = None
         # Set the tooltip from the action label
         button.set_tooltip_text(action.get_label().replace('_', ''))
     # Set preferences button icon
     icon_name = self.ui.image_preferences.get_icon_name()[0]
     if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
         icon_name += '-symbolic'
     self.ui.image_preferences.set_from_icon_name(icon_name, icon_size)
     # Load settings
     self.dict_settings_map = {
         preferences.HEADERBARS_SMALL_ICONS:
             self.ui.action_preferences_small_icons,
         preferences.HEADERBARS_SYMBOLIC_ICONS:
             self.ui.action_preferences_symbolic_icons,
         preferences.PREFERENCES_SHOW_MISSING:
             self.ui.action_preferences_show_missing_files
     }
     for setting_name, action in self.dict_settings_map.items():
         action.set_active(preferences.get(setting_name))
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)
コード例 #4
0
 def __init__(self, parent, existing_files):
     """Prepare the application picker dialog"""
     # Load the user interface
     self.ui = GtkBuilderLoader(get_ui_file('application_picker.ui'))
     self.ui.dialog_application_picker.set_titlebar(self.ui.header_bar)
     # Prepares the models for the applications
     self.model_applications = ModelApplications(self.ui.store_applications)
     self.model_applications.model.set_sort_column_id(
         self.ui.treeview_column_applications.get_sort_column_id(),
         Gtk.SortType.ASCENDING)
     self.ui.filter_applications.set_visible_column(
         ModelApplications.COL_VISIBLE)
     # Initialize actions
     for widget in self.ui.get_objects_by_type(Gtk.Action):
         # Connect the actions accelerators
         widget.connect_accelerator()
         # Set labels
         label = widget.get_label()
         if not label:
             label = widget.get_short_label()
         widget.set_short_label(text(label))
         widget.set_label(text(label))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Set various properties
     self.ui.dialog_application_picker.set_transient_for(parent)
     set_style_suggested_action(self.ui.button_add)
     self.selected_applications = None
     # Set preferences button icon
     icon_name = self.ui.image_preferences.get_icon_name()[0]
     if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
         icon_name += '-symbolic'
     # Get desired icon size
     icon_size = (Gtk.IconSize.BUTTON
                  if preferences.get(preferences.HEADERBARS_SMALL_ICONS)
                  else Gtk.IconSize.LARGE_TOOLBAR)
     self.ui.image_preferences.set_from_icon_name(icon_name, icon_size)
     # Load settings
     self.dict_settings_map = {
         preferences.APP_PICKER_SHOW_HIDDEN: self.ui.action_show_hidden
     }
     for setting_name, action in self.dict_settings_map.items():
         action.set_active(preferences.get(setting_name))
     # Prepares the applications list
     for desktop_entry in Gio.app_info_get_all():
         try:
             icon_name = None
             icon = desktop_entry.get_icon()
             if isinstance(icon, Gio.ThemedIcon):
                 # From Gio.ThemedIcon get the icon name only
                 icons = desktop_entry.get_icon().get_names()
                 icon_name = icons[0] if icons else None
             elif isinstance(icon, Gio.FileIcon):
                 # From Gio.FileIcon get the full file name
                 icon_name = icon.get_file().get_parse_name()
             description = (desktop_entry.get_description()
                            if desktop_entry.get_description() else '')
             application = ApplicationInfo(desktop_entry.get_id(),
                                           desktop_entry.get_name(),
                                           description, icon_name,
                                           desktop_entry.should_show())
             # Skip existing files
             if application.filename not in existing_files:
                 self.model_applications.add_data(application)
         except Exception as e:
             print 'error for', desktop_entry.get_id(), e
     self.model_applications.set_all_rows_visibility(
         preferences.get(preferences.APP_PICKER_SHOW_HIDDEN))
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)
コード例 #5
0
 def __init__(self, parent, existing_files):
     """Prepare the application picker dialog"""
     # Load the user interface
     self.ui = GtkBuilderLoader(get_ui_file('application_picker.ui'))
     self.ui.dialog_application_picker.set_titlebar(self.ui.header_bar)
     # Prepares the models for the applications
     self.model_applications = ModelApplications(self.ui.store_applications)
     self.model_applications.model.set_sort_column_id(
         self.ui.treeview_column_applications.get_sort_column_id(),
         Gtk.SortType.ASCENDING)
     self.ui.filter_applications.set_visible_column(
         ModelApplications.COL_VISIBLE)
     # Initialize actions
     for widget in self.ui.get_objects_by_type(Gtk.Action):
         # Connect the actions accelerators
         widget.connect_accelerator()
         # Set labels
         label = widget.get_label()
         if not label:
             label = widget.get_short_label()
         widget.set_short_label(text(label))
         widget.set_label(text(label))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Set various properties
     self.ui.dialog_application_picker.set_transient_for(parent)
     set_style_suggested_action(self.ui.button_add)
     self.selected_applications = None
     # Set preferences button icon
     icon_name = self.ui.image_preferences.get_icon_name()[0]
     if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
         icon_name += '-symbolic'
     # Get desired icon size
     icon_size = (Gtk.IconSize.BUTTON
                  if preferences.get(preferences.HEADERBARS_SMALL_ICONS)
                  else Gtk.IconSize.LARGE_TOOLBAR)
     self.ui.image_preferences.set_from_icon_name(icon_name, icon_size)
     # Load settings
     self.dict_settings_map = {
         preferences.APP_PICKER_SHOW_HIDDEN:
             self.ui.action_show_hidden
     }
     for setting_name, action in self.dict_settings_map.items():
         action.set_active(preferences.get(setting_name))
     # Prepares the applications list
     for desktop_entry in Gio.app_info_get_all():
         try:
             icon_name = None
             icon = desktop_entry.get_icon()
             if isinstance(icon, Gio.ThemedIcon):
                 # From Gio.ThemedIcon get the icon name only
                 icons = desktop_entry.get_icon().get_names()
                 icon_name = icons[0] if icons else None
             elif isinstance(icon, Gio.FileIcon):
                 # From Gio.FileIcon get the full file name
                 icon_name = icon.get_file().get_parse_name()
             description = (desktop_entry.get_description()
                            if desktop_entry.get_description() else '')
             application = ApplicationInfo(desktop_entry.get_id(),
                                           desktop_entry.get_name(),
                                           description,
                                           icon_name,
                                           desktop_entry.should_show())
             # Skip existing files
             if application.filename not in existing_files:
                 self.model_applications.add_data(application)
         except Exception as e:
             print 'error for', desktop_entry.get_id(), e
     self.model_applications.set_all_rows_visibility(
         preferences.get(preferences.APP_PICKER_SHOW_HIDDEN))
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)
コード例 #6
0
 def loadUI(self):
     """Load the interface UI"""
     self.ui = GtkBuilderLoader(get_ui_file('main.ui'))
     self.ui.win_main.set_application(self.application)
     self.ui.win_main.set_title(APP_NAME)
     # Initialize actions
     for widget in self.ui.get_objects_by_type(Gtk.Action):
         # Connect the actions accelerators
         widget.connect_accelerator()
         # Set labels
         label = widget.get_label()
         if not label:
             label = widget.get_short_label()
         widget.set_label(text(label))
         widget.set_short_label(label)
     # Initialize labels
     for widget in self.ui.get_objects_by_type(Gtk.Label):
         widget.set_label(text(widget.get_label()))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Initialize Gtk.HeaderBar
     self.ui.header_bar.props.title = self.ui.win_main.get_title()
     self.ui.win_main.set_titlebar(self.ui.header_bar)
     for button in (
             self.ui.button_folder_new,
             self.ui.button_folder_remove,
             self.ui.button_folder_properties,
             self.ui.button_files_add,
             self.ui.button_files_remove,
             self.ui.button_files_save,
             self.ui.button_about,
     ):
         action = button.get_related_action()
         icon_name = action.get_icon_name()
         if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
             icon_name += '-symbolic'
         # Get desired icon size
         icon_size = (Gtk.IconSize.BUTTON
                      if preferences.get(preferences.HEADERBARS_SMALL_ICONS)
                      else Gtk.IconSize.LARGE_TOOLBAR)
         button.set_image(Gtk.Image.new_from_icon_name(
             icon_name, icon_size))
         # Remove the button label
         button.props.label = None
         # Set the tooltip from the action label
         button.set_tooltip_text(action.get_label().replace('_', ''))
     # Set preferences button icon
     icon_name = self.ui.image_preferences.get_icon_name()[0]
     if preferences.get(preferences.HEADERBARS_SYMBOLIC_ICONS):
         icon_name += '-symbolic'
     self.ui.image_preferences.set_from_icon_name(icon_name, icon_size)
     # Load settings
     self.dict_settings_map = {
         preferences.HEADERBARS_SMALL_ICONS:
         self.ui.action_preferences_small_icons,
         preferences.HEADERBARS_SYMBOLIC_ICONS:
         self.ui.action_preferences_symbolic_icons,
         preferences.PREFERENCES_SHOW_MISSING:
         self.ui.action_preferences_show_missing_files
     }
     for setting_name, action in self.dict_settings_map.items():
         action.set_active(preferences.get(setting_name))
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)