예제 #1
0
파일: main.py 프로젝트: muflone/glivesnmp
 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()
예제 #2
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)
예제 #3
0
파일: main.py 프로젝트: muflone/glivesnmp
 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()
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
0
파일: main.py 프로젝트: muflone/glivesnmp
 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))
예제 #8
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)
예제 #9
0
파일: main.py 프로젝트: muflone/glivesnmp
 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))
예제 #10
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(name='',
                            description='',
                            protocol='UDP',
                            address='',
                            port_number=161,
                            version=1,
                            community='public',
                            device='',
                            requests=0,
                            title=_('Add a new host'),
                            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, dialog.requests)
         self.add_host(host=host, 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()
예제 #11
0
파일: main.py 프로젝트: muflone/glivesnmp
 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()
예제 #12
0
파일: main.py 프로젝트: muflone/glivesnmp
 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(name='',
                            description='',
                            protocol='UDP',
                            address='',
                            port_number=161,
                            version=1,
                            community='public',
                            device='',
                            title=_('Add a new host'),
                            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)
         # 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()
예제 #13
0
파일: main.py 프로젝트: muflone/glivesnmp
 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))
예제 #14
0
파일: main.py 프로젝트: muflone/glivesnmp
 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))
예제 #15
0
 def on_action_add_activate(self, action):
     """Add a new service"""
     dialog = UIServiceDetail(self.ui.dialog_services, self.model)
     if dialog.show(name='',
                    description='',
                    title=_('Add new service'),
                    treeiter=None) == Gtk.ResponseType.OK:
         self.model.add_data(
             ServiceInfo(name=dialog.name, description=dialog.description))
     dialog.destroy()
예제 #16
0
 def on_action_add_activate(self, action):
     """Add a new group"""
     dialog = UIGroupDetail(self.ui.dialog_groups, self.model)
     if dialog.show(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))
     dialog.destroy()
예제 #17
0
 def on_action_add_activate(self, action):
     """Add a new device"""
     dialog = UIDeviceDetail(self.ui.dialog_devices, self.model)
     if dialog.show(name='',
                    description='',
                    services=[],
                    title=_('Add new device type'),
                    treeiter=None) == Gtk.ResponseType.OK:
         self.model.add_data(DeviceInfo(name=dialog.name,
                                        description=dialog.description,
                                        services=dialog.services))
     dialog.destroy()
예제 #18
0
 def on_action_add_activate(self, action):
     """Add a new service"""
     dialog = UIServiceDetail(self.ui.dialog_services, self.model)
     if dialog.show(name='',
                    description='',
                    numeric_oid='',
                    title=_('Add new service'),
                    treeiter=None) == Gtk.ResponseType.OK:
         self.model.add_data(ServiceInfo(name=dialog.name,
                                         description=dialog.description,
                                         numeric_oid=dialog.numeric_oid))
     dialog.destroy()
예제 #19
0
 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),
             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 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'))
     else:
         self.ui.dialog_edit_service.response(Gtk.ResponseType.OK)
예제 #20
0
 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),
             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 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'))
     else:
         self.ui.dialog_edit_service.response(Gtk.ResponseType.OK)
예제 #21
0
파일: host.py 프로젝트: muflone/glivesnmp
 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,
                      self.ui.txt_address, self.ui.txt_community),
             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()
     address = self.ui.txt_address.get_text().strip()
     community = self.ui.txt_community.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'))
     elif len(address) == 0:
         # Show error for missing address
         show_error_message_on_infobar(
             self.ui.txt_address,
             _('The host address is missing'))
     elif '\'' in address or '\\' in address or '/' in address:
         # Show error for invalid address
         show_error_message_on_infobar(
             self.ui.txt_address,
             _('The host address is invalid'))
     elif len(community) == 0:
         # Show error for missing community string
         show_error_message_on_infobar(
             self.ui.txt_community,
             _('The community string is missing'))
     else:
         self.ui.dialog_host.response(Gtk.ResponseType.OK)
예제 #22
0
        def update_ui(values):
            """Update the UI in a thread-safe way using GLib"""
            for service in self.services.keys():
                treeiter = self.model.rows[service]
                self.model.set_value(
                    treeiter,
                    values.get(self.services[service], _('<SNMP Error>')))
                if values.has_key('error'):
                    print values

            # Start scan again if the timer is enabled
            if self.ui.action_timer.get_active():
                GLib.timeout_add(self.ui.adjustment_timer.get_value(),
                                 self.on_action_refresh_activate, action)
            else:
                # Stop the scan
                self.ui.action_refresh.set_active(False)
예제 #23
0
        def update_ui(values):
            """Update the UI in a thread-safe way using GLib"""
            for service in self.services.keys():
                treeiter = self.model.rows[service]
                self.model.set_value(treeiter,
                                     values.get(self.services[service],
                                                _('<SNMP Error>')))
                if values.has_key('error'):
                    print values

            # Start scan again if the timer is enabled
            if self.ui.action_timer.get_active():
                GLib.timeout_add(self.ui.adjustment_timer.get_value(),
                                 self.on_action_refresh_activate,
                                 action)
            else:
                # Stop the scan
                self.ui.action_refresh.set_active(False)
예제 #24
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()
예제 #25
0
파일: host.py 프로젝트: muflone/glivesnmp
    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,
                         self.ui.txt_address, self.ui.txt_community),
                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()
        address = self.ui.txt_address.get_text().strip()
        community = self.ui.txt_community.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'))
        elif len(address) == 0:
            # Show error for missing address
            show_error_message_on_infobar(self.ui.txt_address,
                                          _('The host address is missing'))
        elif '\'' in address or '\\' in address or '/' in address:
            # Show error for invalid address
            show_error_message_on_infobar(self.ui.txt_address,
                                          _('The host address is invalid'))
        elif len(community) == 0:
            # Show error for missing community string
            show_error_message_on_infobar(self.ui.txt_community,
                                          _('The community string is missing'))
        else:
            self.ui.dialog_host.response(Gtk.ResponseType.OK)
예제 #26
0
 def __init__(self, parent, host):
     """Prepare the snmp values dialog"""
     # Load the user interface
     self.ui = GtkBuilderLoader(get_ui_file('snmp_values.glade'))
     if not preferences.get(preferences.DETACHED_WINDOWS):
         self.ui.window_snmp.set_transient_for(parent)
     # Restore the saved size and position
     settings.positions.restore_window_position(
         self.ui.window_snmp, 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
         if widget.get_label():
             widget.set_label(text(widget.get_label()))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Initialize column headers
     for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn):
         widget.set_title(text(widget.get_title()))
     # Initialize services
     self.model = SNMPValues(self.ui.store_values)
     self.services = {}
     for service in model_devices.devices[host.device].services:
         oid = model_services.services[service].numeric_oid
         self.services[service] = oid
         value = SNMPValueInfo(name=service, value='', timestamp=0)
         self.model.add_data(value)
     # Sort the data in the models
     self.model.model.set_sort_column_id(
         self.ui.column_name.get_sort_column_id(),
         Gtk.SortType.ASCENDING)
     self.host = host
     self.ui.window_snmp.set_title(_('SNMP values for %s') % host.name)
     self.semaphore = None
     self.completed_threads = 0
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)
예제 #27
0
파일: about.py 프로젝트: muflone/glivesnmp
 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)
예제 #28
0
 def __init__(self, parent, host):
     """Prepare the snmp values dialog"""
     # Load the user interface
     self.ui = GtkBuilderLoader(get_ui_file('snmp_values.glade'))
     if not preferences.get(preferences.DETACHED_WINDOWS):
         self.ui.window_snmp.set_transient_for(parent)
     # Restore the saved size and position
     settings.positions.restore_window_position(self.ui.window_snmp,
                                                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
         if widget.get_label():
             widget.set_label(text(widget.get_label()))
     # Initialize tooltips
     for widget in self.ui.get_objects_by_type(Gtk.Button):
         action = widget.get_related_action()
         if action:
             widget.set_tooltip_text(action.get_label().replace('_', ''))
     # Initialize column headers
     for widget in self.ui.get_objects_by_type(Gtk.TreeViewColumn):
         widget.set_title(text(widget.get_title()))
     # Initialize services
     self.model = SNMPValues(self.ui.store_values)
     self.services = {}
     for service in model_devices.devices[host.device].services:
         oid = model_services.services[service].numeric_oid
         self.services[service] = oid
         value = SNMPValueInfo(name=service, value='', timestamp=0)
         self.model.add_data(value)
     # Sort the data in the models
     self.model.model.set_sort_column_id(
         self.ui.column_name.get_sort_column_id(), Gtk.SortType.ASCENDING)
     self.host = host
     self.ui.window_snmp.set_title(_('SNMP values for %s') % host.name)
     self.semaphore = None
     self.completed_threads = 0
     # Connect signals from the glade file to the module functions
     self.ui.connect_signals(self)
예제 #29
0
파일: about.py 프로젝트: muflone/glivesnmp
 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)
예제 #30
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()
예제 #31
0
파일: main.py 프로젝트: muflone/glivesnmp
 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()
예제 #32
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 glivesnmp.requires

from glivesnmp.functions import store_message, text, _
from glivesnmp.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('_', ''))
예제 #33
0
 def on_txt_description_changed(self, widget):
     """Check the service description field"""
     check_invalid_input(widget, False, True, False)
     self.ui.txt_numeric_oid.set_text(
         snmp.snmp.translate(widget.get_text().strip()) or _('Unkown OID'))
예제 #34
0
 def on_txt_description_changed(self, widget):
     """Check the service description field"""
     check_invalid_input(widget, False, True, False)
     self.ui.txt_numeric_oid.set_text(
         snmp.snmp.translate(widget.get_text().strip()) or
         _('Unkown OID'))