def del_bridge_dialog(self, button): msg = "Delete bridge: %s ?" % self.activebridge_name dialog.display_dialog(self, urwid.Text(msg), "Confirm your operation", body_type='bool', mod_callback=self.del_bridge)
def check_eth(self): focus = self.walker.get_focus() if focus[1] != 2: pass else: inner_pos = focus[0].original_widget.focus_position eth_name = focus[0].contents[inner_pos].get_label().split()[0] dialog.display_dialog(self, urwid.Text("%s is highlight" % eth_name), 'highlight', 'esc')
def edit_bridge(self, button): if len(self.bridge_list) == 0: dialog.display_dialog(self, urwid.Text("No bridge could be edited"), "Error Operation") return # back button self.back_button = widget.Button('BACK', self.back_screen) back_button_line = urwid.GridFlow([self.back_button], 8, 0, 0, 'left') ## draw a new screen with two lineboxes which used to ## configure net info and eths for bond # linebox 1 net_info_listbox = modulehelper.ModuleHelper.screenUI( self, [], self.fields, self.defaults, button_visible=False) net_info_linebox = urwid.LineBox(net_info_listbox, "Network Address") # store edit fields for visiting conveniently self.edits_tmp = self.edits # linebox 2 bond_for_bridge = widget.ColContainTwoListBox( "Bond inuse", "Bond usable", self.active_bridge_bond_inuse, self.active_bridge_bond_usable, self.remove_bond, self.add_bond) bond_for_bridge_listbox = modulehelper.ModuleHelper.screenUI( self, [bond_for_bridge], [], {}, button_visible=False, iblank=False) bond_for_bridge_linebox = urwid.LineBox(bond_for_bridge_listbox, "Bond Interface") # new screen self.bond_for_bridge_height = max([ len(self.active_bridge_bond_inuse), len(self.active_bridge_bond_usable) ]) screen_new_header = [ back_button_line, urwid.BoxAdapter(net_info_linebox, 7), blank, urwid.BoxAdapter(bond_for_bridge_linebox, self.bond_for_bridge_height + 7) ] screen_new = modulehelper.ModuleHelper.screenUI( self, screen_new_header, [], {}, button_label=["DEL", "APPLY"], button_callback=[self.del_bridge_dialog, self.apply]) self.edits = self.edits_tmp # redraw mod screen self.parent.draw_child_screen(screen_new) self.parent.cols.set_focus(1) self.edit_open = True
def save(self): results, modulename = self.parent.global_save() if results: self.parent.footer.original_widget.set_text( "All changes saved successfully!") return True else: #show pop up with more details msg = "ERROR: Module %s failed to save. Go back" % (modulename) \ + " and fix any mistakes or choose Quit without Saving." dialog.display_dialog(self, urwid.Text(msg), "Error saving changes!") return False
def power_off(self, args=None): if not self.parent.globalsave: if self.language == modulehelper.LanguageType.CHINESE: msg = u"请确认已经保存了修改" elif self.language == modulehelper.LanguageType.ENGLISH: msg = u"please check you have saved your changes" dialog.display_dialog(self, urwid.Text(msg), "You cannot power off immediate!") return False else: time.sleep(1.5) system('reboot') self.parent.exit_program(None)
def add_bond(self, button): msg = "Create new bond" edit_field = widget.TextField( None, 'Bond name', 10, tooltip='Manual add bond, edit bond name with digit and alpha', default_value="", tool_bar=self.parent.footer) dialog.display_dialog(self, edit_field, msg, body_type='edit', mod_callback=self.dialog_callback_add_bond)
def add_bridge(self, button): msg = "create new bridge" edit_field = widget.TextField( None, 'Bridge name', 13, tooltip= 'Manual add bridge, please add bridge name with digit and alpha', default_value="", tool_bar=self.parent.footer) dialog.display_dialog(self, edit_field, msg, body_type='edit', mod_callback=self.dialog_callback_add_bridge)
def menuitem_chosen(self, button, c): if self.is_login is False: if c != "Login": self.menuitems.set_focus(2) dialog.display_dialog(self.child, urwid.Text("Please login first"), "Illegal Operation") return False size = self.screen.get_cols_rows() self.screen.draw_screen(size, self.frame.render(size)) for item in self.menuitems.body.contents: try: if isinstance(item.base_widget, urwid.Button): if item.base_widget.get_label() == c: item.set_attr_map({None: 'header'}) else: item.set_attr_map({None: None}) except AttributeError: log.exception("Unable to set menu item %s" % item) self.set_child_screen(name=c)
def check(self, button): str = self.edit1.edit_text if not str[0].isdigit(): msg = u'请在第一个框内输入数字' dialog.display_dialog(self, urwid.Text(msg), u"输入错误") return False str = self.edit2.edit_text if not str[0].isalpha(): msg = u'请在第二个框内输入字母' dialog.display_dialog(self, urwid.Text(msg), u"输入错误") return False msg = u'姜毅是真的帅' dialog.display_dialog(self, urwid.Text(msg), u"告诉你个秘密") self.cool_num += 1 self.text.set_text( self.text.text.replace('%d' % (self.cool_num - 1), '%d' % self.cool_num)) self.edit1.original_widget.set_mask('*') return True
def main(self): #Disable kernel print messages. They make our UI ugly noout = open('/dev/null', 'w') subprocess.call(["sysctl", "-w", "kernel.printk=4 1 1 7"], stdout=noout, stderr=noout) text_header = (u"Fuel %s setup " u"Use Up/Down/Left/Right to navigate. F8 exits." % self.version) text_footer = (u"Status messages go here.") #Top and bottom lines of frame self.header = urwid.AttrWrap(urwid.Text(text_header), 'header') self.footer = urwid.AttrWrap(urwid.Text(text_footer), 'footer') #Prepare submodules loader = Loader(self) moduledir = "%s/modules" % (os.path.dirname(__file__)) self.children, self.choices = loader.load_modules(module_dir=moduledir) if len(self.children) == 0: import sys sys.exit(1) #Build list of choices excluding visible self.visiblechoices = [] for child, choice in zip(self.children, self.choices): if child.visible: self.visiblechoices.append(choice) self.menuitems = self.menu(u'Menu', self.visiblechoices) menufill = urwid.Filler(self.menuitems, 'top', 40) self.menubox = urwid.BoxAdapter(menufill, 40) self.child = self.children[0] self.childpage = self.child.screenUI() self.childfill = urwid.Filler(self.childpage, 'top', 22) self.childbox = urwid.BoxAdapter(self.childfill, 22) self.cols = urwid.Columns( [ ('fixed', 20, urwid.Pile([ urwid.AttrMap(self.menubox, 'bright'), urwid.Divider(" ")])), ('weight', 3, urwid.Pile([ urwid.Divider(" "), self.childbox, urwid.Divider(" ")])) ], 1) self.listwalker = urwid.SimpleListWalker([self.cols]) #self.listwalker = urwid.TreeWalker([self.cols]) self.listbox = urwid.ListBox(self.listwalker) #listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content)) self.frame = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=self.header, footer=self.footer) palette = \ [ ('body', 'black', 'light gray', 'standout'), ('reverse', 'light gray', 'black'), ('header', 'white', 'dark red', 'bold'), ('important', 'dark blue', 'light gray', ('standout', 'underline')), ('editfc', 'white', 'dark blue', 'bold'), ('editbx', 'light gray', 'dark blue'), ('editcp', 'black', 'light gray', 'standout'), ('bright', 'dark gray', 'light gray', ('bold', 'standout')), ('buttn', 'black', 'dark cyan'), ('buttnf', 'white', 'dark blue', 'bold'), ('light gray', 'white', 'light gray', 'bold'), ('red', 'dark red', 'light gray', 'bold'), ('black', 'black', 'black', 'bold'), ] # use appropriate Screen class if urwid.web_display.is_web_request(): self.screen = urwid.web_display.Screen() else: self.screen = urwid.raw_display.Screen() def unhandled(key): if key == 'f8': raise urwid.ExitMainLoop() if key == 'shift tab': self.child.walker.tab_prev() if key == 'tab': self.child.walker.tab_next() self.mainloop = urwid.MainLoop(self.frame, palette, self.screen, unhandled_input=unhandled) #Initialize each module completely before any events are handled for child in reversed(self.children): self.setChildScreen(name=child.name) #Prepare DNS for resolution dnsobj = self.children[int(self.choices.index("DNS & Hostname"))] dnsobj.setEtcResolv() signal.signal(signal.SIGUSR1, self.handle_sigusr1) dialog.display_dialog( self.child, widget.TextLabel("It is highly recommended to change default " "admin password."), "WARNING!") self.mainloop.run()
def callback_button(self, button): msg = 'this is a menu item, %s is called' % button.get_label() dialog.display_dialog(self, urwid.Text(msg), "Hello")
def callback(self, button): msg = 'this is a button' dialog.display_dialog(self, urwid.Text(msg), "Hello")
def main(self): #Disable kernel print messages. They make our UI ugly noout = open('/dev/null', 'w') subprocess.call(["sysctl", "-w", "kernel.printk=4 1 1 7"], stdout=noout, stderr=noout) text_header = (u"Fuel %s setup " u"Use Up/Down/Left/Right to navigate. F8 exits." % self.version) text_footer = (u"Status messages go here.") #Top and bottom lines of frame self.header = urwid.AttrWrap(urwid.Text(text_header), 'header') self.footer = urwid.AttrWrap(urwid.Text(text_footer), 'footer') #Prepare submodules loader = Loader(self) moduledir = "%s/modules" % (os.path.dirname(__file__)) self.children, self.choices = loader.load_modules(module_dir=moduledir) if len(self.children) == 0: import sys sys.exit(1) #Build list of choices excluding visible self.visiblechoices = [] for child, choice in zip(self.children, self.choices): if child.visible: self.visiblechoices.append(choice) self.menuitems = self.menu(u'Menu', self.visiblechoices) menufill = urwid.Filler(self.menuitems, 'top', 40) self.menubox = urwid.BoxAdapter(menufill, 40) self.child = self.children[0] self.childpage = self.child.screenUI() self.childfill = urwid.Filler(self.childpage, 'top', 22) self.childbox = urwid.BoxAdapter(self.childfill, 22) self.cols = urwid.Columns( [('fixed', 20, urwid.Pile( [urwid.AttrMap(self.menubox, 'bright'), urwid.Divider(" ")])), ('weight', 3, urwid.Pile( [urwid.Divider(" "), self.childbox, urwid.Divider(" ")]))], 1) self.listwalker = urwid.SimpleListWalker([self.cols]) #self.listwalker = urwid.TreeWalker([self.cols]) self.listbox = urwid.ListBox(self.listwalker) #listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content)) self.frame = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=self.header, footer=self.footer) palette = \ [ ('body', 'black', 'light gray', 'standout'), ('reverse', 'light gray', 'black'), ('header', 'white', 'dark red', 'bold'), ('important', 'dark blue', 'light gray', ('standout', 'underline')), ('editfc', 'white', 'dark blue', 'bold'), ('editbx', 'light gray', 'dark blue'), ('editcp', 'black', 'light gray', 'standout'), ('bright', 'dark gray', 'light gray', ('bold', 'standout')), ('buttn', 'black', 'dark cyan'), ('buttnf', 'white', 'dark blue', 'bold'), ('light gray', 'white', 'light gray', 'bold'), ('red', 'dark red', 'light gray', 'bold'), ('black', 'black', 'black', 'bold'), ] # use appropriate Screen class if urwid.web_display.is_web_request(): self.screen = urwid.web_display.Screen() else: self.screen = urwid.raw_display.Screen() def unhandled(key): if key == 'f8': raise urwid.ExitMainLoop() if key == 'shift tab': self.child.walker.tab_prev() if key == 'tab': self.child.walker.tab_next() self.mainloop = urwid.MainLoop(self.frame, palette, self.screen, unhandled_input=unhandled) #Initialize each module completely before any events are handled for child in reversed(self.children): self.setChildScreen(name=child.name) #Prepare DNS for resolution dnsobj = self.children[int(self.choices.index("DNS & Hostname"))] dnsobj.setEtcResolv() signal.signal(signal.SIGUSR1, self.handle_sigusr1) dialog.display_dialog( self.child, widget.TextLabel("It is highly recommended to change default " "admin password."), "WARNING!") self.mainloop.run()