class Proprieties(HIGScrolledWindow): ''' This box should be configurable if widget is of a type all configuration should be change to this type #tricks: option_list have a icon to fill with options and option_check have a list of options in combo to change ''' def __init__(self): HIGScrolledWindow.__init__(self) self._boxeditable = None vp = gtk.Viewport() self._create_widgets() vp.add(self._box) vp.set_shadow_type(gtk.SHADOW_NONE) self.add(vp) self._profilecore = None self._selected = None def set_profilecore(self, profilecore): self._profilecore = profilecore def _create_widgets(self): ''' Create the main entrys of the option ''' self._box = HIGVBox() self._table = HIGTable() #Name self._label_name = HIGEntryLabel(_('Name')) self._entry_name = HIGTextEntry() self._entry_name.connect('activate', self._update_label) #Type self._label_type = HIGEntryLabel(_('Type')) self._combo_type = gtk.combo_box_new_text() self._combo_type.append_text('') self._combo_type.append_text('Option List') self._combo_type.append_text('Option Check') self._combo_type.set_active(0) self._combo_type.connect('changed', self.change_combo) self._label_opt = HIGEntryLabel(_('Option')) self._entry_opt = HIGTextEntry() self._entry_opt.set_sensitive(False) #For option list open a dialog to add/remove options self._button_list = HIGButton('Edit Option List') img = gtk.Image() img_dir = os.path.join(pixmaps_dir, 'uie', 'combo.png') img.set_from_file(img_dir) self._button_list.set_image(img) self._button_list.connect('button-press-event', self._button_list_clicked) self._table.attach(self._label_name, 0,1,0, 1) self._table.attach(self._entry_name, 1,2,0,1) self._table.attach(self._label_type, 0,1,1,2) self._table.attach(self._combo_type, 1,2,1, 2) self._table.attach(self._button_list, 0,2, 3,4) self._table.attach(self._label_opt, 0,1, 4,5) self._table.attach(self._entry_opt, 1,2,4,5) self._box.pack_start(self._table, False, False) def _button_list_clicked(self, widget, event): section_name = self._boxeditable.get_name() lm = ListManager(self._entry_name.get_text(),section_name, self._profilecore, self._selected, _('List of items')) def _update_label(self, widget): #XXX Replace by Command log.debug("Update Label") selected = self._selected cmd = CommandChangeLabel(selected, self._entry_name.get_text(), self._profilecore,self._boxeditable, True) command_manager.add_command(cmd) def change_combo(self,combo): model = combo.get_model() index = combo.get_active() if index: if model[index][0]=='Option List': log.debug('Show Button List ') self._button_list.show() else: log.debug('Hide Button List ') self._button_list.hide() return def show_notebook_label(self): ''' show proprieties of notebook label and hide others ''' pass def show_item(self): pass def hide_item(self): self._label_opt.hide() self._entry_opt.hide() self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._entry_name.hide() self._label_name.hide() def set_notebooklabel(self, selected): self._entry_name.show() self._label_name.show() self._entry_name.set_text(selected.get_text()) self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._label_opt.hide() self._entry_opt.hide() self._selected = selected def set_item(self, selected): self._entry_name.show() self._label_name.show() self._selected = selected if selected.get_name()!=None: self._entry_name.set_text(selected.get_name()) else: self.hide_item() return childs = selected.get_children() self._combo_type.show() self._label_type.show() child_label = childs[0] if isinstance(child_label, gtk.HBox): #OptionCheck self._label_opt.show() self._entry_opt.show() opt_ = self._profilecore.get_opt_check(self._boxeditable.get_name(), selected.get_name()) self._entry_opt.set_text(opt_) self._button_list.hide() child_label.cbutton.set_label(self._entry_name.get_text()) self._combo_type.set_active(2) #XXX: Put other widget that sensitible = False with option name elif isinstance(child_label, gtk.EventBox): #OptionList self._button_list.show() other = child_label.get_children()[0] other.set_label(self._entry_name.get_text()) self._combo_type.set_active(1) #Disable Combo to change OptionList/OptionChange self._combo_type.set_sensitive(False) def set_boxeditable(self, boxeditable): self._boxeditable = boxeditable def update(self): pass def disable_all(self): self._label_opt.hide() self._entry_opt.hide() self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._entry_name.hide() self._label_name.hide() def load_data(self, option): pass def unload(self,option): pass
class Proprieties(HIGScrolledWindow): ''' This box should be configurable if widget is of a type all configuration should be change to this type #tricks: option_list have a icon to fill with options and option_check have a list of options in combo to change ''' def __init__(self): HIGScrolledWindow.__init__(self) self._boxeditable = None vp = gtk.Viewport() self._create_widgets() vp.add(self._box) vp.set_shadow_type(gtk.SHADOW_NONE) self.add(vp) self._profilecore = None self._selected = None def set_profilecore(self, profilecore): self._profilecore = profilecore def _create_widgets(self): ''' Create the main entrys of the option ''' self._box = HIGVBox() self._table = HIGTable() #Name self._label_name = HIGEntryLabel(_('Name')) self._entry_name = HIGTextEntry() self._entry_name.connect('activate', self._update_label) #Type self._label_type = HIGEntryLabel(_('Type')) self._combo_type = gtk.combo_box_new_text() self._combo_type.append_text('') self._combo_type.append_text('Option List') self._combo_type.append_text('Option Check') self._combo_type.set_active(0) self._combo_type.connect('changed', self.change_combo) self._label_opt = HIGEntryLabel(_('Option')) self._entry_opt = HIGTextEntry() self._entry_opt.set_sensitive(False) #For option list open a dialog to add/remove options self._button_list = HIGButton('Edit Option List') img = gtk.Image() img_dir = os.path.join(pixmaps_dir, 'uie', 'combo.png') img.set_from_file(img_dir) self._button_list.set_image(img) self._button_list.connect('button-press-event', self._button_list_clicked) self._table.attach(self._label_name, 0, 1, 0, 1) self._table.attach(self._entry_name, 1, 2, 0, 1) self._table.attach(self._label_type, 0, 1, 1, 2) self._table.attach(self._combo_type, 1, 2, 1, 2) self._table.attach(self._button_list, 0, 2, 3, 4) self._table.attach(self._label_opt, 0, 1, 4, 5) self._table.attach(self._entry_opt, 1, 2, 4, 5) self._box.pack_start(self._table, False, False) def _button_list_clicked(self, widget, event): section_name = self._boxeditable.get_name() lm = ListManager(self._entry_name.get_text(), section_name, self._profilecore, self._selected, _('List of items')) def _update_label(self, widget): #XXX Replace by Command log.debug("Update Label") selected = self._selected cmd = CommandChangeLabel(selected, self._entry_name.get_text(), self._profilecore, self._boxeditable, True) command_manager.add_command(cmd) def change_combo(self, combo): model = combo.get_model() index = combo.get_active() if index: if model[index][0] == 'Option List': log.debug('Show Button List ') self._button_list.show() else: log.debug('Hide Button List ') self._button_list.hide() return def show_notebook_label(self): ''' show proprieties of notebook label and hide others ''' pass def show_item(self): pass def hide_item(self): self._label_opt.hide() self._entry_opt.hide() self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._entry_name.hide() self._label_name.hide() def set_notebooklabel(self, selected): self._entry_name.show() self._label_name.show() self._entry_name.set_text(selected.get_text()) self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._label_opt.hide() self._entry_opt.hide() self._selected = selected def set_item(self, selected): self._entry_name.show() self._label_name.show() self._selected = selected if selected.get_name() != None: self._entry_name.set_text(selected.get_name()) else: self.hide_item() return childs = selected.get_children() self._combo_type.show() self._label_type.show() child_label = childs[0] if isinstance(child_label, gtk.HBox): #OptionCheck self._label_opt.show() self._entry_opt.show() opt_ = self._profilecore.get_opt_check( self._boxeditable.get_name(), selected.get_name()) self._entry_opt.set_text(opt_) self._button_list.hide() child_label.cbutton.set_label(self._entry_name.get_text()) self._combo_type.set_active(2) #XXX: Put other widget that sensitible = False with option name elif isinstance(child_label, gtk.EventBox): #OptionList self._button_list.show() other = child_label.get_children()[0] other.set_label(self._entry_name.get_text()) self._combo_type.set_active(1) #Disable Combo to change OptionList/OptionChange self._combo_type.set_sensitive(False) def set_boxeditable(self, boxeditable): self._boxeditable = boxeditable def update(self): pass def disable_all(self): self._label_opt.hide() self._entry_opt.hide() self._button_list.hide() self._combo_type.hide() self._label_type.hide() self._entry_name.hide() self._label_name.hide() def load_data(self, option): pass def unload(self, option): pass
class ExposeProfiles(TabBox, object): def __init__(self, name): """ Create defaults Widget """ TabBox.__init__(self, name) self._pack_widgets() self._connect_events() def _create_widgets(self): """ Create widgets""" self._frm_option = HIGFrame(_('Options')) self._box_option = HIGHBox() self.__lbl_file_opt = HIGEntryLabel(_('File:')) self.__entry_file_opt = HIGTextEntry() self.__entry_file_opt.set_editable(False) self.__file_browser_opt = HIGButton(_('Browse file'), \ gtk.STOCK_DIRECTORY) self._frm_profile = HIGFrame(_('Profile')) self._box_profile = HIGHBox() self.__lbl_file_profile = HIGEntryLabel(_('File:')) self.__entry_file_profile = HIGTextEntry() self.__entry_file_profile.set_editable(False) self.__file_browser_profile = HIGButton(_('Browse file'), \ gtk.STOCK_DIRECTORY) self._frm_wizard = HIGFrame(_('Wizard')) self._box_wizard = HIGHBox() self.__lbl_file_wizard = HIGEntryLabel(_('File:')) self.__entry_file_wizard = HIGTextEntry() self.__entry_file_wizard.set_editable(False) self.__file_browser_wizard = HIGButton(_('Browse file'), \ gtk.STOCK_DIRECTORY) self.__btn_restore = HIGButton(_('Restore Defaults'), gtk.STOCK_CLEAR) def _pack_widgets(self): # Options self._box_option._pack_noexpand_nofill(self.__lbl_file_opt) self._box_option._pack_noexpand_nofill(self.__entry_file_opt) self._box_option._pack_noexpand_nofill(self.__file_browser_opt) self._frm_option.add(self._box_option) # Profile self._box_profile._pack_noexpand_nofill(self.__lbl_file_profile) self._box_profile._pack_noexpand_nofill(self.__entry_file_profile) self._box_profile._pack_noexpand_nofill(self.__file_browser_profile) self._frm_profile.add(self._box_profile) # Wizard self._box_wizard._pack_noexpand_nofill(self.__lbl_file_wizard) self._box_wizard._pack_noexpand_nofill(self.__entry_file_wizard) self._box_wizard._pack_noexpand_nofill(self.__file_browser_wizard) self._frm_wizard.add(self._box_wizard) # Pack Frames self.pack_start(self._frm_option, False,False) self.pack_start(self._frm_profile, False, False) self.pack_start(self._frm_wizard, False, False) def _connect_events(self): self.__entry_file_opt.connect("changed", self.update_file_opt) self.__entry_file_profile.connect("changed", self.update_file_profile) self.__entry_file_wizard.connect("changed", self.update_file_wizard) # Callbacks # Should be merged callback based on a dict or whatever. def update_file_opt(self): profile_conf.options = self.__entry_file_opt.get_text() def update_file_profile(self): profile_conf.profile = self.__entry_file_wizard.get_text() def update_file_wizard(self): profile_conf.wizard = self.__entry_file_wizard.get_text() # API def get_profile(self): return self.__entry_file_profile.get_text() def set_profile(self, profile): self.__entry_file_profile.set_text(profile) def get_wizard(self): return self.__entry_file_wizard.get_text() def set_wizard(self, wizard): self.__entry_file_wizard.set_text(wizard) def set_options(self, options): self.__entry_file_opt.set_text(options) def get_options(self): return self.__entry_file_opt.get_text() profile = property(get_profile, set_profile) wizard = property(get_wizard, set_wizard) options = property(get_options, set_options)
class EntryField(object): """ This class is responsible by the main part of QS: the EntryField. All logic of completion, data handling and interface is here. """ def __init__(self): self.qs_data = QSData() self.entry = HIGTextEntry() self.entry.set_visibility(True) self.status = Status() self.status.set_empty() self.scan_result = Result() self.b_text = "" self.rgx_is_domain = "^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}" self.rgx_is_domain += "([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)" self.rgx_is_domain += "(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?" self.completion = gtk.EntryCompletion() self.entry.set_max_length(1000) # add button to launch result in umit self.btn_umit = gtk.Button ("Open Result") self.results_opened = False self.nmap_output = None self.load_data(None) self.btn_umit.connect("clicked", self._launch_umit, None) self.entry.show() def show_results(self): """ Show scan output """ if not self.results_opened: self.nmap_output = NmapOutputViewer() # remove some buttons self.nmap_output.hbox_buttons.remove(self.nmap_output.btn_output_properties) self.nmap_output.hbox_buttons.remove(self.nmap_output.btn_refresh) self.nmap_output.hbox_buttons.pack_start(self.btn_umit) self.vbox.pack_end(self.nmap_output) self.vbox.show_all() self.results_opened = True def hide_results(self): """ Hide scan output """ if self.results_opened: self.nmap_output.hbox_buttons.remove(self.btn_umit) self.vbox.remove(self.nmap_output) self.results_opened = False def menu_to_umit(self, widget, button, time, data=None): """ Here will be the small menu responsible to call Network Scanner. """ if button == 3: data.show_all() def _launch_umit(self, widget, event): """ Here will go the call to NetWork Scanner to display results previously loaded here. """ nscanner_call = "umit -f %s" % self.command_execution.get_xml_output_file() args = shlex.split(nscanner_call) self.command_process = Popen(args, bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE) def load_data(self, option=None): """ Load the data on gtk.ListStore, generate the model and set functions of match and signals. """ liststore = gtk.ListStore(str) if option == "host": for _d in self.qs_data.get_target_list(): liststore.append([_d]) elif option == "profile": for _d in self.qs_data.get_profiles("profile_name"): liststore.append([_d]) elif option == "nmap_options": for _d in self.qs_data.get_nmap_options(): liststore.append([_d]) else: for _d in self.qs_data.get_all().values(): for _i in _d: liststore.append([_i]) self.completion.set_model(liststore) self.completion.set_match_func(self.match_func) self.completion.connect('match-selected', self.on_completion_match) self.entry.connect('activate', self.on_completion_not_match) self.entry.connect('backspace', self.on_backspace) self.entry.set_completion(self.completion) self.completion.set_text_column(0) #def load_if_not_complete(self, widget, event): #self.load_data("host") def match_func(self, completion, key, iter): """ This function have the job to match and compare the words that was entered on the entry field. """ model = self.completion.get_model() modelstr = model[iter][0] if ' ' in key: last_word = " ".join(key.split()[1:]) if last_word != "": return modelstr.lower().startswith(last_word.lower()) or modelstr.lower().startswith(key.lower()) return modelstr.lower().startswith(key.lower()) def on_completion_not_match(self, widget): """ This method is called when the autocompletion don't match any result or user press Enter. """ target_list = TargetList() entered_text = self.entry.get_text() # If has a profile if len(entered_text) > 1 and entered_text.find(" ") != -1: possible_host = entered_text.split(" ")[0] possible_profile = " ".join(entered_text.split(" ")[1:]) else: # If is just a domain self.b_text = entered_text + " " self.entry.set_text(self.b_text) possible_host = entered_text possible_profile = None # Saving the target target_list.add_target(possible_host) self.entry.set_position(-1) # if len(self.b_text.split(" ")) > 1: # host = self.b_text.split(" ")[0] # profile = " ".join(self.b_text.split(" ")[1:]) # else: # host = entered_text # profile = None #Launch the scan self.run_scan(possible_host, possible_profile) #TODO: get the end of the scan here? try: alive = self.command_execution.scan_state() while alive: alive = self.command_execution.scan_state() file = self.command_execution.get_normal_output_file() self.show_results() self.nmap_output.show_nmap_output(file) self.nmap_output.refresh_output() #text_out = self.scan_result.set_nmap_output(possible_host, # self.command_execution.get_normal_output(), # possible_profile) #self.buffer.set_text(text_out) #self.vbox.pack_start(self.result_text, False, False, 0) #self.result_text.show() self.save_scan(possible_host) #del entered_text #self.load_data("profile") return True except: pass def on_completion_match(self, completion, model, iter): #get the text entered by the user entered_text = self.entry.get_text() if model[iter][0]: current_text = model[iter][0] # If has a profile if len(entered_text) > 1 and entered_text.find(" ") != -1: self.b_text = entered_text.split(" ")[0] + " " + current_text + " " self.entry.set_text(self.b_text) possible_host = entered_text.split(" ")[0] possible_profile = current_text #elif self.entry.get_text() else: # If is just a domain self.b_text = current_text + " " self.entry.set_text(self.b_text) possible_host = current_text possible_profile = None self.entry.set_position(-1) data_from_db = self.qs_data.get_from_db() if current_text in data_from_db.keys(): text_out = "" for _t in data_from_db[current_text]: if _t[0] == "ports" or _t[0] == "stats": pass else: text_out += "%s: %s\n" % (_t[0], _t[1]) #self.buffer.set_text(text_out) #self.vbox.pack_start(self.result_text, False, False, 0) #self.result_text.show() self.run_scan(possible_host, possible_profile) try: alive = self.command_execution.scan_state() while alive: alive = self.command_execution.scan_state() if not alive: break self.show_results() file = self.command_execution.get_normal_output_file() print "scan finished - %s" % file self.nmap_output.show_nmap_output(file) self.nmap_output.refresh_output() #text_out = self.scan_result.set_nmap_output(possible_host, # self.command_execution.get_normal_output(), # possible_profile) #self.buffer.set_text(text_out) #self.vbox.pack_start(self.result_text, False, False, 0) #self.result_text.show() self.save_scan(possible_host) #self.load_data("profile") return True except: print("exception") traceback.print_exc(file=sys.stdout) del data_from_db #self.load_data("profile") return True def on_backspace(self, entry): self.hide_results() self.resize(500,30) self.b_text = "" def disable_widgets(self): self.scan_result.set_sensitive(False) def enable_widgets(self): self.scan_result.set_sensitive(True) def kill_scan(self): try: self.command_execution.kill() except AttributeError: pass self.entry.set_text("") self.status.set_empty() self.disable_widgets() def run_scan(self, host, profile): if re.match(self.rgx_is_domain, host): commands = self.qs_data.get_profiles("profile_commands") try: nmap_option = commands[profile] except: nmap_option = "-T Aggressive -v -n" print "QuickScan: running scan: %s on %s" % (nmap_option, host) if Ipv6.is_ipv6(host): namp_option = nmap_option + " -6" self.command_execution = NmapCommand('%s %s %s' % (Path.nmap_command_path, nmap_option, host)) try: alive = self.command_execution.scan_state() if alive: warn_dialog = HIGAlertDialog( message_format="Scan has not finished yet", secondary_text="Another scan is running in the background.", type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK_CANCEL) response = warn_dialog.run() warn_dialog.destroy() if response == gtk.RESPONSE_OK: self.kill_scan() else: return except: pass try: self.command_execution.run_scan() self.status.set_scanning() except OSError, msg: warn_dialog = HIGAlertDialog( message_format="Nmap couldn't be found", secondary_text="Umit Quick Scan couldn't find Nmap. " "Please check your Nmap instalation.", type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() except Exception, msg: warn_dialog = HIGAlertDialog( message_format="Command is missing!", secondary_text="Please check your profile's command.", type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() self.verify_thread_timeout_id = gobject.timeout_add(2000, self.verify_execution) return
class GeneralSettings(TabBox, object): """ General Settings - Splash enable/disable - Warnings - Erros, log, configure bugreport - Autosave: clean up, define folder etc - Define Nmap Command """ def __init__(self, name): TabBox.__init__(self, name) def _create_widgets(self): """ Design all """ # Create general widgets self._create_widgets_common() self._create_widgets_autosave() self._create_widgets_error() # Packing main section self.pack_start(self._box_common, False, False) self.pack_start(self._box_error_frame, False, False) self.pack_start(self._box_save_frame, False, False) self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE) self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE) # Settings Values self.splash = general_settings.splash self.warnings_extensions = general_settings.warnings_extensions self.silent_root = general_settings.silent_root self.crash_report = general_settings.crash_report self.log = general_settings.log self.log_file = general_settings.log_file self.warnings_save = general_settings.warnings_save self._connect_events() def _create_widgets_common(self): """ generally tab """ self._box_common = HIGVBox() # pack main section self.__check_splash = gtk.CheckButton(_('Enable Splash on start')) self.__check_silent_root = gtk.CheckButton(\ _('Silent Warning Non-Root')) self.__check_warning_extensions = gtk.CheckButton(\ _('Set/Check extensions - Windows only')) self._box_common.pack_start(self.__check_splash, False, False) #self._box_common.pack_start(self.__check_warning_extensions, False, \ # False) self._box_common.pack_start(self.__check_silent_root, False, False) self.__label_nmap = HIGEntryLabel(_('Nmap Command')) self.__entry_nmap = HIGTextEntry() # Files usr saved on predefined directory: self.__label_path = HIGEntryLabel(_('Nmap Command')) self.__entry_path = HIGTextEntry() self.__button_path = HIGButton(_('Choose')) self.__box_path = HIGHBox() self.__box_path.pack_start(self.__label_path, False, False) self.__box_path.pack_end(self.__button_path, False, False) self._box_common.set_border_width(0) def _create_widgets_error(self): # Create Widgets self._box_error_frame = HIGFrame('Error') self._box_error = HIGTable(5, 2) self._box_error.set_border_width(10) self._box_error_frame.add(self._box_error) self.__crash_report = gtk.CheckButton(_('Enable Crash Report')) # Radio Button List self.__log_no = gtk.RadioButton(None, _('No log')) self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal')) self.__log_file = gtk.RadioButton(self.__log_terminal,\ _('Enable log file')) self.__log_file_label = HIGEntryLabel(_('Log file')) self.__log_file_entry = HIGTextEntry() self.__log_file_entry.set_editable(False) # FIXME: Do default file ~/.umit/umit.log self.__log_file_browser = HIGButton(_('Browse file'), \ gtk.STOCK_DIRECTORY) tmpbox = HIGHBox() tmpbox.pack_start(self.__log_file_entry, False, False) tmpbox.pack_start(self.__log_file_browser, False, False) # attach table self._box_error.attach(self.__crash_report, 0,1,0,1,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) self._box_error.attach(self.__log_no, 0,1,1,2,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) self._box_error.attach(self.__log_terminal, 0,1,2,3,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) self._box_error.attach(self.__log_file, 0,1,3,4,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) self._box_error.attach(self.__log_file_label, 0,1,4,5,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) self._box_error.attach(tmpbox, 1,2,4,5,\ gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL) def _create_widgets_autosave(self): # Create Widgets self._box_save_frame = HIGFrame('Auto-save') self._box_save = HIGVBox() self._box_save_frame.add(self._box_save) self._box_save.set_border_width(10) self._warnings_save = gtk.CheckButton( _('Enable warnings without saving')) self._clean_b = HIGButton(_('Delete saved files'), gtk.STOCK_CLEAR) self._clean_b_box = HIGHBox() self._clean_b_box.pack_start(self._clean_b, False, True) # pack self._box_save.pack_start(self._warnings_save, False, False) self._box_save.pack_start(self._clean_b_box, False, False) def _connect_events(self): """ connect call backs """ self.__check_splash.connect('toggled', self.update_splash) self.__check_silent_root.connect('toggled', self.update_silent_root) self.__crash_report.connect('toggled', self.update_crash_report) self.__log_file.connect('toggled', self.update_log) self.__log_file.connect('toggled', self.update_log_file) self.__log_terminal.connect('toggled', self.update_log) self.__log_no.connect('toggled', self.update_log) self.__log_file_browser.connect('clicked', self.read_file) self.__log_file_entry.connect('changed', self.update_log_file_text) self._warnings_save.connect('toggled', self.update_save_warn) self._clean_b.connect('clicked', self.delete_files) self.update_log_file(None) # Callbacks def delete_files(self, widget): # NOTE: This method should be adapted in umit.core.UserConf # Creating an empty recent_scans file log.debug('>>> Reset store files: - %s' % base_paths['user_dir']) reset_user_dir(base_paths['user_dir']) def update_save_warn(self, widget): general_settings.warnings_save = self.warnings_save def read_file(self, widget): dialog = gtk.FileChooserDialog("Open..", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) response = dialog.run() if response == gtk.RESPONSE_OK: # Get name of file self.__log_file_entry.set_text(dialog.get_filename()) dialog.destroy() def update_crash_report(self, widget): general_settings.crash_report = self.crash_report def update_splash(self, widget): general_settings.splash = self.splash def update_silent_root(self, widget): general_settings.silent_root = self.silent_root def update_log_file_text(self, widget): general_settings.log_file = self.log_file def update_log_file(self, widget): if not self.__log_file.get_active(): self.__log_file_active(False) else: self.__log_file_active(True) def update_log(self, widget): """ Verify if is enable, if it is not enable nothing to do """ if not widget.get_active(): return # Widget is enable. ## But which is enable? # Setting kind of log if widget == self.__log_no: general_settings.log = "None" elif widget == self.__log_terminal: general_settings.log = "Debug" elif widget == self.__log_file: general_settings.log = "File" # API def get_splash(self): return self.__check_splash.get_active() def set_splash(self, splash): self.__check_splash.set_active(splash) def set_warnings_extensions(self, extensions): self.__check_warning_extensions.set_active(extensions) def get_warnings_extensions(self): return self.__check_warning_extensions.get_active() def set_silent_root(self, root): self.__check_silent_root.set_active(root) def get_silent_root(self): return self.__check_silent_root.get_active() def set_crash_report(self, crash): self.__crash_report.set_active(crash) def get_crash_report(self): return self.__crash_report.get_active() def get_log(self): """ filter a str with None, Debug or File return: int (means 0 - No debug, 1 - debug, 2 - debug file) """ if self.__log_no.get_active(): return "None" elif self.__log_terminal.get_active(): return "Debug" elif self.__log_file.get_active(): return "File" else: raise LogException() def set_log(self, log): if log == "None": self.__log_no.set_active(True) elif log == "Debug": self.__log_terminal.set_active(True) elif log == "File": self.__log_file.set_active(True) def __log_file_active(self, bool): self.__log_file_label.set_sensitive(bool) self.__log_file_entry.set_sensitive(bool) self.__log_file_browser.set_sensitive(bool) def set_log_file(self, filename): self.__log_file_entry.set_text(filename) def get_log_file(self): return self.__log_file_entry.get_text() def set_warnings_save(self, save): self._warnings_save.set_active(save) def get_warnings_save(self): return self._warnings_save.get_active() # Propertys splash = property(get_splash, set_splash) warnings_extensions = property(get_warnings_extensions, \ set_warnings_extensions) silent_root = property(get_silent_root, set_silent_root) crash_report = property(get_crash_report, set_crash_report) log = property(get_log, set_log) log_file = property(get_log_file, set_log_file) warnings_save = property(get_warnings_save, set_warnings_save)