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 on_action_confirm_activate(self, action):
     """Check the destination configuration before confirm"""
     def show_error_message_on_infobar(widget, error_msg):
         """Show the error message on the GtkInfoBar"""
         set_error_message_on_infobar(
             widget=widget,
             widgets=(self.ui.txt_name, self.ui.txt_value),
             label=self.ui.lbl_error_message,
             infobar=self.ui.infobar_error_message,
             error_msg=error_msg)
     name = self.ui.txt_name.get_text().strip()
     value = self.ui.txt_value.get_text().strip()
     if len(name) == 0:
         # Show error for missing destination name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The destination name is missing'))
     elif '\'' in name or '\\' in name:
         # Show error for invalid destination name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The destination name is invalid'))
     elif self.model.get_iter(name) not in (None, self.selected_iter):
         # Show error for existing destination name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('A destination with that name already exists'))
     elif len(value) == 0:
         # Show error for missing destination value
         show_error_message_on_infobar(
             self.ui.txt_value,
             _('The destination value is missing'))
     else:
         self.ui.dialog_destination.response(Gtk.ResponseType.OK)
    def on_action_confirm_activate(self, action):
        """Check the destination configuration before confirm"""
        def show_error_message_on_infobar(widget, error_msg):
            """Show the error message on the GtkInfoBar"""
            set_error_message_on_infobar(widget=widget,
                                         widgets=(self.ui.txt_name,
                                                  self.ui.txt_value),
                                         label=self.ui.lbl_error_message,
                                         infobar=self.ui.infobar_error_message,
                                         error_msg=error_msg)

        name = self.ui.txt_name.get_text().strip()
        value = self.ui.txt_value.get_text().strip()
        if len(name) == 0:
            # Show error for missing destination name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The destination name is missing'))
        elif '\'' in name or '\\' in name:
            # Show error for invalid destination name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The destination name is invalid'))
        elif self.model.get_iter(name) not in (None, self.selected_iter):
            # Show error for existing destination name
            show_error_message_on_infobar(
                self.ui.txt_name,
                _('A destination with that name already exists'))
        elif len(value) == 0:
            # Show error for missing destination value
            show_error_message_on_infobar(
                self.ui.txt_value, _('The destination value is missing'))
        else:
            self.ui.dialog_destination.response(Gtk.ResponseType.OK)
    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()
Exemple #5
0
 def on_action_confirm_activate(self, action):
     """Check che host configuration before confirm"""
     def show_error_message_on_infobar(widget, error_msg):
         """Show the error message on the GtkInfoBar"""
         set_error_message_on_infobar(
             widget=widget,
             widgets=(self.ui.txt_name, self.ui.txt_description),
             label=self.ui.lbl_error_message,
             infobar=self.ui.infobar_error_message,
             error_msg=error_msg)
     name = self.ui.txt_name.get_text().strip()
     description = self.ui.txt_description.get_text().strip()
     if len(name) == 0:
         # Show error for missing host name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The host name is missing'))
     elif '\'' in name or '\\' in name or '/' in name:
         # Show error for invalid host name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The host name is invalid'))
     elif self.hosts.get_iter(name) not in (None, self.selected_iter):
         # Show error for existing host name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('A host with that name already exists'))
     elif len(description) == 0:
         # Show error for missing host description
         show_error_message_on_infobar(
             self.ui.txt_description,
             _('The host description is missing'))
     else:
         self.ui.dialog_host.response(Gtk.ResponseType.OK)
Exemple #6
0
    def on_action_confirm_activate(self, action):
        """Check che host configuration before confirm"""
        def show_error_message_on_infobar(widget, error_msg):
            """Show the error message on the GtkInfoBar"""
            set_error_message_on_infobar(widget=widget,
                                         widgets=(self.ui.txt_name,
                                                  self.ui.txt_description),
                                         label=self.ui.lbl_error_message,
                                         infobar=self.ui.infobar_error_message,
                                         error_msg=error_msg)

        name = self.ui.txt_name.get_text().strip()
        description = self.ui.txt_description.get_text().strip()
        if len(name) == 0:
            # Show error for missing host name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The host name is missing'))
        elif '\'' in name or '\\' in name or '/' in name:
            # Show error for invalid host name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The host name is invalid'))
        elif self.hosts.get_iter(name) not in (None, self.selected_iter):
            # Show error for existing host name
            show_error_message_on_infobar(
                self.ui.txt_name, _('A host with that name already exists'))
        elif len(description) == 0:
            # Show error for missing host description
            show_error_message_on_infobar(self.ui.txt_description,
                                          _('The host description is missing'))
        else:
            self.ui.dialog_host.response(Gtk.ResponseType.OK)
 def on_action_confirm_activate(self, action):
     """Check che group configuration before confirm"""
     def show_error_message_on_infobar(widget, error_msg):
         """Show the error message on the GtkInfoBar"""
         set_error_message_on_infobar(
             widget=widget,
             widgets=(self.ui.txt_name, ),
             label=self.ui.lbl_error_message,
             infobar=self.ui.infobar_error_message,
             error_msg=error_msg)
     name = self.ui.txt_name.get_text().strip()
     if len(name) == 0:
         # Show error for missing group name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The group name is missing'))
     elif '\'' in name or '\\' in name or '/' in name or ',' in name:
         # Show error for invalid group name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The Group name is invalid'))
     elif self.model.get_iter(name):
         # Show error for existing group name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('A group with that name already exists'))
     else:
         self.ui.dialog_edit_group.response(Gtk.ResponseType.OK)
Exemple #8
0
    def on_action_confirm_activate(self, action):
        """Check che group configuration before confirm"""
        def show_error_message_on_infobar(widget, error_msg):
            """Show the error message on the GtkInfoBar"""
            set_error_message_on_infobar(widget=widget,
                                         widgets=(self.ui.txt_name, ),
                                         label=self.ui.lbl_error_message,
                                         infobar=self.ui.infobar_error_message,
                                         error_msg=error_msg)

        name = self.ui.txt_name.get_text().strip()
        if len(name) == 0:
            # Show error for missing group name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The group name is missing'))
        elif '\'' in name or '\\' in name or '/' in name or ',' in name:
            # Show error for invalid group name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The Group name is invalid'))
        elif self.model.get_iter(name):
            # Show error for existing group name
            show_error_message_on_infobar(
                self.ui.txt_name, _('A group with that name already exists'))
        else:
            self.ui.dialog_edit_group.response(Gtk.ResponseType.OK)
Exemple #9
0
 def on_action_add_activate(self, action):
     """Add a new group"""
     dialog = UIGroupDetail(self.ui.dialog_groups, self.model)
     if dialog.show(default_name='',
                    title=_('Add new group'),
                    treeiter=None) == Gtk.ResponseType.OK:
         os.mkdir(os.path.join(DIR_HOSTS, dialog.name))
         self.model.add_data(GroupInfo(name=dialog.name,
                                       description=dialog.name))
         debug.add_info(_('Added a new group "%s"') % dialog.name)
     dialog.destroy()
Exemple #10
0
 def on_action_add_activate(self, action):
     """Add a new group"""
     dialog = UIGroupDetail(self.ui.dialog_groups, self.model)
     if dialog.show(default_name='',
                    title=_('Add new group'),
                    treeiter=None) == Gtk.ResponseType.OK:
         os.mkdir(os.path.join(DIR_HOSTS, dialog.name))
         self.model.add_data(
             GroupInfo(name=dialog.name, description=dialog.name))
         debug.add_info(_('Added a new group "%s"') % dialog.name)
     dialog.destroy()
 def on_action_remove_activate(self, action):
     """Remove the selected service"""
     selected_row = get_treeview_selected_row(self.ui.tvw_arguments)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_arguments,
             message_type=Gtk.MessageType.WARNING,
             title=None,
             msg1=_("Remove argument"),
             msg2=_("Remove the selected argument?"),
             is_response_id=Gtk.ResponseType.YES):
         self.model_arguments.remove(selected_row)
Exemple #12
0
 def on_action_associations_remove_activate(self, action):
     """Remove the selected destination"""
     selected_row = get_treeview_selected_row(self.ui.tvw_associations)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_host,
             message_type=Gtk.MessageType.QUESTION,
             title=None,
             msg1=_("Remove association"),
             msg2=_("Remove the selected association?"),
             is_response_id=Gtk.ResponseType.YES):
         self.model_associations.remove(selected_row)
Exemple #13
0
 def on_action_associations_remove_activate(self, action):
     """Remove the selected destination"""
     selected_row = get_treeview_selected_row(self.ui.tvw_associations)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_host,
             message_type=Gtk.MessageType.QUESTION,
             title=None,
             msg1=_("Remove association"),
             msg2=_("Remove the selected association?"),
             is_response_id=Gtk.ResponseType.YES):
         self.model_associations.remove(selected_row)
Exemple #14
0
 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)
Exemple #15
0
 def on_action_delete_activate(self, action):
     """Remove the selected host"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.win_main,
             message_type=Gtk.MessageType.QUESTION,
             title=None,
             msg1=_("Remove host"),
             msg2=_("Remove the selected host?"),
             is_response_id=Gtk.ResponseType.YES):
         self.remove_host(self.model_hosts.get_key(selected_row))
Exemple #16
0
 def on_action_connect_activate(self, action):
     """Establish the connection for the destination"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row and not self.is_selected_row_host():
         host = self.hosts[self.model_hosts.get_key(
             self.ui.store_hosts.iter_parent(selected_row))]
         destination_name = self.model_hosts.get_key(selected_row)
         destination = host.destinations[destination_name]
         description = self.model_hosts.get_association(selected_row)
         service_name = self.model_hosts.get_service(selected_row)
         service_arguments = self.model_hosts.get_arguments(selected_row)
         arguments = json.loads(service_arguments)
         association = host.find_association(description=description,
                                             destination=destination.name,
                                             service=service_name,
                                             arguments=arguments)
         if service_name in model_services.services:
             service = model_services.services[service_name]
             command = service.command
             # Prepares the arguments
             arguments_map = {}
             arguments_map['address'] = destination.value
             for key in association.service_arguments:
                 arguments_map[key] = association.service_arguments[key]
             # Execute command
             try:
                 command = command.format(**arguments_map)
                 processes.processes.add_process(host, destination, service,
                                                 command)
             except KeyError as error:
                 # An error occurred processing the command
                 error_msg1 = _('Connection open failed')
                 error_msg2 = _('An error occurred processing the '
                                'service command.')
                 show_message_dialog(class_=UIMessageDialogClose,
                                     parent=self.ui.win_main,
                                     message_type=Gtk.MessageType.ERROR,
                                     title=None,
                                     msg1=error_msg1,
                                     msg2=error_msg2,
                                     is_response_id=None)
                 debug.add_error(error_msg2)
                 debug.add_error('Host: "%s"' % host.name)
                 debug.add_error('Destination name: "%s"' %
                                 destination.name)
                 debug.add_error('Destination value: "%s"' %
                                 destination.value)
                 debug.add_error('Service: %s' % service.name),
                 debug.add_error('Command: "%s"' % command)
         else:
             debug.add_warning('service %s not found' % service_name)
Exemple #17
0
 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()
Exemple #18
0
 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()
Exemple #19
0
 def on_action_new_activate(self, action):
     """Define a new host"""
     dialog = UIHost(parent=self.ui.win_main, hosts=self.model_hosts)
     response = dialog.show(default_name='',
                            default_description='',
                            title=_('Add a new host'),
                            treeiter=None)
     if response == Gtk.ResponseType.OK:
         destinations = dialog.model_destinations.dump()
         associations = dialog.model_associations.dump()
         host = HostInfo(dialog.name, dialog.description)
         # Set the associations
         for values in associations:
             (destination_name, description, service_name,
              service_arguments) = associations[values]
             destination = destinations[destination_name]
             arguments = json.loads(service_arguments)
             host.add_association(description=description,
                                  destination_name=destination_name,
                                  service_name=service_name,
                                  arguments=arguments)
         self.add_host(host=host,
                       destinations=destinations,
                       update_settings=True)
         # Automatically select the newly added host
         self.ui.tvw_connections.set_cursor(
             path=self.model_hosts.get_path_by_name(dialog.name),
             column=None,
             start_editing=False)
     dialog.destroy()
Exemple #20
0
 def reload_groups(self):
     """Load groups from hosts folder"""
     self.model_groups.clear()
     # Always add a default group
     self.model_groups.add_data(GroupInfo('', _('Default group')))
     for filename in os.listdir(DIR_HOSTS):
         if os.path.isdir(os.path.join(DIR_HOSTS, filename)):
             # For each folder add a new group
             self.model_groups.add_data(GroupInfo(filename, filename))
Exemple #21
0
 def on_action_destinations_add_activate(self, action):
     """Add a new destination"""
     dialog = UIDestination(self.ui.dialog_host, self.model_destinations)
     if dialog.show(default_name='',
                    default_value='',
                    title=_('Add new destination'),
                    treeiter=None) == Gtk.ResponseType.OK:
         self.model_destinations.add_data(
             DestinationInfo(name=dialog.name, value=dialog.value))
     # Get the new destinations list, clear and store the list again
     dialog.destroy()
Exemple #22
0
 def on_action_destinations_add_activate(self, action):
     """Add a new destination"""
     dialog = UIDestination(self.ui.dialog_host, self.model_destinations)
     if dialog.show(default_name='',
                    default_value='',
                    title=_('Add new destination'),
                    treeiter=None) == Gtk.ResponseType.OK:
         self.model_destinations.add_data(
             DestinationInfo(name=dialog.name, value=dialog.value))
     # Get the new destinations list, clear and store the list again
     dialog.destroy()
 def on_action_confirm_activate(self, action):
     """Check che service configuration before confirm"""
     def show_error_message_on_infobar(widget, error_msg):
         """Show the error message on the GtkInfoBar"""
         set_error_message_on_infobar(
             widget=widget,
             widgets=(self.ui.txt_name, self.ui.txt_description,
                      self.ui.txt_command),
             label=self.ui.lbl_error_message,
             infobar=self.ui.infobar_error_message,
             error_msg=error_msg)
     name = self.ui.txt_name.get_text().strip()
     description = self.ui.txt_description.get_text().strip()
     command = self.ui.txt_command.get_text().strip()
     terminal = self.ui.chk_terminal.get_active()
     icon = self.ui.txt_icon.get_text().strip()
     if len(name) == 0:
         # Show error for missing service name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The service name is missing'))
     elif '\'' in name or '\\' in name or '/' in name or ',' in name:
         # Show error for invalid service name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('The service name is invalid'))
     elif self.model.get_iter(name) not in (None, self.selected_iter):
         # Show error for existing service name
         show_error_message_on_infobar(
             self.ui.txt_name,
             _('A service with that name already exists'))
     elif len(description) == 0:
         # Show error for missing service description
         show_error_message_on_infobar(
             self.ui.txt_description,
             _('The service description is missing'))
     elif '\'' in description or '\\' in description:
         # Show error for invalid service description
         show_error_message_on_infobar(
             self.ui.txt_description,
             _('The service description is invalid'))
     elif len(command) == 0:
         # Show error for missing service description
         show_error_message_on_infobar(
             self.ui.txt_command,
             _('The service command is missing'))
     elif len(icon) > 0 and not os.path.isfile(icon):
         # Show error for missing service description
         show_error_message_on_infobar(
             self.ui.txt_icon,
             _('The service icon doesn''t exists'))
     else:
         self.ui.dialog_edit_service.response(Gtk.ResponseType.OK)
 def add_process(self, host, destination, service, command):
     """Add a new process"""
     process = subprocess.Popen(args=get_list_from_string_list(command),
                                shell=False)
     treeiter = self.model.add_data(ProcessInfo(host,
                                                destination,
                                                service,
                                                process))
     # Enable process actions
     self.ui.actions_processes.set_sensitive(True)
     # Save process for further polling
     self.processes[self.model.get_key(treeiter)] = process
     self.model.add_detail(treeiter,
                           _('Process started'),
                           'media-playback-start')
     self.start_polling()
Exemple #25
0
 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()
Exemple #26
0
    def on_action_confirm_activate(self, action):
        """Check che argument before confirm"""
        def show_error_message_on_infobar(widget, error_msg):
            """Show the error message on the GtkInfoBar"""
            set_error_message_on_infobar(widget=widget,
                                         widgets=(self.ui.txt_argument, ),
                                         label=self.ui.lbl_error_message,
                                         infobar=self.ui.infobar_error_message,
                                         error_msg=error_msg)

        if len(self.ui.txt_argument.get_text().strip()) == 0:
            # Show error for missing argument
            show_error_message_on_infobar(self.ui.txt_argument,
                                          _('The argument is missing'))
        else:
            self.ui.dialog_argument.response(Gtk.ResponseType.OK)
    def on_action_confirm_activate(self, action):
        """Check che service configuration before confirm"""
        def show_error_message_on_infobar(widget, error_msg):
            """Show the error message on the GtkInfoBar"""
            set_error_message_on_infobar(widget=widget,
                                         widgets=(self.ui.txt_name,
                                                  self.ui.txt_description,
                                                  self.ui.txt_command),
                                         label=self.ui.lbl_error_message,
                                         infobar=self.ui.infobar_error_message,
                                         error_msg=error_msg)

        name = self.ui.txt_name.get_text().strip()
        description = self.ui.txt_description.get_text().strip()
        command = self.ui.txt_command.get_text().strip()
        terminal = self.ui.chk_terminal.get_active()
        icon = self.ui.txt_icon.get_text().strip()
        if len(name) == 0:
            # Show error for missing service name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The service name is missing'))
        elif '\'' in name or '\\' in name or '/' in name or ',' in name:
            # Show error for invalid service name
            show_error_message_on_infobar(self.ui.txt_name,
                                          _('The service name is invalid'))
        elif self.model.get_iter(name) not in (None, self.selected_iter):
            # Show error for existing service name
            show_error_message_on_infobar(
                self.ui.txt_name, _('A service with that name already exists'))
        elif len(description) == 0:
            # Show error for missing service description
            show_error_message_on_infobar(
                self.ui.txt_description,
                _('The service description is missing'))
        elif '\'' in description or '\\' in description:
            # Show error for invalid service description
            show_error_message_on_infobar(
                self.ui.txt_description,
                _('The service description is invalid'))
        elif len(command) == 0:
            # Show error for missing service description
            show_error_message_on_infobar(self.ui.txt_command,
                                          _('The service command is missing'))
        elif len(icon) > 0 and not os.path.isfile(icon):
            # Show error for missing service description
            show_error_message_on_infobar(
                self.ui.txt_icon, _('The service icon doesn'
                                    't exists'))
        else:
            self.ui.dialog_edit_service.response(Gtk.ResponseType.OK)
 def on_action_confirm_activate(self, action):
     """Check che argument before confirm"""
     def show_error_message_on_infobar(widget, error_msg):
         """Show the error message on the GtkInfoBar"""
         set_error_message_on_infobar(
             widget=widget,
             widgets=(self.ui.txt_argument, ),
             label=self.ui.lbl_error_message,
             infobar=self.ui.infobar_error_message,
             error_msg=error_msg)
     if len(self.ui.txt_argument.get_text().strip()) == 0:
         # Show error for missing argument
         show_error_message_on_infobar(
             self.ui.txt_argument,
             _('The argument is missing'))
     else:
         self.ui.dialog_argument.response(Gtk.ResponseType.OK)
Exemple #29
0
 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()
Exemple #30
0
 def on_action_destinations_edit_activate(self, action):
     """Edit the selected destination"""
     selected_row = get_treeview_selected_row(self.ui.tvw_destinations)
     if selected_row:
         name = self.model_destinations.get_key(selected_row)
         value = self.model_destinations.get_value(selected_row)
         selected_iter = self.model_destinations.get_iter(name)
         dialog = UIDestination(self.ui.dialog_host,
                                self.model_destinations)
         if dialog.show(default_name=name,
                        default_value=value,
                        title=_('Edit destination'),
                        treeiter=selected_iter) == Gtk.ResponseType.OK:
             # Update values
             self.model_destinations.set_data(
                 selected_iter,
                 DestinationInfo(name=dialog.name, value=dialog.value))
         dialog.destroy()
Exemple #31
0
 def on_action_destinations_edit_activate(self, action):
     """Edit the selected destination"""
     selected_row = get_treeview_selected_row(self.ui.tvw_destinations)
     if selected_row:
         name = self.model_destinations.get_key(selected_row)
         value = self.model_destinations.get_value(selected_row)
         selected_iter = self.model_destinations.get_iter(name)
         dialog = UIDestination(self.ui.dialog_host,
                                self.model_destinations)
         if dialog.show(default_name=name,
                        default_value=value,
                        title=_('Edit destination'),
                        treeiter=selected_iter
                        ) == Gtk.ResponseType.OK:
             # Update values
             self.model_destinations.set_data(
                 selected_iter, DestinationInfo(name=dialog.name,
                                                value=dialog.value))
         dialog.destroy()
 def poll_processes(self):
     """Poll each process to check if it was terminated"""
     for key in self.processes.keys():
         process = self.processes[key]
         return_code = process.poll()
         # Has the process exited?
         if return_code is not None:
             treeiter = self.model.get_iter(key)
             self.model.add_detail(treeiter,
                                   _('Exit code: %d') % return_code,
                                   'media-playback-stop')
             # Remove the completed process
             self.processes.pop(key)
     if len(self.processes):
         # Continue the polling
         return True
     else:
         # Stop the polling
         self.poller_id = None
         return False
Exemple #33
0
 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)
Exemple #34
0
 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 on_action_process_activate(self, action):
     """Execute an action for the selected process"""
     selected_row = get_treeview_selected_row(self.ui.tvw_processes)
     if selected_row:
         iter_parent = self.model.model.iter_parent(selected_row)
         selected_path = self.model.model[selected_row].path
         # Get the path of the process
         if iter_parent is None:
             tree_path = self.model.model[selected_row].path
         else:
             tree_path = self.model.model[iter_parent].path
         #
         selected_key = self.model.get_key(tree_path)
         if selected_key in self.processes:
             selected_process = self.processes[selected_key]
             treeiter = self.model.get_iter(selected_key)
             if action is self.ui.action_kill:
                 # Resume the process and terminate it
                 selected_process.send_signal(subprocess.signal.SIGCONT)
                 selected_process.terminate()
                 debug.add_info(
                     _('The process with the PID %d was terminated') % (
                         selected_process.pid))
                 self.model.add_detail(treeiter,
                                       _('Process terminated'),
                                       'media-playback-stop')
             elif action is self.ui.action_pause:
                 # Pause the process by sending the STOP signal
                 selected_process.send_signal(subprocess.signal.SIGSTOP)
                 debug.add_info(
                     _('The process with the PID %d was paused') % (
                         selected_process.pid))
                 self.model.add_detail(treeiter,
                                       _('Process paused'),
                                       'media-playback-pause')
             elif action is self.ui.action_resume:
                 # Pause the process by sending the CONT signal
                 selected_process.send_signal(subprocess.signal.SIGCONT)
                 debug.add_info(
                     _('The process with the PID %d was resumed') % (
                         selected_process.pid))
                 self.model.add_detail(treeiter,
                                       _('Process resumed'),
                                       'media-playback-start')
Exemple #36
0
 def on_action_remove_activate(self, action):
     """Remove the selected group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     group_name = self.model.get_key(selected_row) if selected_row else ''
     if selected_row and group_name and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_groups,
             message_type=Gtk.MessageType.WARNING,
             title=None,
             msg1=_('Remove the group'),
             msg2=_('Remove the group «%s»?') % group_name,
             is_response_id=Gtk.ResponseType.YES):
         group_path = os.path.join(DIR_HOSTS, group_name)
         # Check for directory not empty
         if len(os.listdir(group_path)) and not show_message_dialog(
                 class_=UIMessageDialogNoYes,
                 parent=self.ui.dialog_groups,
                 message_type=Gtk.MessageType.WARNING,
                 title=None,
                 msg1=_('The group is not empty'),
                 msg2='%s\n%s\n\n%s' % (
                     text('If you delete an item, it will '
                          'be permanently lost.'),
                     _('All the hosts defined for the group will be lost.'),
                     _('Are you sure you want to delete the '
                       'group «%s»?') % group_name,
                                    ),
                 is_response_id=Gtk.ResponseType.YES):
             # Exit immediately without deleting the group
             return
         # Delete all the contained files and the directory for the group
         for filename in os.listdir(group_path):
             os.remove(os.path.join(group_path, filename))
         os.rmdir(group_path)
         debug.add_info(_('Removed the group "%s"') % group_name)
         self.model.remove(selected_row)
Exemple #37
0
 def on_action_remove_activate(self, action):
     """Remove the selected group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     group_name = self.model.get_key(selected_row) if selected_row else ''
     if selected_row and group_name and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_groups,
             message_type=Gtk.MessageType.WARNING,
             title=None,
             msg1=_('Remove the group'),
             msg2=_('Remove the group «%s»?') % group_name,
             is_response_id=Gtk.ResponseType.YES):
         group_path = os.path.join(DIR_HOSTS, group_name)
         # Check for directory not empty
         if len(os.listdir(group_path)) and not show_message_dialog(
                 class_=UIMessageDialogNoYes,
                 parent=self.ui.dialog_groups,
                 message_type=Gtk.MessageType.WARNING,
                 title=None,
                 msg1=_('The group is not empty'),
                 msg2='%s\n%s\n\n%s' % (
                     text('If you delete an item, it will '
                          'be permanently lost.'),
                     _('All the hosts defined for the group will be lost.'),
                     _('Are you sure you want to delete the '
                       'group «%s»?') % group_name,
                 ),
                 is_response_id=Gtk.ResponseType.YES):
             # Exit immediately without deleting the group
             return
         # Delete all the contained files and the directory for the group
         for filename in os.listdir(group_path):
             os.remove(os.path.join(group_path, filename))
         os.rmdir(group_path)
         debug.add_info(_('Removed the group "%s"') % group_name)
         self.model.remove(selected_row)
Exemple #38
0
 def on_action_copy_activate(self, action):
     """Copy the selected host to another"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         if self.is_selected_row_host():
             # First level (host)
             name = self.model_hosts.get_key(selected_row)
             description = self.model_hosts.get_description(selected_row)
             selected_iter = self.model_hosts.get_iter(name)
             expanded = self.ui.tvw_connections.row_expanded(
                 self.model_hosts.get_path(selected_iter))
             dialog = UIHost(parent=self.ui.win_main,
                             hosts=self.model_hosts)
             # Restore the destinations for the selected host
             destinations = self.hosts[name].destinations
             for destination_name in destinations:
                 destination = destinations[destination_name]
                 dialog.model_destinations.add_data(destination)
             # Restore the associations for the selected host
             for association in self.hosts[name].associations:
                 service_name = association.service_name
                 if service_name in model_services.services:
                     dialog.model_associations.add_data(
                         index=dialog.model_associations.count(),
                         name=association.destination_name,
                         description=association.description,
                         service=model_services.services[service_name],
                         arguments=association.service_arguments)
                 else:
                     debug.add_warning('service %s not found' %
                                       service_name)
             # Show the edit host dialog
             response = dialog.show(default_name=_('Copy of %s') % name,
                                    default_description='',
                                    title=_('Copy host'),
                                    treeiter=None)
             if response == Gtk.ResponseType.OK:
                 destinations = dialog.model_destinations.dump()
                 associations = dialog.model_associations.dump()
                 host = HostInfo(dialog.name, dialog.description)
                 # Set the associations
                 for values in associations:
                     (destination_name, description, service_name,
                      service_arguments) = associations[values]
                     destination = destinations[destination_name]
                     arguments = json.loads(service_arguments)
                     host.add_association(description=description,
                                          destination_name=destination_name,
                                          service_name=service_name,
                                          arguments=arguments)
                 self.add_host(host=host,
                               destinations=destinations,
                               update_settings=True)
                 # Get the path of the host
                 tree_path = self.model_hosts.get_path_by_name(dialog.name)
                 # Automatically select again the previously selected host
                 self.ui.tvw_connections.set_cursor(path=tree_path,
                                                    column=None,
                                                    start_editing=False)
                 # Automatically expand the row if it was expanded before
                 if expanded:
                     self.ui.tvw_connections.expand_row(tree_path, False)
                     # Collapse the duplicated row
                     self.ui.tvw_connections.collapse_row(
                         self.model_hosts.get_path(selected_iter))
Exemple #39
0
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
##

import gettext
import locale

import gcentralaccess.requires

from gcentralaccess.functions import store_message, text, _
from gcentralaccess.constants import DOMAIN_NAME, DIR_LOCALE

# Load domain for translation
for module in (gettext, locale):
    module.bindtextdomain(DOMAIN_NAME, DIR_LOCALE)
    module.textdomain(DOMAIN_NAME)

# Import some translated messages from GTK+ domain
store_message('_Icon:', '_%s:' % text(message='Icon', gtk30=True))
for message in ('_OK', '_Cancel', '_Close', '_Open', '_Save', '_Connect',
                '_Copy', '_Delete', 'Select a File', 'Services', 'Name',
                'Value', '_Name:', '_Value:',
                'If you delete an item, it will be permanently lost.'):
    text(message=message, gtk30=True)
# With domain context
for message in ('_Add', '_Remove', '_Edit', '_New', '_Quit', '_About'):
    text(message=message, gtk30=True, context='Stock label')
# Remove the underscore
for message in ('_Add', '_Remove', '_Edit', '_New', '_Connect', '_Delete'):
    store_message(message.replace('_', ''), _(message).replace('_', ''))
Exemple #40
0
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
##

import gettext
import locale

import gcentralaccess.requires

from gcentralaccess.functions import store_message, text, _
from gcentralaccess.constants import DOMAIN_NAME, DIR_LOCALE

# Load domain for translation
for module in (gettext, locale):
    module.bindtextdomain(DOMAIN_NAME, DIR_LOCALE)
    module.textdomain(DOMAIN_NAME)

# Import some translated messages from GTK+ domain
store_message('_Icon:', '_%s:' % text(message='Icon', gtk30=True))
for message in ('_OK', '_Cancel', '_Close', '_Open', '_Save', '_Connect',
                '_Copy', '_Delete', 'Select a File', 'Services',
                'Name', 'Value', '_Name:', '_Value:',
                'If you delete an item, it will be permanently lost.'):
    text(message=message, gtk30=True)
# With domain context
for message in ('_Add', '_Remove', '_Edit', '_New', '_Quit', '_About'):
    text(message=message, gtk30=True, context='Stock label')
# Remove the underscore
for message in ('_Add', '_Remove', '_Edit', '_New', '_Connect', '_Delete'):
    store_message(message.replace('_', ''), _(message).replace('_', ''))