コード例 #1
0
 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 = {}
コード例 #2
0
 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)
コード例 #3
0
ファイル: services.py プロジェクト: muflone/gCentralAccess
 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)
コード例 #4
0
 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 = {}
コード例 #5
0
class UIServiceAssociation(object):
    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 show(self, default_description, default_destination, default_service,
             default_arguments):
        """Show the Service association dialog"""
        # Set default description
        self.ui.entry_description.set_text(default_description)
        # Set default destination
        if default_destination:
            self.ui.cbo_destinations.set_active_id(default_destination)
        elif self.destinations.count() > 0:
            self.ui.cbo_destinations.set_active(0)
        # Set default service
        if default_service:
            self.ui.cbo_services.set_active_id(default_service)
        elif self.services.count() > 0:
            self.ui.cbo_services.set_active(0)
        # Set default arguments
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            if argument in default_arguments:
                new_entry.set_text(default_arguments[argument])
        # Show the dialog
        response = self.ui.dialog_association.run()
        self.ui.dialog_association.hide()
        self.destination = self.ui.cbo_destinations.get_active_id()
        self.service = self.ui.cbo_services.get_active_id()
        self.description = self.ui.entry_description.get_text()
        # Prepares argument values
        self.arguments = {}
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            self.arguments[argument] = new_entry.get_text()
        return response

    def destroy(self):
        """Destroy the Service association dialog"""
        settings.positions.save_window_position(self.ui.dialog_association,
                                                SECTION_WINDOW_NAME)
        self.ui.dialog_association.destroy()
        self.ui.dialog_association = None

    def on_cbo_services_changed(self, widget):
        """Update the service arguments widgets"""
        treeiter = self.ui.cbo_services.get_active_iter()
        # Remove the previously added arguments widgets
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            new_label.destroy()
            new_entry.destroy()
        self.service_arguments_widgets = {}
        # Collect the needed arguments
        command = get_list_from_string_list(
            self.services.get_command(treeiter))
        row_number = 0
        processed_arguments = []
        # The argument address, already has a default widget
        processed_arguments.append('address')
        for option in command:
            arguments = get_string_fields(option)
            # Add a pair of widgets for each argument
            for argument in arguments:
                # Skip existing arguments
                if argument in processed_arguments:
                    continue
                row_number += 1
                processed_arguments.append(argument)
                # Add a new descriptive label for the argument
                new_label = Gtk.Label('%s:' % argument.title())
                new_label.set_xalign(1.0)
                new_label.set_visible(True)
                self.ui.grid_service_arguments.attach(child=new_label,
                                                      left=0,
                                                      top=row_number,
                                                      width=1,
                                                      height=1)
                # Add a new entry for the argument value
                new_entry = Gtk.Entry()
                new_entry.set_visible(True)
                new_entry.set_hexpand(True)
                self.ui.grid_service_arguments.attach(child=new_entry,
                                                      left=1,
                                                      top=row_number,
                                                      width=1,
                                                      height=1)
                # Save a tuple of widgets, to remove later
                self.service_arguments_widgets[argument] = (new_label,
                                                            new_entry)

    def on_cbo_destinations_changed(self, widget):
        """Update the address entry for the selected destination"""
        treeiter = self.ui.cbo_destinations.get_active_iter()
        self.ui.entry_service_arguments_address.set_text(
            self.destinations.get_value(treeiter))
コード例 #6
0
ファイル: services.py プロジェクト: muflone/gCentralAccess
class UIServices(object):
    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 show(self):
        """Show the Services dialog"""
        self.ui.dialog_services.run()
        self.ui.dialog_services.hide()

    def destroy(self):
        """Destroy the Services dialog"""
        settings.positions.save_window_position(
            self.ui.dialog_services, SECTION_WINDOW_NAME)
        self.ui.dialog_services.destroy()
        self.ui.dialog_services = None

    def on_action_add_activate(self, action):
        """Add a new service"""
        dialog = UIServiceDetail(self.ui.dialog_services, self.model)
        if dialog.show(default_name='',
                       default_description='',
                       default_command='',
                       default_terminal=False,
                       default_icon='',
                       title=_('Add new service'),
                       treeiter=None) == Gtk.ResponseType.OK:
            self.model.add_data(ServiceInfo(name=dialog.name,
                                            description=dialog.description,
                                            command=dialog.command,
                                            terminal=dialog.terminal,
                                            icon=dialog.icon))
        dialog.destroy()

    def on_action_edit_activate(self, action):
        """Edit the selected service"""
        selected_row = get_treeview_selected_row(self.ui.tvw_services)
        if selected_row:
            name = self.model.get_key(selected_row)
            description = self.model.get_description(selected_row)
            command = self.model.get_command(selected_row)
            terminal = self.model.get_terminal(selected_row)
            icon = self.model.get_icon(selected_row)
            selected_iter = self.model.get_iter(name)
            dialog = UIServiceDetail(self.ui.dialog_services, self.model)
            if dialog.show(default_name=name,
                           default_description=description,
                           default_command=command,
                           default_terminal=terminal,
                           default_icon=icon,
                           title=_('Edit service'),
                           treeiter=selected_iter
                           ) == Gtk.ResponseType.OK:
                # Update values
                self.model.set_data(selected_iter, ServiceInfo(
                    name=dialog.name,
                    description=dialog.description,
                    command=dialog.command,
                    terminal=dialog.terminal,
                    icon=dialog.icon))
            dialog.destroy()

    def on_action_remove_activate(self, action):
        """Remove the selected service"""
        selected_row = get_treeview_selected_row(self.ui.tvw_services)
        if selected_row and show_message_dialog(
                class_=UIMessageDialogNoYes,
                parent=self.ui.dialog_services,
                message_type=Gtk.MessageType.WARNING,
                title=None,
                msg1=_("Remove service"),
                msg2=_("Remove the selected service?"),
                is_response_id=Gtk.ResponseType.YES):
            self.model.remove(selected_row)

    def on_tvw_services_row_activated(self, widget, treepath, column):
        """Edit the selected row on activation"""
        self.ui.action_edit.activate()
コード例 #7
0
class UIServices(object):
    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 show(self):
        """Show the Services dialog"""
        self.ui.dialog_services.run()
        self.ui.dialog_services.hide()

    def destroy(self):
        """Destroy the Services dialog"""
        settings.positions.save_window_position(self.ui.dialog_services,
                                                SECTION_WINDOW_NAME)
        self.ui.dialog_services.destroy()
        self.ui.dialog_services = None

    def on_action_add_activate(self, action):
        """Add a new service"""
        dialog = UIServiceDetail(self.ui.dialog_services, self.model)
        if dialog.show(default_name='',
                       default_description='',
                       default_command='',
                       default_terminal=False,
                       default_icon='',
                       title=_('Add new service'),
                       treeiter=None) == Gtk.ResponseType.OK:
            self.model.add_data(
                ServiceInfo(name=dialog.name,
                            description=dialog.description,
                            command=dialog.command,
                            terminal=dialog.terminal,
                            icon=dialog.icon))
        dialog.destroy()

    def on_action_edit_activate(self, action):
        """Edit the selected service"""
        selected_row = get_treeview_selected_row(self.ui.tvw_services)
        if selected_row:
            name = self.model.get_key(selected_row)
            description = self.model.get_description(selected_row)
            command = self.model.get_command(selected_row)
            terminal = self.model.get_terminal(selected_row)
            icon = self.model.get_icon(selected_row)
            selected_iter = self.model.get_iter(name)
            dialog = UIServiceDetail(self.ui.dialog_services, self.model)
            if dialog.show(default_name=name,
                           default_description=description,
                           default_command=command,
                           default_terminal=terminal,
                           default_icon=icon,
                           title=_('Edit service'),
                           treeiter=selected_iter) == Gtk.ResponseType.OK:
                # Update values
                self.model.set_data(
                    selected_iter,
                    ServiceInfo(name=dialog.name,
                                description=dialog.description,
                                command=dialog.command,
                                terminal=dialog.terminal,
                                icon=dialog.icon))
            dialog.destroy()

    def on_action_remove_activate(self, action):
        """Remove the selected service"""
        selected_row = get_treeview_selected_row(self.ui.tvw_services)
        if selected_row and show_message_dialog(
                class_=UIMessageDialogNoYes,
                parent=self.ui.dialog_services,
                message_type=Gtk.MessageType.WARNING,
                title=None,
                msg1=_("Remove service"),
                msg2=_("Remove the selected service?"),
                is_response_id=Gtk.ResponseType.YES):
            self.model.remove(selected_row)

    def on_tvw_services_row_activated(self, widget, treepath, column):
        """Edit the selected row on activation"""
        self.ui.action_edit.activate()
コード例 #8
0
class UIServiceAssociation(object):
    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 show(self, default_description, default_destination, default_service,
             default_arguments):
        """Show the Service association dialog"""
        # Set default description
        self.ui.entry_description.set_text(default_description)
        # Set default destination
        if default_destination:
            self.ui.cbo_destinations.set_active_id(default_destination)
        elif self.destinations.count() > 0:
            self.ui.cbo_destinations.set_active(0)
        # Set default service
        if default_service:
            self.ui.cbo_services.set_active_id(default_service)
        elif self.services.count() > 0:
            self.ui.cbo_services.set_active(0)
        # Set default arguments
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            if argument in default_arguments:
                new_entry.set_text(default_arguments[argument])
        # Show the dialog
        response = self.ui.dialog_association.run()
        self.ui.dialog_association.hide()
        self.destination = self.ui.cbo_destinations.get_active_id()
        self.service = self.ui.cbo_services.get_active_id()
        self.description = self.ui.entry_description.get_text()
        # Prepares argument values
        self.arguments = {}
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            self.arguments[argument] = new_entry.get_text()
        return response

    def destroy(self):
        """Destroy the Service association dialog"""
        settings.positions.save_window_position(
            self.ui.dialog_association, SECTION_WINDOW_NAME)
        self.ui.dialog_association.destroy()
        self.ui.dialog_association = None

    def on_cbo_services_changed(self, widget):
        """Update the service arguments widgets"""
        treeiter = self.ui.cbo_services.get_active_iter()
        # Remove the previously added arguments widgets
        for argument in self.service_arguments_widgets:
            (new_label, new_entry) = self.service_arguments_widgets[argument]
            new_label.destroy()
            new_entry.destroy()
        self.service_arguments_widgets = {}
        # Collect the needed arguments
        command = get_list_from_string_list(
            self.services.get_command(treeiter))
        row_number = 0
        processed_arguments = []
        # The argument address, already has a default widget
        processed_arguments.append('address')
        for option in command:
            arguments = get_string_fields(option)
            # Add a pair of widgets for each argument
            for argument in arguments:
                # Skip existing arguments
                if argument in processed_arguments:
                    continue
                row_number += 1
                processed_arguments.append(argument)
                # Add a new descriptive label for the argument
                new_label = Gtk.Label('%s:' % argument.title())
                new_label.set_xalign(1.0)
                new_label.set_visible(True)
                self.ui.grid_service_arguments.attach(child=new_label,
                                                      left=0,
                                                      top=row_number,
                                                      width=1,
                                                      height=1)
                # Add a new entry for the argument value
                new_entry = Gtk.Entry()
                new_entry.set_visible(True)
                new_entry.set_hexpand(True)
                self.ui.grid_service_arguments.attach(child=new_entry,
                                                      left=1,
                                                      top=row_number,
                                                      width=1,
                                                      height=1)
                # Save a tuple of widgets, to remove later
                self.service_arguments_widgets[argument] = (
                    new_label, new_entry)

    def on_cbo_destinations_changed(self, widget):
        """Update the address entry for the selected destination"""
        treeiter = self.ui.cbo_destinations.get_active_iter()
        self.ui.entry_service_arguments_address.set_text(
            self.destinations.get_value(treeiter))