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()
def reload_hosts(self): """Load hosts from the settings files""" self.model_hosts.clear() self.hosts.clear() hosts_path = self.get_current_group_path() # Fix bug where the groups model isn't yet emptied, resulting in # being still used after a clear, then an invalid path if not os.path.isdir(hosts_path): return for filename in os.listdir(hosts_path): # Skip folders, used for groups if os.path.isdir(os.path.join(hosts_path, filename)): continue settings_host = settings.Settings(filename=os.path.join( hosts_path, filename), case_sensitive=True) host = HostInfo( name=settings_host.get(SECTION_HOST, OPTION_HOST_NAME), description=settings_host.get(SECTION_HOST, OPTION_HOST_DESCRIPTION), protocol=settings_host.get(SECTION_HOST, OPTION_HOST_PROTOCOL), address=settings_host.get(SECTION_HOST, OPTION_HOST_ADDRESS), port_number=settings_host.get_int(SECTION_HOST, OPTION_HOST_PORT), version=settings_host.get_int(SECTION_HOST, OPTION_HOST_VERSION), community=settings_host.get(SECTION_HOST, OPTION_HOST_COMMUNITY), device=settings_host.get(SECTION_HOST, OPTION_HOST_DEVICE)) self.add_host(host, False)
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()
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()
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()