wizard.py
来自「Ubuntu packages of security software。 相」· Python 代码 · 共 522 行 · 第 1/2 页
PY
522 行
self.directions['Profile'].hide() self.directions['Command'].show_all() self.directions['LastPage'] = self.directions['Profile'] def command_page(self): return self.directions[self.options.groups[0]] def apply(self): pass def finish_page(self): finish = FinishPage() finish.bar.cancel.connect('clicked', self.close_wizard) finish.bar.help.connect('clicked', self._show_help) finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1]) finish.bar.apply.connect('clicked', self.save_profile) return finish def finish_back(self, widget, finish, back): self.main_vbox.remove(finish) finish.hide() self.main_vbox._pack_expand_fill(self.directions[back]) self.directions[back].show_all() def constructor_page(self): pass def save_profile(self, widget): command = self.constructor.get_command('%s') if self.directions['Choose'].profile_radio.get_active(): profile_name = self.directions['Profile'].profile_entry.get_text() hint = self.directions['Profile'].hint_entry.get_text() buffer = self.directions['Profile'].description_text.get_buffer() description = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) buffer = self.directions['Profile'].annotation_text.get_buffer() annotation = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ options=self.constructor.get_options()) for i in xrange(self.notebook.get_n_pages()): page = self.notebook.get_nth_page(i) page.toolbar.profile_entry.update() else: target = self.directions['Choose'].target_entry.get_text() cmd = command % target current_page = self.notebook.get_nth_page(self.notebook.get_current_page()) if current_page == None: current_page = self.notebook.add_scan_page(target) current_page.execute_command(cmd) current_page.toolbar.target_entry.selected_target = self.\ directions['Choose'].target_entry.get_text() current_page.command_toolbar.command_entry.command = cmd current_page.command_toolbar.set_command(cmd) self.close_wizard()class FinishPage(HIGVBox): def __init__(self): HIGVBox.__init__(self) self.set_spacing(12) self.description = HIGEntryLabel(_("""The %s command has been generated. \Click Apply to finish this wizard.""" % NMAP_DISPLAY_NAME)) spacer = hig_box_space_holder() self.bar = ApplyBar() self._pack_noexpand_nofill(self.description) self._pack_expand_fill(spacer) self._pack_noexpand_nofill(self.bar)class ProfilePage(HIGVBox): def __init__(self): HIGVBox.__init__(self) self.set_spacing(12) self.prof = False self.description = HIGEntryLabel(_("""Please, enter the profile name, \and optionally, enter a hint, description and annotation for this \new profile""")) self.profile_label = HIGEntryLabel(_("Profile name")) self.hint_label = HIGEntryLabel(_("Hint")) self.description_label = HIGEntryLabel(_("Description")) self.annotation_label = HIGEntryLabel(_("Annotation")) self.profile_entry = gtk.Entry() self.hint_entry = gtk.Entry() self.description_scroll = HIGScrolledWindow() self.description_text = HIGTextView() self.annotation_scroll = HIGScrolledWindow() self.annotation_text = HIGTextView() self.description_scroll.add(self.description_text) self.annotation_scroll.add(self.annotation_text) table = HIGTable() self.bar = ForwardBar() self._pack_noexpand_nofill(self.description) self._pack_expand_fill(table) self._pack_noexpand_nofill(self.bar) table.attach(self.profile_label,0,1,0,1,xoptions=0) table.attach(self.profile_entry,1,2,0,1) table.attach(self.hint_label,0,1,1,2,xoptions=0) table.attach(self.hint_entry,1,2,1,2) table.attach(self.description_label,0,1,2,3,xoptions=0) table.attach(self.description_scroll,1,2,2,3) table.attach(self.annotation_label,0,1,3,4,xoptions=0) table.attach(self.annotation_scroll,1,2,3,4)class StartPage(HIGVBox): def __init__(self): HIGVBox.__init__(self) self.set_spacing(12) sec_vbox = HIGVBox() self.description = HIGEntryLabel(_("""You can construct \powerful %s commands in two distinct ways:""" % NMAP_DISPLAY_NAME)) self.novice_radio = gtk.RadioButton(None, _('Novice')) self.expert_radio = gtk.RadioButton(self.novice_radio, _('Expert (opens the Profile Editor)')) self.bar = ForwardBar(back=False) self._pack_noexpand_nofill(self.description) self._pack_expand_fill(sec_vbox) self._pack_noexpand_nofill(self.bar) sec_vbox._pack_noexpand_nofill(self.novice_radio) sec_vbox._pack_noexpand_nofill(self.expert_radio)class ChoosePage(HIGVBox): def __init__(self): HIGVBox.__init__(self) self.set_spacing(12) table = HIGTable() self.hbox = HIGHBox() self.description = HIGEntryLabel(_("""You wish to create a new profile,\ or just want to quickly create a command and run it once?""")) self.profile_radio = gtk.RadioButton(None, _('Profile')) self.command_radio = gtk.RadioButton(self.profile_radio, _('Command')) self.command_radio.connect('toggled', self.enable_target) self.profile_radio.connect('toggled', self.disable_target) self.target_label = HIGEntryLabel(_("Target")) self.target_entry = gtk.Entry() self.set_completion() self.hbox._pack_noexpand_nofill(hig_box_space_holder()) self.hbox._pack_noexpand_nofill(self.target_label) self.hbox._pack_expand_fill(self.target_entry) self.bar = ForwardBar() self._pack_noexpand_nofill(self.description) self._pack_expand_fill(table) self._pack_noexpand_nofill(self.bar) table.attach(self.profile_radio,0,1,0,1, yoptions=0) table.attach(self.command_radio,0,1,1,2, yoptions=0) table.attach(self.hbox,0,1,2,3, yoptions=0) self.disable_target() def set_completion(self): self.completion = gtk.EntryCompletion() self.target_list = gtk.ListStore(str) self.completion.set_model(self.target_list) self.completion.set_text_column(0) self.target_entry.set_completion(self.completion) for target in target_list.get_target_list()[:15]: self.target_list.append([target.replace('\n','')]) def add_new_target(self, target): target_list.add_target(target) def enable_target(self, widget=None): self.hbox.set_sensitive(True) def disable_target(self, widget=None): self.hbox.set_sensitive(False)class ForwardBar(HIGHBox): def __init__(self, help=True, cancel=True, back=True, forward=True): HIGHBox.__init__(self) self.set_homogeneous(True) self.help = HIGButton(stock=gtk.STOCK_HELP) self.cancel = HIGButton(stock=gtk.STOCK_CANCEL) self.back = HIGButton(stock=gtk.STOCK_GO_BACK) self.forward = HIGButton(stock=gtk.STOCK_GO_FORWARD) self._pack_expand_fill(self.help) self._pack_expand_fill(hig_box_space_holder()) self._pack_expand_fill(self.cancel) self._pack_expand_fill(self.back) self._pack_expand_fill(self.forward) if not help: self.help.set_sensitive(False) if not cancel: self.cancel.set_sensitive(False) if not back: self.back.set_sensitive(False) if not forward: self.forward.set_sensitive(False)class ApplyBar(HIGHBox): def __init__(self, help=True, cancel=True, back=True, apply=True): HIGHBox.__init__(self) self.set_homogeneous(True) self.help = HIGButton(stock=gtk.STOCK_HELP) self.cancel = HIGButton(stock=gtk.STOCK_CANCEL) self.back = HIGButton(stock=gtk.STOCK_GO_BACK) self.apply = HIGButton(stock=gtk.STOCK_APPLY) self._pack_expand_fill(self.help) self._pack_expand_fill(hig_box_space_holder()) self._pack_expand_fill(self.cancel) self._pack_expand_fill(self.back) self._pack_expand_fill(self.apply) if not help: self.help.set_sensitive(False) if not cancel: self.cancel.set_sensitive(False) if not back: self.back.set_sensitive(False) if not apply: self.apply.set_sensitive(False)if __name__ == '__main__': w = Wizard() w.show_all() w.connect('delete-event', lambda x,y:gtk.main_quit()) gtk.main()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?