Esempio n. 1
0
 def on_action_devices_activate(self, action):
     """Edit devices"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         iter_parent = self.ui.store_hosts.iter_parent(selected_row)
         selected_path = self.model_hosts.model[selected_row].path
         # Get the path of the host
         if iter_parent is None:
             tree_path = self.model_hosts.model[selected_row].path
         else:
             tree_path = self.model_hosts.model[iter_parent].path
     dialog_devices = UIDevices(parent=self.ui.win_main)
     # Load devices list
     dialog_devices.model.load(model_devices.devices)
     dialog_devices.show()
     # Get the new devices list, clear and store the list again
     model_devices.devices = dialog_devices.model.dump()
     dialog_devices.destroy()
     settings.devices.clear()
     for key in model_devices.devices.iterkeys():
         settings.devices.set(section=key,
                              option=OPTION_DEVICE_DESCRIPTION,
                              value=model_devices.devices[key].description)
         settings.devices.set(section=key,
                              option=OPTION_DEVICE_SERVICES,
                              value=','.join(
                                  model_devices.devices[key].services))
     self.reload_hosts()
     if selected_row:
         # Automatically select again the previously selected row
         self.ui.tvw_connections.set_cursor(path=selected_path,
                                            column=None,
                                            start_editing=False)
Esempio n. 2
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)
         self.model.remove(selected_row)
Esempio n. 3
0
 def on_action_copy_activate(self, action):
     """Copy the selected host to another"""
     row = get_treeview_selected_row(self.ui.tvw_connections)
     if row:
         model = self.model_hosts
         name = self.model_hosts.get_key(row)
         description = self.model_hosts.get_description(row)
         selected_iter = self.model_hosts.get_iter(name)
         dialog = UIHost(parent=self.ui.win_main, hosts=self.model_hosts)
         # Show the edit host dialog
         response = dialog.show(name=_('Copy of %s') % name,
                                description=description,
                                title=_('Copy host'),
                                protocol=model.get_protocol(row),
                                address=model.get_address(row),
                                port_number=model.get_port_number(row),
                                version=model.get_version(row),
                                community=model.get_community(row),
                                device=model.get_device(row),
                                treeiter=None)
         if response == Gtk.ResponseType.OK:
             host = HostInfo(dialog.name, dialog.description,
                             dialog.protocol, dialog.address,
                             dialog.port_number, dialog.version,
                             dialog.community, dialog.device)
             self.add_host(host=host, 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)
         dialog.destroy()
Esempio n. 4
0
 def on_action_edit_activate(self, action):
     """Define a new host"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         dialog = UIHost(parent=self.ui.win_main, hosts=self.model_hosts)
         # Show the edit host dialog
         model = self.model_hosts
         name = model.get_key(selected_row)
         selected_iter = model.get_iter(name)
         response = dialog.show(
             name=name,
             description=model.get_description(selected_row),
             protocol=model.get_protocol(selected_row),
             address=model.get_address(selected_row),
             port_number=model.get_port_number(selected_row),
             version=model.get_version(selected_row),
             community=model.get_community(selected_row),
             device=model.get_device(selected_row),
             title=_('Edit host'),
             treeiter=selected_iter)
         if response == Gtk.ResponseType.OK:
             # Remove older host and add the newer
             host = HostInfo(dialog.name, dialog.description,
                             dialog.protocol, dialog.address,
                             dialog.port_number, dialog.version,
                             dialog.community, dialog.device)
             self.remove_host(name)
             self.add_host(host=host, 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)
         dialog.destroy()
Esempio n. 5
0
 def on_action_copy_activate(self, action):
     """Copy the selected host to another"""
     row = get_treeview_selected_row(self.ui.tvw_connections)
     if row:
         model = self.model_hosts
         name = self.model_hosts.get_key(row)
         description = self.model_hosts.get_description(row)
         selected_iter = self.model_hosts.get_iter(name)
         dialog = UIHost(parent=self.ui.win_main,
                         hosts=self.model_hosts)
         # Show the edit host dialog
         response = dialog.show(name=_('Copy of %s') % name,
                                description=description,
                                title=_('Copy host'),
                                protocol=model.get_protocol(row),
                                address=model.get_address(row),
                                port_number=model.get_port_number(row),
                                version=model.get_version(row),
                                community=model.get_community(row),
                                device=model.get_device(row),
                                treeiter=None)
         if response == Gtk.ResponseType.OK:
             host = HostInfo(dialog.name, dialog.description,
                             dialog.protocol, dialog.address,
                             dialog.port_number, dialog.version,
                             dialog.community, dialog.device)
             self.add_host(host=host,
                           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)
         dialog.destroy()
Esempio n. 6
0
 def on_action_devices_activate(self, action):
     """Edit devices"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         iter_parent = self.ui.store_hosts.iter_parent(selected_row)
         selected_path = self.model_hosts.model[selected_row].path
         # Get the path of the host
         if iter_parent is None:
             tree_path = self.model_hosts.model[selected_row].path
         else:
             tree_path = self.model_hosts.model[iter_parent].path
     dialog_devices = UIDevices(parent=self.ui.win_main)
     # Load devices list
     dialog_devices.model.load(model_devices.devices)
     dialog_devices.show()
     # Get the new devices list, clear and store the list again
     model_devices.devices = dialog_devices.model.dump()
     dialog_devices.destroy()
     settings.devices.clear()
     for key in model_devices.devices.iterkeys():
         settings.devices.set(
             section=key,
             option=OPTION_DEVICE_DESCRIPTION,
             value=model_devices.devices[key].description)
         settings.devices.set(
             section=key,
             option=OPTION_DEVICE_SERVICES,
             value=','.join(model_devices.devices[key].services))
     self.reload_hosts()
     if selected_row:
         # Automatically select again the previously selected row
         self.ui.tvw_connections.set_cursor(path=selected_path,
                                            column=None,
                                            start_editing=False)
Esempio n. 7
0
 def on_action_group_next_activate(self, action):
     """Move to the next group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     new_iter = self.model_groups.model.iter_next(selected_row)
     if new_iter:
         # Select the newly selected row in the groups list
         new_path = self.model_groups.get_path(new_iter)
         self.ui.tvw_groups.set_cursor(new_path)
Esempio n. 8
0
 def on_action_group_next_activate(self, action):
     """Move to the next group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     new_iter = self.model_groups.model.iter_next(selected_row)
     if new_iter:
         # Select the newly selected row in the groups list
         new_path = self.model_groups.get_path(new_iter)
         self.ui.tvw_groups.set_cursor(new_path)
Esempio n. 9
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))
Esempio n. 10
0
 def on_action_remove_activate(self, action):
     """Remove the selected devices"""
     selected_row = get_treeview_selected_row(self.ui.tvw_devices)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_devices,
             message_type=Gtk.MessageType.WARNING,
             title=None,
             msg1=_("Remove device"),
             msg2=_("Remove the selected device?"),
             is_response_id=Gtk.ResponseType.YES):
         self.model.remove(selected_row)
Esempio n. 11
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))
Esempio n. 12
0
 def on_action_remove_activate(self, action):
     """Remove the selected devices"""
     selected_row = get_treeview_selected_row(self.ui.tvw_devices)
     if selected_row and show_message_dialog(
             class_=UIMessageDialogNoYes,
             parent=self.ui.dialog_devices,
             message_type=Gtk.MessageType.WARNING,
             title=None,
             msg1=_("Remove device"),
             msg2=_("Remove the selected device?"),
             is_response_id=Gtk.ResponseType.YES):
         self.model.remove(selected_row)
Esempio n. 13
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:
         model = self.model_hosts
         dialog = UISNMPValues(
             parent=self.ui.win_main,
             host=HostInfo(name=model.get_key(selected_row),
                           description=model.get_description(selected_row),
                           protocol=model.get_protocol(selected_row),
                           address=model.get_address(selected_row),
                           port_number=model.get_port_number(selected_row),
                           version=model.get_version(selected_row),
                           community=model.get_community(selected_row),
                           device=model.get_device(selected_row)))
         dialog.show()
Esempio n. 14
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:
         model = self.model_hosts
         dialog = UISNMPValues(
             parent=self.ui.win_main,
             host=HostInfo(name=model.get_key(selected_row),
                           description=model.get_description(selected_row),
                           protocol=model.get_protocol(selected_row),
                           address=model.get_address(selected_row),
                           port_number=model.get_port_number(selected_row),
                           version=model.get_version(selected_row),
                           community=model.get_community(selected_row),
                           device=model.get_device(selected_row))
         )
         dialog.show()
Esempio n. 15
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)
         selected_iter = self.model.get_iter(name)
         dialog = UIServiceDetail(self.ui.dialog_services, self.model)
         if dialog.show(name=name,
                        description=description,
                        title=_('Edit service'),
                        treeiter=selected_iter) == Gtk.ResponseType.OK:
             # Update values
             self.model.set_data(
                 selected_iter,
                 ServiceInfo(name=dialog.name,
                             description=dialog.description))
         dialog.destroy()
Esempio n. 16
0
 def on_action_edit_activate(self, action):
     """Edit the selected device"""
     selected_row = get_treeview_selected_row(self.ui.tvw_devices)
     if selected_row:
         name = self.model.get_key(selected_row)
         description = self.model.get_description(selected_row)
         services = self.model.get_services(selected_row)
         selected_iter = self.model.get_iter(name)
         dialog = UIDeviceDetail(self.ui.dialog_devices, self.model)
         if dialog.show(name=name,
                        description=description,
                        services=services,
                        title=_('Edit device type'),
                        treeiter=selected_iter
                        ) == Gtk.ResponseType.OK:
             # Update values
             self.model.set_data(selected_iter, DeviceInfo(
                 name=dialog.name,
                 description=dialog.description,
                 services=dialog.services))
         dialog.destroy()
Esempio n. 17
0
 def on_action_edit_activate(self, action):
     """Define a new host"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         dialog = UIHost(parent=self.ui.win_main,
                         hosts=self.model_hosts)
         # Show the edit host dialog
         model = self.model_hosts
         name = model.get_key(selected_row)
         selected_iter = model.get_iter(name)
         response = dialog.show(
             name=name,
             description=model.get_description(selected_row),
             protocol=model.get_protocol(selected_row),
             address=model.get_address(selected_row),
             port_number=model.get_port_number(selected_row),
             version=model.get_version(selected_row),
             community=model.get_community(selected_row),
             device=model.get_device(selected_row),
             title=_('Edit host'),
             treeiter=selected_iter)
         if response == Gtk.ResponseType.OK:
             # Remove older host and add the newer
             host = HostInfo(dialog.name, dialog.description,
                             dialog.protocol, dialog.address,
                             dialog.port_number, dialog.version,
                             dialog.community, dialog.device)
             self.remove_host(name)
             self.add_host(host=host,
                           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)
         dialog.destroy()
Esempio n. 18
0
 def on_tvw_connections_row_activated(self, widget, treepath, column):
     """Edit the selected row on activation"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         # Start host connection
         self.ui.action_connect.activate()
Esempio n. 19
0
 def on_tvw_groups_cursor_changed(self, widget):
     """Set actions sensitiveness for host and connection"""
     if get_treeview_selected_row(self.ui.tvw_groups):
         self.reload_hosts()
         # Automatically select the first host for the group
         self.ui.tvw_connections.set_cursor(0)
Esempio n. 20
0
 def get_current_group_path(self):
     """Return the path of the currently selected group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     group_name = self.model_groups.get_key(selected_row) if selected_row \
         else ''
     return os.path.join(DIR_HOSTS, group_name) if group_name else DIR_HOSTS
Esempio n. 21
0
 def on_tvw_connections_cursor_changed(self, widget):
     """Set actions sensitiveness for host and connection"""
     if get_treeview_selected_row(self.ui.tvw_connections):
         self.ui.actions_connection.set_sensitive(True)
         self.ui.actions_host.set_sensitive(True)
Esempio n. 22
0
 def on_tvw_connections_cursor_changed(self, widget):
     """Set actions sensitiveness for host and connection"""
     if get_treeview_selected_row(self.ui.tvw_connections):
         self.ui.actions_connection.set_sensitive(True)
         self.ui.actions_host.set_sensitive(True)
Esempio n. 23
0
 def on_tvw_connections_row_activated(self, widget, treepath, column):
     """Edit the selected row on activation"""
     selected_row = get_treeview_selected_row(self.ui.tvw_connections)
     if selected_row:
         # Start host connection
         self.ui.action_connect.activate()
Esempio n. 24
0
 def get_current_group_path(self):
     """Return the path of the currently selected group"""
     selected_row = get_treeview_selected_row(self.ui.tvw_groups)
     group_name = self.model_groups.get_key(selected_row) if selected_row \
         else ''
     return os.path.join(DIR_HOSTS, group_name) if group_name else DIR_HOSTS
Esempio n. 25
0
 def on_tvw_groups_cursor_changed(self, widget):
     """Set actions sensitiveness for host and connection"""
     if get_treeview_selected_row(self.ui.tvw_groups):
         self.reload_hosts()
         # Automatically select the first host for the group
         self.ui.tvw_connections.set_cursor(0)