def __init__(self, parent): """Prepare the services dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('services.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_services.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position(self.ui.dialog_services, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels 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 column headers for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn): widget.set_title(text(widget.get_title())) # Load the services self.model = ModelServices(self.ui.store_services) self.selected_iter = None self.ui.cell_icon.props.height = preferences.get(preferences.ICON_SIZE) # Sort the data in the models self.model.model.set_sort_column_id( self.ui.column_name.get_sort_column_id(), Gtk.SortType.ASCENDING) # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def __init__(self, parent): """Prepare the services dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('services.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_services.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position( self.ui.dialog_services, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels 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 column headers for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn): widget.set_title(text(widget.get_title())) # Load the services self.model = ModelServices(self.ui.store_services) self.selected_iter = None self.ui.cell_icon.props.height = preferences.get(preferences.ICON_SIZE) # Sort the data in the models self.model.model.set_sort_column_id( self.ui.column_name.get_sort_column_id(), Gtk.SortType.ASCENDING) # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def __init__(self, name, description, command, terminal, icon): self.name = name self.description = description self.command = command self.terminal = terminal self.icon = icon self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( icon, preferences.get(preferences.ICON_SIZE), preferences.get(preferences.ICON_SIZE)) if icon else None
def add_line(self, severity, text): """Add a text line to the debug buffer""" # Check the requested severity level if (severity == INFO and preferences.get(DEBUG_SHOW_INFO) or (severity == WARNING and preferences.get(DEBUG_SHOW_WARNING)) or (severity == ERROR and preferences.get(DEBUG_SHOW_ERROR))): timestamp = (DEBUG_FORMAT_TIMESTAMP.format(datetime.datetime.now()) if preferences.get(DEBUG_TIMESTAMP) else '') self.add_text(DEBUG_FORMAT.format(timestamp=timestamp, severity=severity, text=text))
def add_line(self, severity, text): """Add a text line to the debug buffer""" # Check the requested severity level if (severity == INFO and preferences.get(DEBUG_SHOW_INFO) or (severity == WARNING and preferences.get(DEBUG_SHOW_WARNING)) or (severity == ERROR and preferences.get(DEBUG_SHOW_ERROR))): timestamp = (DEBUG_FORMAT_TIMESTAMP.format(datetime.datetime.now()) if preferences.get(DEBUG_TIMESTAMP) else '') self.add_text( DEBUG_FORMAT.format(timestamp=timestamp, severity=severity, text=text))
def update_preview_cb(widget, image, get_preview_filename, set_active): """Update preview by trying to load the image""" try: # Try to load the image from the previewed file image.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file_at_size( get_preview_filename(), preferences.get(preferences.PREVIEW_SIZE), preferences.get(preferences.PREVIEW_SIZE))) set_active(True) except: # Hide the preview widget for errors image.set_from_pixbuf(None) set_active(False)
def update_preview_cb(widget, image, get_preview_filename, set_active): """Update preview by trying to load the image""" try: # Try to load the image from the previewed file image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( get_preview_filename(), preferences.get(preferences.PREVIEW_SIZE), preferences.get(preferences.PREVIEW_SIZE))) set_active(True) except: # Hide the preview widget for errors image.set_from_pixbuf(None) set_active(False)
def __init__(self, parent, services): """Prepare the services detail dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('service_detail.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_edit_service.set_transient_for(parent) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels widget.set_label(text(widget.get_label())) # Initialize labels for widget in self.ui.get_objects_by_type(Gtk.Label): widget.set_label(text(widget.get_label())) widget.set_tooltip_text(widget.get_label().replace('_', '')) # 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('_', '')) self.model = services self.selected_iter = None self.name = '' self.description = '' self.command = '[]' self.terminal = False self.icon = '' # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def on_action_browse_icon_activate(self, action): """Browse for an icon file""" def update_preview_cb(widget, image, get_preview_filename, set_active): """Update preview by trying to load the image""" try: # Try to load the image from the previewed file image.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size( get_preview_filename(), preferences.get(preferences.PREVIEW_SIZE), preferences.get(preferences.PREVIEW_SIZE))) set_active(True) except: # Hide the preview widget for errors image.set_from_pixbuf(None) set_active(False) # Prepare the browse for icon dialog dialog = UIFileChooserOpenFile(self.ui.dialog_edit_service, text("Select a File")) dialog.add_filter(_("All Image Files"), "image/*", None) dialog.add_filter(_("All Files"), None, "*") dialog.set_filename(self.ui.txt_icon.get_text()) # Set the image preview widget image_preview = Gtk.Image() image_preview.set_hexpand(False) image_preview.set_size_request( preferences.get(preferences.PREVIEW_SIZE), -1) dialog.set_preview_widget(image_preview, update_preview_cb) # Show the browse for icon dialog filename = dialog.show() if filename is not None: self.ui.txt_icon.set_text(filename) dialog.destroy()
def __init__(self, parent, delete_event_cb): """Prepare the Debug dialog""" self.on_window_debug_delete_event = delete_event_cb # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('debug.glade')) # Initialize preferences self.actions_preferences = { DEBUG_ENABLED: self.ui.action_enable, DEBUG_ENABLED_HIDDEN: self.ui.action_enable_hidden, DEBUG_SHOW_INFO: self.ui.action_show_info, DEBUG_SHOW_WARNING: self.ui.action_show_warning, DEBUG_SHOW_ERROR: self.ui.action_show_error, DEBUG_TIMESTAMP: self.ui.action_show_timestamp, DEBUG_FOLLOW_TEXT: self.ui.action_follow_text, } for key in self.actions_preferences: self.actions_preferences[key].set_active(preferences.get(key)) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels widget.set_label(text(widget.get_label())) # Initialize tooltips for widget in self.ui.get_objects_by_type(Gtk.ToolButton): action = widget.get_related_action() if action: widget.set_tooltip_text(action.get_label().replace('_', '')) # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def __init__(self, parent, destinations): """Prepare the destination dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('destination.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_destination.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position( self.ui.dialog_destination, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels widget.set_label(text(widget.get_label())) # Initialize labels for widget in self.ui.get_objects_by_type(Gtk.Label): widget.set_label(text(widget.get_label())) widget.set_tooltip_text(widget.get_label().replace('_', '')) # 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('_', '')) self.model = destinations self.selected_iter = None self.name = '' self.value = '' # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def __init__(self, parent, destinations): """Prepare the service association dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('service_association.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_association.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position(self.ui.dialog_association, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels widget.set_label(text(widget.get_label())) # Initialize labels for widget in self.ui.get_objects_by_type(Gtk.Label): widget.set_label(text(widget.get_label())) widget.set_tooltip_text(widget.get_label().replace('_', '')) # 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('_', '')) # Load destinations self.destinations = destinations self.ui.cbo_destinations.set_model(self.destinations.model) # Load services self.services = ModelServices(self.ui.store_services) self.services.load(model_services.services) # Connect signals from the glade file to the module functions self.ui.connect_signals(self) self.service_arguments_widgets = {}
def __init__(self, parent): """Prepare the command arguments dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('command_arguments.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_arguments.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position(self.ui.dialog_arguments, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels 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 column headers for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn): widget.set_title(text(widget.get_title())) # Load the arguments self.model_arguments = self.ui.store_arguments self.arguments = '[]' # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def on_action_browse_icon_activate(self, action): """Browse for an icon file""" def update_preview_cb(widget, image, get_preview_filename, set_active): """Update preview by trying to load the image""" try: # Try to load the image from the previewed file image.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file_at_size( get_preview_filename(), preferences.get(preferences.PREVIEW_SIZE), preferences.get(preferences.PREVIEW_SIZE))) set_active(True) except: # Hide the preview widget for errors image.set_from_pixbuf(None) set_active(False) # Prepare the browse for icon dialog dialog = UIFileChooserOpenFile(self.ui.dialog_edit_service, text("Select a File")) dialog.add_filter(_("All Image Files"), "image/*", None) dialog.add_filter(_("All Files"), None, "*") dialog.set_filename(self.ui.txt_icon.get_text()) # Set the image preview widget image_preview = Gtk.Image() image_preview.set_hexpand(False) image_preview.set_size_request( preferences.get(preferences.PREVIEW_SIZE), -1) dialog.set_preview_widget(image_preview, update_preview_cb) # Show the browse for icon dialog filename = dialog.show() if filename is not None: self.ui.txt_icon.set_text(filename) dialog.destroy()
def __init__(self, parent): """Prepare the command arguments dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file("command_arguments.glade")) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_arguments.set_transient_for(parent) # Restore the saved size and position settings.positions.restore_window_position(self.ui.dialog_arguments, SECTION_WINDOW_NAME) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels 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 column headers for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn): widget.set_title(text(widget.get_title())) # Load the arguments self.model_arguments = self.ui.store_arguments self.arguments = "[]" # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def add_text(self, text): """Add a text to the debug buffer""" if preferences.get(DEBUG_ENABLED) and ( preferences.get(DEBUG_ENABLED_HIDDEN) or self.ui.window_debug.get_visible()): # Insert the text at the end self.ui.buffer_debug.insert(self.ui.buffer_debug.get_end_iter(), text) # Follow the text if requested if preferences.get(DEBUG_FOLLOW_TEXT): process_events() self.ui.textview_debug.scroll_to_iter( iter=self.ui.buffer_debug.get_end_iter(), within_margin=0.0, use_align=False, xalign=0.0, yalign=0.0)
def create_button_from_action(action): """Create a new Gtk.Button from a Gtk.Action""" if isinstance(action, Gtk.ToggleAction): new_button = Gtk.ToggleButton() else: new_button = Gtk.Button() new_button.set_use_action_appearance(False) new_button.set_related_action(action) # Use icon from the 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) new_button.set_image( Gtk.Image.new_from_icon_name(icon_name, icon_size)) # Set the tooltip from the action label new_button.set_tooltip_text(action.get_label().replace('_', '')) return new_button
def loadUI(self): """Load the interface UI""" self.ui = GtkBuilderLoader(get_ui_file('main.glade')) 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 widget.set_label(text(widget.get_label())) # Initialize tooltips for widget in self.ui.get_objects_by_type(Gtk.ToolButton): action = widget.get_related_action() if action: widget.set_tooltip_text(action.get_label().replace('_', '')) # Initialize column headers for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn): widget.set_title(text(widget.get_title())) # Set list items row height icon_size = preferences.ICON_SIZE self.ui.cell_name.props.height = preferences.get(icon_size) self.ui.cell_group_name.props.height = preferences.get(icon_size) # Set groups visibility self.ui.scroll_groups.set_visible( preferences.get(preferences.GROUPS_SHOW)) # Add a Gtk.Headerbar, only for GTK+ 3.10.0 and higher if (not Gtk.check_version(3, 10, 0) and not preferences.get(preferences.HEADERBARS_DISABLE)): self.load_ui_headerbar() if preferences.get(preferences.HEADERBARS_REMOVE_TOOLBAR): # This is only for development, it should always be True # Remove the redundant toolbar self.ui.toolbar_main.destroy() # Flatten the Gtk.ScrolledWindows self.ui.scroll_groups.set_shadow_type(Gtk.ShadowType.NONE) self.ui.scroll_connections.set_shadow_type(Gtk.ShadowType.NONE) # Connect signals from the glade file to the module functions self.ui.connect_signals(self)
def set_data(self, treeiter, item): """Update an existing TreeIter""" super(self.__class__, self).set_data(treeiter, item) icon = item.icon if item.icon is not None else '' icon_size = preferences.get(preferences.ICON_SIZE) pixbuf = None if icon == '' else \ GdkPixbuf.Pixbuf.new_from_file_at_size(item.icon, icon_size, icon_size) self.model.set_value(treeiter, self.COL_KEY, item.name) self.model.set_value(treeiter, self.COL_DESCRIPTION, item.description) self.model.set_value(treeiter, self.COL_COMMAND, item.command) self.model.set_value(treeiter, self.COL_TERMINAL, item.terminal) self.model.set_value(treeiter, self.COL_ICON, icon) self.model.set_value(treeiter, self.COL_PIXBUF, pixbuf)
def add_data(self, item): """Add a new row to the model if it doesn't exists""" super(self.__class__, self).add_data(item) if item.name not in self.rows: icon = item.icon if item.icon is not None else '' icon_size = preferences.get(preferences.ICON_SIZE) pixbuf = None if icon == '' else \ GdkPixbuf.Pixbuf.new_from_file_at_size(item.icon, icon_size, icon_size) new_row = self.model.append( (item.name, item.description, item.command, item.terminal, icon, pixbuf)) self.rows[item.name] = new_row return new_row
def on_txt_icon_changed(self, widget): """Check the icon field""" text = widget.get_text().strip() if len(text) > 0 and os.path.isfile(text): icon_size = preferences.get(preferences.ICON_SIZE) self.ui.image_icon.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size(text, icon_size, icon_size)) icon_name = None else: icon_name = 'dialog-error' if len(text) > 0 else None self.ui.image_icon.set_from_icon_name('image-missing', Gtk.IconSize.LARGE_TOOLBAR) widget.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, icon_name)
def on_txt_icon_changed(self, widget): """Check the icon field""" text = widget.get_text().strip() if len(text) > 0 and os.path.isfile(text): icon_size = preferences.get(preferences.ICON_SIZE) self.ui.image_icon.set_from_pixbuf( GdkPixbuf.Pixbuf.new_from_file_at_size(text, icon_size, icon_size)) icon_name = None else: icon_name = 'dialog-error' if len(text) > 0 else None self.ui.image_icon.set_from_icon_name('image-missing', Gtk.IconSize.LARGE_TOOLBAR) widget.set_icon_from_icon_name( Gtk.EntryIconPosition.SECONDARY, icon_name)
def add_data(self, item): """Add a new row to the model if it doesn't exists""" super(self.__class__, self).add_data(item) if item.name not in self.rows: icon = item.icon if item.icon is not None else '' icon_size = preferences.get(preferences.ICON_SIZE) pixbuf = None if icon == '' else \ GdkPixbuf.Pixbuf.new_from_file_at_size(item.icon, icon_size, icon_size) new_row = self.model.append(( item.name, item.description, item.command, item.terminal, icon, pixbuf)) self.rows[item.name] = new_row return new_row
def __init__(self, parent): """Prepare the about dialog""" # Retrieve the translators list translators = [] for line in readlines(FILE_TRANSLATORS, False): if ':' in line: line = line.split(':', 1)[1] line = line.replace('(at)', '@').strip() if line not in translators: translators.append(line) # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('about.glade')) # Set various properties self.ui.dialog_about.set_program_name(APP_NAME) self.ui.dialog_about.set_version('Version %s' % APP_VERSION) self.ui.dialog_about.set_comments(APP_DESCRIPTION) self.ui.dialog_about.set_website(APP_URL) self.ui.dialog_about.set_copyright(APP_COPYRIGHT) # Prepare lists for authors and contributors authors = ['%s <%s>' % (APP_AUTHOR, APP_AUTHOR_EMAIL)] contributors = [] for line in readlines(FILE_CONTRIBUTORS, False): contributors.append(line) if len(contributors) > 0: contributors.insert(0, _('Contributors:')) authors.extend(contributors) self.ui.dialog_about.set_authors(authors) self.ui.dialog_about.set_license('\n'.join( readlines(FILE_LICENSE, True))) self.ui.dialog_about.set_translator_credits('\n'.join(translators)) # Retrieve the external resources links # only for GTK+ 3.6.0 and higher if not Gtk.check_version(3, 6, 0): for line in readlines(FILE_RESOURCES, False): resource_type, resource_url = line.split(':', 1) self.ui.dialog_about.add_credit_section( resource_type, (resource_url, )) icon_logo = Pixbuf.new_from_file(FILE_ICON) self.ui.dialog_about.set_logo(icon_logo) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_about.set_transient_for(parent)
def __init__(self, parent): """Prepare the about dialog""" # Retrieve the translators list translators = [] for line in readlines(FILE_TRANSLATORS, False): if ':' in line: line = line.split(':', 1)[1] line = line.replace('(at)', '@').strip() if line not in translators: translators.append(line) # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('about.glade')) # Set various properties self.ui.dialog_about.set_program_name(APP_NAME) self.ui.dialog_about.set_version('Version %s' % APP_VERSION) self.ui.dialog_about.set_comments(APP_DESCRIPTION) self.ui.dialog_about.set_website(APP_URL) self.ui.dialog_about.set_copyright(APP_COPYRIGHT) # Prepare lists for authors and contributors authors = ['%s <%s>' % (APP_AUTHOR, APP_AUTHOR_EMAIL)] contributors = [] for line in readlines(FILE_CONTRIBUTORS, False): contributors.append(line) if len(contributors) > 0: contributors.insert(0, _('Contributors:')) authors.extend(contributors) self.ui.dialog_about.set_authors(authors) self.ui.dialog_about.set_license( '\n'.join(readlines(FILE_LICENSE, True))) self.ui.dialog_about.set_translator_credits('\n'.join(translators)) # Retrieve the external resources links # only for GTK+ 3.6.0 and higher if not Gtk.check_version(3, 6, 0): for line in readlines(FILE_RESOURCES, False): resource_type, resource_url = line.split(':', 1) self.ui.dialog_about.add_credit_section( resource_type, (resource_url,)) icon_logo = Pixbuf.new_from_file(FILE_ICON) self.ui.dialog_about.set_logo(icon_logo) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_about.set_transient_for(parent)
def __init__(self, parent): """Prepare the argument dialog""" # Load the user interface self.ui = GtkBuilderLoader(get_ui_file('command_argument.glade')) if not preferences.get(preferences.DETACHED_WINDOWS): self.ui.dialog_argument.set_transient_for(parent) # Initialize actions for widget in self.ui.get_objects_by_type(Gtk.Action): # Connect the actions accelerators widget.connect_accelerator() # Set labels widget.set_label(text(widget.get_label())) # Initialize labels for widget in self.ui.get_objects_by_type(Gtk.Label): widget.set_label(text(widget.get_label())) widget.set_tooltip_text(widget.get_label().replace('_', '')) # 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('_', '')) self.argument = '' # Connect signals from the glade file to the module functions self.ui.connect_signals(self)