def test_listbox(self, test_list): list_items = [] for position, test_id in enumerate(test_list): test_line_attr = self.get_list_item(test_id, position) list_items.append(test_line_attr) return urwid.ListBox(urwid.SimpleFocusListWalker(list_items))
def set_title(self, title): if len(title) == 0: return self.title.original_widget = urwid.ListBox( [urwid.Text(title, align="center")])
def BoxText(label): return urwid.ListBox(urwid.SimpleListWalker([urwid.Text(label)]))
def __init__(self, body, pos, ui, dbus=None): global daemon, wireless, wired self.thebackends = None self.backends = None self.wpadrivers = None self.thedrivers = None daemon = dbus['daemon'] wireless = dbus['wireless'] wired = dbus['wired'] width, height = ui.get_cols_rows() height -= 3 #width = 80 #height = 20 # Stuff that goes at the top header0_t = _('General Settings') header1_t = _('External Programs') header2_t = _('Advanced Settings') self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active', 'focus') self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus') self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus') title = ('Preferences') # Blank line _blank = urwid.Text('') #### #### Text in the widgets #### # General Settings net_cat_t = ('header', ('Network Interfaces')) wired_t = ('editcp', ('Wired Interface') + ': ') wless_t = ('editcp', ('Wireless Interface') + ':') always_show_wired_t = _('Always show wired interface') prefer_wired_t = _('Always switch to wired connection when available') global_dns_cat_t = ('header', _('Global DNS servers')) global_dns_t = ('editcp', _('Use global DNS servers')) dns_dom_t = ('editcp', ' ' + _('DNS domain') + ': ') search_dom_t = ('editcp', ' ' + _('Search domain') + ':') dns1_t = ('editcp', ' ' + _('DNS server') + ' 1: ') dns2_t = ('editcp', ' ' + _('DNS server') + ' 2: ') dns3_t = ('editcp', ' ' + _('DNS server') + ' 3: ') wired_auto_cat_t = ('header', _('Wired Autoconnect Settings')) wired_auto_1_t = _('Use default profile on wired autoconnect') wired_auto_2_t = _('Prompt for profile on wired autoconnect') wired_auto_3_t = _('Use last used profile on wired autoconnect') auto_reconn_cat_t = ('header', _('Automatic Reconnection')) auto_reconn_t = _('Automatically reconnect on connection loss') #### External Programs automatic_t = _('Automatic (recommended)') dhcp_header_t = ('header', _('DHCP Client')) # Automatic dhcp1_t = 'dhclient' dhcp2_t = 'dhcpcd' dhcp3_t = 'pump' dhcp4_t = 'udhcpc' wired_detect_header_t = ('header', _('Wired Link Detection')) wired1_t = 'ethtool' wired2_t = 'mii-tool' flush_header_t = ('header', _('Route Table Flushing')) flush1_t = 'ip' flush2_t = 'route' #### Advanced Settings wpa_cat_t = ('header', _('WPA Supplicant')) wpa_t = ('editcp', 'Driver:') wpa_list = [] wpa_warn_t = ( 'important', _('You should almost always use wext as the WPA supplicant driver') ) backend_cat_t = ('header', _('Backend')) backend_t = _('Backend') + ':' backend_list = [] debug_cat_t = ('header', _('Debugging')) debug_mode_t = _('Enable debug mode') wless_cat_t = ('header', _('Wireless Interface')) use_dbm_t = _('Use dBm to measure signal strength') verify_ap_t = \ _('Ping static gateways after connecting to verify association') #### #### UI Widgets #### # General Settings self.net_cat = urwid.Text(net_cat_t) self.wired_edit = \ urwid.AttrWrap(urwid.Edit(wired_t), 'editbx', 'editfc') self.wless_edit = \ urwid.AttrWrap(urwid.Edit(wless_t), 'editbx', 'editfc') self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t) self.global_dns_cat = urwid.Text(global_dns_cat_t) # Default the global DNS settings to off. They will be reenabled later # if so required. global_dns_state = False self.global_dns_checkb = urwid.CheckBox( global_dns_t, global_dns_state, on_state_change=self.global_dns_trigger) self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state) self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state) self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state) self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state) self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state) self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t) self.wired_auto_l = [] self.wired_auto_cat = urwid.Text(wired_auto_cat_t) self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l, wired_auto_1_t) self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l, wired_auto_2_t) self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l, wired_auto_3_t) self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t) self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t) generalLB = urwid.ListBox([ self.net_cat, self.wless_edit, # _blank, self.wired_edit, self.always_show_wired_checkb, self.prefer_wired_chkbx, _blank, self.global_dns_cat, self.global_dns_checkb, # _blank, self.search_dom, self.dns_dom, self.dns1, self.dns2, self.dns3, _blank, self.wired_auto_cat, self.wired_auto_1, self.wired_auto_2, self.wired_auto_3, _blank, self.auto_reconn_cat, self.auto_reconn_checkb ]) #### External Programs tab automatic_t = _('Automatic (recommended)') self.dhcp_header = urwid.Text(dhcp_header_t) self.dhcp_l = [] # Order of these is flipped in the actual interface, # (2, 3, 1 -> dhcpcd, pump, dhclient), because dhclient often doesn't # like to work on several distros. self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t) self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t) self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t) self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t) self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t) self.dhcp_l = [ self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4 ] self.wired_l = [] self.wired_detect_header = urwid.Text(wired_detect_header_t) self.wired0 = urwid.RadioButton(self.wired_l, automatic_t) self.wired1 = DynRadioButton(self.wired_l, wired1_t) self.wired2 = DynRadioButton(self.wired_l, wired2_t) self.wired_l = [self.wired0, self.wired1, self.wired2] self.flush_l = [] self.flush_header = urwid.Text(flush_header_t) self.flush0 = urwid.RadioButton(self.flush_l, automatic_t) self.flush1 = DynRadioButton(self.flush_l, flush1_t) self.flush2 = DynRadioButton(self.flush_l, flush2_t) self.flush_l = [self.flush0, self.flush1, self.flush2] externalLB = urwid.ListBox([ self.dhcp_header, self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1, self.dhcp4, _blank, self.wired_detect_header, self.wired0, self.wired1, self.wired2, _blank, self.flush_header, self.flush0, self.flush1, self.flush2 ]) #### Advanced settings self.wpa_cat = urwid.Text(wpa_cat_t) self.wpa_cbox = ComboBox(wpa_t) self.wpa_warn = urwid.Text(wpa_warn_t) self.backend_cat = urwid.Text(backend_cat_t) self.backend_cbox = ComboBox(backend_t) self.debug_cat = urwid.Text(debug_cat_t) self.debug_mode_checkb = urwid.CheckBox(debug_mode_t) self.wless_cat = urwid.Text(wless_cat_t) self.use_dbm_checkb = urwid.CheckBox(use_dbm_t) self.verify_ap_checkb = urwid.CheckBox(verify_ap_t) advancedLB = urwid.ListBox([ self.wpa_cat, self.wpa_cbox, self.wpa_warn, _blank, self.backend_cat, self.backend_cbox, _blank, self.debug_cat, self.debug_mode_checkb, _blank, self.wless_cat, self.use_dbm_checkb, _blank, self.verify_ap_checkb, _blank ]) headerList = [self.header0, self.header1, self.header2] lbList = [generalLB, externalLB, advancedLB] self.tab_map = { self.header0: generalLB, self.header1: externalLB, self.header2: advancedLB } #self.load_settings() self.tabs = TabColumns(headerList, lbList, _('Preferences')) # pylint: disable-msg=E1101 self.__super.__init__(self.tabs)
def __init__(self): self.ui = None self.body = None self.wired = None self.networkid = None self.encryption_info = None self.encryption_combo = None self.encrypt_types = None self.encryption_chkbox = None static_ip_t = _('Use Static IPs') ip_t = ('editcp', _('IP') + ': ') netmask_t = ('editcp', _('Netmask') + ':') gateway_t = ('editcp', _('Gateway') + ':') use_static_dns_t = _('Use Static DNS') use_global_dns_t = _('Use global DNS servers') dns_dom_t = ('editcp', _('DNS domain') + ': ') search_dom_t = ('editcp', _('Search domain') + ':') dns1_t = ('editcp', _('DNS server') + ' 1' + ':' + ' ' * 8) dns2_t = ('editcp', _('DNS server') + ' 2' + ':' + ' ' * 8) dns3_t = ('editcp', _('DNS server') + ' 3' + ':' + ' ' * 8) use_dhcp_h_t = _('Use DHCP Hostname') dhcp_h_t = ('editcp', _('DHCP Hostname') + ': ') cancel_t = _('Cancel') ok_t = _('OK') self.static_ip_cb = urwid.CheckBox( static_ip_t, on_state_change=self.static_ip_toggle) self.ip_edit = DynWrap(urwid.Edit(ip_t), False) self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False) self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False) self.static_dns_cb = DynWrap( urwid.CheckBox(use_static_dns_t, on_state_change=self.dns_toggle), True, ('body', 'editnfc'), None) self.global_dns_cb = DynWrap( urwid.CheckBox(use_global_dns_t, on_state_change=self.dns_toggle), False, ('body', 'editnfc'), None) self.checkb_cols = urwid.Columns( [self.static_dns_cb, self.global_dns_cb]) self.dns_dom_edit = DynWrap(urwid.Edit(dns_dom_t), False) self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False) self.dns1 = DynWrap(urwid.Edit(dns1_t), False) self.dns2 = DynWrap(urwid.Edit(dns2_t), False) self.dns3 = DynWrap(urwid.Edit(dns3_t), False) self.use_dhcp_h = urwid.CheckBox( use_dhcp_h_t, False, on_state_change=self.use_dhcp_h_toggle) self.dhcp_h = DynWrap(urwid.Edit(dhcp_h_t), False) _blank = urwid.Text('') walker = urwid.SimpleListWalker([ self.static_ip_cb, self.ip_edit, self.netmask_edit, self.gateway_edit, _blank, self.checkb_cols, self.dns_dom_edit, self.search_dom_edit, self.dns1, self.dns2, self.dns3, _blank, self.use_dhcp_h, self.dhcp_h, _blank ]) self._listbox = urwid.ListBox(walker) self._frame = urwid.Frame(self._listbox) # pylint: disable-msg=E1101 self.__super.__init__(self._frame)
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) self.menuitems = self.menu(u'Menu', self.choices) 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.choices): self.setChildScreen(name=child) #Prepare DNS for resolution dnsobj = self.children[int(self.choices.index("DNS & Hostname"))] dnsobj.setEtcResolv() self.mainloop.run()
def __init__(self, conversation_list, on_select, keybindings): list_walker = ConversationListWalker(conversation_list, on_select) list_box = urwid.ListBox(list_walker) widget = urwid.Padding(list_box, left=2, right=2) super().__init__(widget) self._keys = keybindings
def edit_config(ui, conf_dict): import urwid old_conf_dict = conf_dict.copy() def _update_theme(): ui.setup_palette(ui.screen) ui.screen.clear() def _update_line_numbers(): for sl in ui.source: sl._invalidate() def _update_prompt_on_quit(): pass def _update_hide_cmdline_win(): ui.update_cmdline_win() def _update_current_stack_frame(): ui.update_stack() def _update_stringifier(): import pudb.var_view pudb.var_view.custom_stringifier_dict = {} ui.update_var_view() def _update_default_variables_access_level(): ui.update_var_view() def _update_wrap_variables(): ui.update_var_view() def _update_config(check_box, new_state, option_newvalue): option, newvalue = option_newvalue new_conf_dict = {option: newvalue} if option == "theme": # only activate if the new state of the radio button is 'on' if new_state: if newvalue is None: # Select the custom theme entry dialog lb.set_focus(lb_contents.index(theme_edit_list_item)) return conf_dict.update(theme=newvalue) _update_theme() elif option == "line_numbers": new_conf_dict["line_numbers"] = not check_box.get_state() conf_dict.update(new_conf_dict) _update_line_numbers() elif option == "prompt_on_quit": new_conf_dict["prompt_on_quit"] = not check_box.get_state() conf_dict.update(new_conf_dict) _update_prompt_on_quit() elif option == "hide_cmdline_win": new_conf_dict["hide_cmdline_win"] = not check_box.get_state() conf_dict.update(new_conf_dict) _update_hide_cmdline_win() elif option == "current_stack_frame": # only activate if the new state of the radio button is 'on' if new_state: conf_dict.update(new_conf_dict) _update_current_stack_frame() elif option == "stringifier": # only activate if the new state of the radio button is 'on' if new_state: if newvalue is None: lb.set_focus(lb_contents.index(stringifier_edit_list_item)) return conf_dict.update(stringifier=newvalue) _update_stringifier() elif option == "default_variables_access_level": # only activate if the new state of the radio button is 'on' if new_state: conf_dict.update(default_variables_access_level=newvalue) _update_default_variables_access_level() elif option == "wrap_variables": new_conf_dict["wrap_variables"] = not check_box.get_state() conf_dict.update(new_conf_dict) _update_wrap_variables() heading = urwid.Text("This is the preferences screen for PuDB. " "Hit Ctrl-P at any time to get back to it.\n\n" "Configuration settings are saved in " "$HOME/.config/pudb or $XDG_CONFIG_HOME/pudb " "environment variable. If both variables are not set " "configurations settings will not be saved.\n") cb_line_numbers = urwid.CheckBox("Show Line Numbers", bool(conf_dict["line_numbers"]), on_state_change=_update_config, user_data=("line_numbers", None)) cb_prompt_on_quit = urwid.CheckBox("Prompt before quitting", bool(conf_dict["prompt_on_quit"]), on_state_change=_update_config, user_data=("prompt_on_quit", None)) hide_cmdline_win = urwid.CheckBox("Hide command line (Ctrl-X) window " "when not in use", bool(conf_dict["hide_cmdline_win"]), on_state_change=_update_config, user_data=("hide_cmdline_win", None)) # {{{ shells shell_info = urwid.Text("This is the shell that will be " "used when you hit '!'.\n") shells = ["internal", "classic", "ipython", "ipython_kernel", "bpython", "ptpython", "ptipython"] known_shell = conf_dict["shell"] in shells shell_edit = urwid.Edit(edit_text=conf_dict["custom_shell"]) shell_edit_list_item = urwid.AttrMap(shell_edit, "value") shell_rb_group = [] shell_rbs = [ urwid.RadioButton(shell_rb_group, name, conf_dict["shell"] == name) for name in shells]+[ urwid.RadioButton(shell_rb_group, "Custom:", not known_shell, on_state_change=_update_config, user_data=("shell", None)), shell_edit_list_item, urwid.Text("\nTo use a custom shell, see example-shell.py " "in the pudb distribution. Enter the full path to a " "file like it in the box above. '~' will be expanded " "to your home directory. The file should contain a " "function called pudb_shell(_globals, _locals) " "at the module level. See the PuDB documentation for " "more information."), ] # }}} # {{{ themes from pudb.theme import THEMES known_theme = conf_dict["theme"] in THEMES theme_rb_group = [] theme_edit = urwid.Edit(edit_text=conf_dict["custom_theme"]) theme_edit_list_item = urwid.AttrMap(theme_edit, "value") theme_rbs = [ urwid.RadioButton(theme_rb_group, name, conf_dict["theme"] == name, on_state_change=_update_config, user_data=("theme", name)) for name in THEMES]+[ urwid.RadioButton(theme_rb_group, "Custom:", not known_theme, on_state_change=_update_config, user_data=("theme", None)), theme_edit_list_item, urwid.Text("\nTo use a custom theme, see example-theme.py in the " "pudb distribution. Enter the full path to a file like it in " "the box above. '~' will be expanded to your home directory. " "Note that a custom theme will not be applied until you close " "this dialog."), ] # }}} # {{{ stack stack_rb_group = [] stack_opts = ["top", "bottom"] stack_info = urwid.Text("Show the current stack frame at the\n") stack_rbs = [ urwid.RadioButton(stack_rb_group, name, conf_dict["current_stack_frame"] == name, on_state_change=_update_config, user_data=("current_stack_frame", name)) for name in stack_opts ] # }}} # {{{ stringifier from pudb.var_view import STRINGIFIERS stringifier_opts = list(STRINGIFIERS.keys()) known_stringifier = conf_dict["stringifier"] in stringifier_opts stringifier_rb_group = [] stringifier_edit = urwid.Edit(edit_text=conf_dict["custom_stringifier"]) stringifier_info = urwid.Text( "This is the default function that will be called on variables in the " "variables list. You can also change this on a per-variable basis by " "selecting a variable and typing 'e' to edit the variable's display " "settings, or by typing one of d/t/r/s/i/c. Note that str and repr will " "be slower than the default, type, or id stringifiers.\n") stringifier_edit_list_item = urwid.AttrMap(stringifier_edit, "value") stringifier_rbs = [ urwid.RadioButton(stringifier_rb_group, name, conf_dict["stringifier"] == name, on_state_change=_update_config, user_data=("stringifier", name)) for name in stringifier_opts ]+[ urwid.RadioButton(stringifier_rb_group, "Custom:", not known_stringifier, on_state_change=_update_config, user_data=("stringifier", None)), stringifier_edit_list_item, urwid.Text("\nTo use a custom stringifier, see " "example-stringifier.py in the pudb distribution. Enter the " "full path to a file like it in the box above. " "'~' will be expanded to your home directory. " "The file should contain a function called pudb_stringifier() " "at the module level, which should take a single argument and " "return the desired string form of the object passed to it. " "Note that if you choose a custom stringifier, the variables " "view will not be updated until you close this dialog."), ] # }}} # {{{ variables access level default_variables_access_level_opts = ["public", "private", "all"] default_variables_access_level_rb_group = [] default_variables_access_level_info = urwid.Text( "Set the default attribute visibility " "of variables in the variables list.\n" "\nNote that you can change this option on " "a per-variable basis by selecting the " "variable and pressing '*'.") default_variables_access_level_rbs = [ urwid.RadioButton(default_variables_access_level_rb_group, name, conf_dict["default_variables_access_level"] == name, on_state_change=_update_config, user_data=("default_variables_access_level", name)) for name in default_variables_access_level_opts ] # }}} # {{{ wrap variables cb_wrap_variables = urwid.CheckBox("Wrap variables", bool(conf_dict["wrap_variables"]), on_state_change=_update_config, user_data=("wrap_variables", None)) wrap_variables_info = urwid.Text("\nNote that you can change this option on " "a per-variable basis by selecting the " "variable and pressing 'w'.") # }}} # {{{ display display_info = urwid.Text("What driver is used to talk to your terminal. " "'raw' has the most features (colors and highlighting), " "but is only correct for " "XTerm and terminals like it. 'curses' " "has fewer " "features, but it will work with just about any terminal. 'auto' " "will attempt to pick between the two based on availability and " "the $TERM environment variable.\n\n" "Changing this setting requires a restart of PuDB.") displays = ["auto", "raw", "curses"] display_rb_group = [] display_rbs = [ urwid.RadioButton(display_rb_group, name, conf_dict["display"] == name) for name in displays] # }}} lb_contents = ( [heading] + [urwid.AttrMap(urwid.Text("General:\n"), "group head")] + [cb_line_numbers] + [cb_prompt_on_quit] + [hide_cmdline_win] + [urwid.AttrMap(urwid.Text("\nShell:\n"), "group head")] + [shell_info] + shell_rbs + [urwid.AttrMap(urwid.Text("\nTheme:\n"), "group head")] + theme_rbs + [urwid.AttrMap(urwid.Text("\nStack Order:\n"), "group head")] + [stack_info] + stack_rbs + [urwid.AttrMap(urwid.Text("\nVariable Stringifier:\n"), "group head")] + [stringifier_info] + stringifier_rbs + [urwid.AttrMap(urwid.Text("\nVariables Attribute Visibility:\n"), "group head")] + [default_variables_access_level_info] + default_variables_access_level_rbs + [urwid.AttrMap(urwid.Text("\nWrap Variables:\n"), "group head")] + [cb_wrap_variables] + [wrap_variables_info] + [urwid.AttrMap(urwid.Text("\nDisplay driver:\n"), "group head")] + [display_info] + display_rbs ) lb = urwid.ListBox(urwid.SimpleListWalker(lb_contents)) if ui.dialog(lb, [ ("OK", True), ("Cancel", False), ], title="Edit Preferences"): # Only update the settings here that instant-apply (above) doesn't take # care of. # if we had a custom theme, it wasn't updated live if theme_rb_group[-1].state: newvalue = theme_edit.get_edit_text() conf_dict.update(theme=newvalue, custom_theme=newvalue) _update_theme() # Ditto for custom stringifiers if stringifier_rb_group[-1].state: newvalue = stringifier_edit.get_edit_text() conf_dict.update(stringifier=newvalue, custom_stringifier=newvalue) _update_stringifier() if shell_rb_group[-1].state: newvalue = shell_edit.get_edit_text() conf_dict.update(shell=newvalue, custom_shell=newvalue) else: for shell, shell_rb in zip(shells, shell_rbs): if shell_rb.get_state(): conf_dict["shell"] = shell for display, display_rb in zip(displays, display_rbs): if display_rb.get_state(): conf_dict["display"] = display else: # The user chose cancel, revert changes conf_dict.update(old_conf_dict) _update_theme() # _update_line_numbers() is equivalent to _update_theme() _update_current_stack_frame() _update_stringifier()
def _load_widget(self): widgets = [urwid.AttrWrap(SelectableText(o, wrap='ellipsis'), None, 'focus') for o in self._options] listbox = urwid.ListBox(urwid.SimpleListWalker(widgets)) return urwid.AttrWrap(listbox, 'popup')
def build(self, ui, results): self.ui = ui widgets = urwid.SimpleListWalker([]) if (results == None): return urwid.Text('Ничего не найдено') if (results['best_type'] == 'track'): widgets.append( urwid.LineBox(self.build_track(results['best']), 'Лучший результат')) if (results['best_type'] == 'artist'): widgets.append( urwid.LineBox( UiButton(results['best'].name, on_press=self.on_artist_click, user_data=results['best']), 'Лучший результат')) if (results['best_type'] == 'playlist'): widgets.append( urwid.LineBox( urwid.Pile([ UiButton(results['best'].title, on_press=self.open_playlist, user_data=results['best']), urwid.Divider(), ]), 'Лучший результат')) if (results['best_type'] == 'album'): widgets.append( urwid.LineBox( urwid.Pile([ UiButton('{title} {artists}'.format( title=results['best'].title, artists=', '.join( map(lambda e: e.name, results['best']._artists))), on_press=self.on_album_click, user_data=results['best'], normalColor='album'), urwid.Divider(), ]))) if (len(results['tracks']) > 0): self.tracks = results['tracks'] widgets.append(urwid.Divider('═')) widgets.append(urwid.Text('Треки', align='center')) for track in results['tracks']: widgets.append(self.build_track(track)) widgets.append(urwid.Divider('_')) widgets.append(urwid.Divider()) if (len(results['artists']) > 0): widgets.append(urwid.Divider('═')) widgets.append(urwid.Text('Исполнители', align='center')) for artist in results['artists']: widgets.append( urwid.Pile([ UiButton(artist.name, on_press=self.on_artist_click, user_data=artist), urwid.Divider(), ])) widgets.append(urwid.Divider('_')) widgets.append(urwid.Divider()) if (len(results['albums']) > 0): widgets.append(urwid.Divider('═')) widgets.append(urwid.Text('Альбомы', align='center')) for album in results['albums']: widgets.append( urwid.Pile([ UiButton('{title} {artists}'.format( title=album.title, artists=', '.join( map(lambda e: e.name, album._artists))), on_press=self.on_album_click, user_data=album, normalColor='album'), urwid.Divider(), ])) widgets.append(urwid.Divider('_')) widgets.append(urwid.Divider()) if (len(results['playlists']) > 0): widgets.append(urwid.Divider('═')) widgets.append(urwid.Text('Плейлисты', align='center')) for playlist in results['playlists']: widgets.append( urwid.Pile([ UiButton( playlist.title, on_press=self.open_playlist, user_data=playlist, ), urwid.Divider(), ])) widgets.append(urwid.Divider('_')) widgets.append(urwid.Divider()) return urwid.LineBox( urwid.BoxAdapter(urwid.ListBox(widgets), height=self.ui.size() - 10))
self.row = urwid.Columns([('weight', 0.1, self.label), ('weight', 0.5, self.raw), ('weight', 0.1, self.label), ('weight', 0.5, self.level)], dividechars=1) for i in range(1, 128): ch = VisualChannel(i) channel_ui.append(ch) if 0 < i <= 8 or 16 < i <= 24 or 32 < i <= 40 or 48 < i <= 56: rows.append(ch.row) rows.append(ui_log) page = urwid.ListBox(urwid.SimpleFocusListWalker(rows)) loop = urwid.MainLoop(page, palette, unhandled_input=handle_input) LOG_SIZE = 16 log_buffer = collections.deque(maxlen=LOG_SIZE) def log(msg): global log_buffer log_buffer.append("[%s] %s" % (time.strftime("%I:%M:%S %p", time.localtime()), msg)) ui_log.set_text("\n".join(log_buffer)) for i in range(0, LOG_SIZE): log('.')
def refresh(loop=None, data=None): #self.setup_view() #loop.widget = self.view loop.set_alarm_in(3, refresh) col.contents[0] = (urwid.Filler(urwid.Text(str(Tim()))), col.options()) clock_txt = urwid.Text(Tim()) view = urwid.Padding(clock_txt, 'center') view = urwid.AttrMap(view, 'body') view = urwid.Filler(view, 'middle') view = urwid.Pile([view, view, view, view, view, view]) col = urwid.Columns([view, view]) col2 = urwid.Columns([view, view]) w = urwid.ListBox(urwid.SimpleListWalker([clock_txt])) loop = urwid.MainLoop(col, palette=[('body', 'dark cyan', '')], unhandled_input=keypress) loop.set_alarm_in(1, refresh) loop.run() class Refresh: def setup_view(self): A = Tim() self.view = w def main(self): #self.setup_view()
def flowdetails(state, flow): text = [] cc = flow.client_conn sc = flow.server_conn req = flow.request resp = flow.response if sc is not None: text.append(urwid.Text([("head", "Server Connection:")])) parts = [ ["Address", repr(sc.address)], ["Resolved Address", repr(sc.ip_address)], ] text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) c = sc.cert if c: text.append(urwid.Text([("head", "Server Certificate:")])) parts = [["Type", "%s, %s bits" % c.keyinfo], ["SHA1 digest", c.digest("sha1")], ["Valid to", str(c.notafter)], ["Valid from", str(c.notbefore)], ["Serial", str(c.serial)], [ "Subject", urwid.BoxAdapter( urwid.ListBox( common.format_keyvals(c.subject, key="highlight", val="text")), len(c.subject)) ], [ "Issuer", urwid.BoxAdapter( urwid.ListBox( common.format_keyvals(c.issuer, key="highlight", val="text")), len(c.issuer)) ]] if c.altnames: parts.append(["Alt names", ", ".join(c.altnames)]) text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) if cc is not None: text.append(urwid.Text([("head", "Client Connection:")])) parts = [ ["Address", repr(cc.address)], ] text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) parts = [] if cc is not None and cc.timestamp_start: parts.append([ "Client conn. established", maybe_timestamp(cc, "timestamp_start") ]) if cc.ssl_established: parts.append([ "Client conn. TLS handshake", maybe_timestamp(cc, "timestamp_ssl_setup") ]) if sc is not None and sc.timestamp_start: parts.append( ["Server conn. initiated", maybe_timestamp(sc, "timestamp_start")]) parts.append([ "Server conn. TCP handshake", maybe_timestamp(sc, "timestamp_tcp_setup") ]) if sc.ssl_established: parts.append([ "Server conn. TLS handshake", maybe_timestamp(sc, "timestamp_ssl_setup") ]) if req is not None and req.timestamp_start: parts.append( ["First request byte", maybe_timestamp(req, "timestamp_start")]) parts.append( ["Request complete", maybe_timestamp(req, "timestamp_end")]) if resp is not None and resp.timestamp_start: parts.append( ["First response byte", maybe_timestamp(resp, "timestamp_start")]) parts.append( ["Response complete", maybe_timestamp(resp, "timestamp_end")]) if parts: # sort operations by timestamp parts = sorted(parts, key=lambda p: p[1]) text.append(urwid.Text([("head", "Timing:")])) text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) return searchable.Searchable(state, text)
def __init__(self): self._text_widget = urwid.AttrMap( urwid.ListBox( urwid.SimpleListWalker( [urwid.Text(DetailedHelpPage.HELP_TEXT)])), "body") super().__init__(self._text_widget)
def widget(self, txt): cols, _ = self.master.ui.get_cols_rows() return urwid.ListBox( [urwid.Text(i) for i in textwrap.wrap(txt, cols)] )
def main(self): global DATA text_header = (u"OpenChronos config \u2503 " u"UP / DOWN / PAGE UP / PAGE DOWN scroll. F8 aborts.") self.list_content = list_content = [] for key, field in DATA.iteritems(): # generate gui forms depending on type self.generate_widget(key, field) # rescan widgets and disable/enable them based on their dependencies for key, wid in WIDMAP.iteritems(): if not hasattr(wid, '_widget'): continue wid = wid._widget if isinstance(wid, urwid.Edit): val = wid.get_edit_text() elif isinstance(wid, urwid.CheckBox): val = wid.get_state() else: continue widget_changed_callback(wid, val) def ok_pressed(*args, **kwargs): raise urwid.ExitMainLoop() def abort_pressed(*args, **kwargs): sys.exit(0) list_content.append(urwid.Divider(div_char=u"\u2550", top=1, bottom=1)) list_content.append( urwid.Padding( urwid.GridFlow([ urwid.AttrWrap(urwid.Button("Save", ok_pressed), 'opt', 'optsel'), urwid.AttrWrap(urwid.Button("Abort", abort_pressed), 'opt', 'optsel') ], 15, 4, 4, 'center'), ('fixed left', 4), ('fixed right', 3))) header = urwid.AttrWrap(urwid.Text(text_header), 'header') walker = HelpListWalker(self, list_content) listbox = urwid.ListBox(walker) self.help_widget = urwid.Text("") footer = urwid.AttrWrap(self.help_widget, 'footer') frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header, footer=footer) screen = urwid.raw_display.Screen() palette = [ ('header', 'white', 'dark red', 'bold'), ('info', 'black', 'dark cyan'), ('body', 'black', 'dark gray'), ('optsel', 'white', 'dark blue'), ('opt', 'black', 'light gray'), ('optd', 'black', 'dark gray'), ] def unhandled(key): if key == 'f8': #raise urwid.ExitMainLoop() sys.exit(0) urwid.MainLoop(frame, palette, screen, unhandled_input=unhandled).run()
def runscript(mainpyfile, args=None, pre_run="", steal_output=False): dbg = _get_debugger(steal_output=steal_output) # Note on saving/restoring sys.argv: it's a good idea when sys.argv was # modified by the script being debugged. It's a bad idea when it was # changed by the user from the command line. The best approach would be to # have a "restart" command which would allow explicit specification of # command line arguments. import sys if args is not None: prev_sys_argv = sys.argv[:] sys.argv = [mainpyfile] + args # replace pudb's dir with script's dir in front of module search path. from os.path import dirname prev_sys_path = sys.path[:] sys.path[0] = dirname(mainpyfile) while True: if pre_run: from subprocess import call retcode = call(pre_run, close_fds=True, shell=True) if retcode: print("*** WARNING: pre-run process exited with code %d." % retcode) raw_input("[Hit Enter]") status_msg = "" try: dbg._runscript(mainpyfile) except SystemExit: se = sys.exc_info()[1] status_msg = "The debuggee exited normally with " \ "status code %s.\n\n" % se.code except: dbg.post_mortem = True dbg.interaction(None, sys.exc_info()) while True: import urwid pre_run_edit = urwid.Edit("", pre_run) if not CONFIG["prompt_on_quit"]: return result = dbg.ui.call_with_ui(dbg.ui.dialog, urwid.ListBox(urwid.SimpleListWalker([urwid.Text( "Your PuDB session has ended.\n\n%s" "Would you like to quit PuDB or restart your program?\n" "You may hit 'q' to quit." % status_msg), urwid.Text("\n\nIf you decide to restart, this command " "will be run prior to actually restarting:"), urwid.AttrMap(pre_run_edit, "value") ])), [ ("Restart", "restart"), ("Examine", "examine"), ("Quit", "quit"), ], focus_buttons=True, bind_enter_esc=False, title="Finished", extra_bindings=[ ("q", "quit"), ("esc", "examine"), ]) if result == "quit": return if result == "examine": dbg.post_mortem = True dbg.interaction(None, sys.exc_info(), show_exc_dialog=False) if result == "restart": break pre_run = pre_run_edit.get_edit_text() dbg.restart() if args is not None: sys.argv = prev_sys_argv sys.path = prev_sys_path
def test5set_focus_valign(self): T, E = urwid.Text, urwid.Edit lbox = urwid.ListBox(urwid.SimpleFocusListWalker([T(''), T('')])) lbox.set_focus_valign('middle')
def _make_body(self) -> 'urwid.Columns': commits = urwid.ListBox(self.commit_list) feedback = urwid.ListBox(self.feedback_box) return urwid.Columns([commits, feedback])
def test_listbox_pile(self): lb = urwid.ListBox(urwid.SimpleListWalker([urwid.Pile([])])) lb.render((40, 10), focus=True)
def test_listbox(self): self.wstest(urwid.ListBox(urwid.SimpleListWalker([]))) self.wstest( urwid.ListBox(urwid.SimpleListWalker([urwid.Text("hello")])))
def main(): text_header = (u"hi! " u"UP / DOWN / PAGE UP / PAGE DOWN scroll. F8 exits.") Radio_Text = [ u"Select ", ('important', u"one"), ] Multiselect_Text = [ u"Select ", ('important', u"many"), ] MultiSelect_Options = [ u"Wax", u"Wash", u"Buff", u"Clear Coat", u"Dry", u"Racing Stripe" ] Radio_Options = [u"opt1", u"opt2", u"opt3"] def button_press(button): frame.footer = urwid.AttrWrap( urwid.Text([u"Pressed: ", button.get_label()]), 'header') radio_button_group = [] AttrWraps_list = [ urwid.AttrWrap(urwid.CheckBox(txt), 'buttn', 'buttnf') for txt in MultiSelect_Options ] blank = urwid.Divider() listbox_content = [ blank, urwid.Padding(urwid.Text(Radio_Text), left=2, right=2, min_width=20), blank, urwid.Padding(urwid.GridFlow([ urwid.AttrWrap(urwid.RadioButton(radio_button_group, txt), 'buttn', 'buttnf') for txt in Radio_Options ], 23, 7, 1, 'left'), left=3, right=3, min_width=20), blank, urwid.Padding(urwid.Text(Multiselect_Text), left=2, right=2, min_width=20), blank, urwid.Padding(urwid.GridFlow([ urwid.AttrWrap(urwid.CheckBox(txt), 'buttn', 'buttnf') for txt in MultiSelect_Options ], 10, 3, 1, 'left'), left=4, right=3, min_width=10), blank, blank, ] header = urwid.AttrWrap(urwid.Text(text_header), 'header') listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content)) frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header) 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'), ] # use appropriate Screen class if urwid.web_display.is_web_request(): screen = urwid.web_display.Screen() else: screen = urwid.raw_display.Screen() def unhandled(key): if key == 'f8': raise urwid.ExitMainLoop() if key == 'f5': txt = urwid.Text( str({x.get_label(): x.get_state() for x in AttrWraps_list})) fill = urwid.Filler(txt, 'top') loop = urwid.MainLoop(fill) loop.run() urwid.MainLoop(frame, palette, screen, unhandled_input=unhandled).run()
def main(self): # this program use frame as the topmost widget, header and footer # play roles of the top and bottom lines of the frame # field which need to choose language language_field = { 'text_header' : None, 'text_footer' : None, 'menu_label' : None } #language choose language_field = LanguageType.choose_language("DASONEMENU", LanguageType.CHINESE, language_field=language_field) # replace $ with dasonemenu version language_field['text_header'] = language_field['text_header'].replace('$', self.version) self.header = urwid.AttrMap(urwid.Text(language_field['text_header']), 'header') self.footer = urwid.AttrMap(urwid.Text(language_field['text_footer']), 'footer') self.children = [] # load the modules will be used, # every module is one child # you can extend the num of modules by modify modules.__init__.py file for clsobj in modules.__all__: modobj = clsobj(self, LanguageType.CHINESE) # default language is chinese self.children.append(modobj) if len(self.children) == 0: log.debug('there is no available modules, dsMenu exit') sys.exit(1) # build list of choices self.choices = [m.name for m in self.children] # build list of visible choices self.visiblechoices = [] for child, choice in zip(self.children, self.choices): if child.visible: self.visiblechoices.append(choice) # finish menu box self.menuitems = self.menu(language_field['menu_label'], self.visiblechoices) menufill = urwid.Filler(self.menuitems, 'top', 40) self.menubox = urwid.BoxAdapter(menufill, 40) # finish child box self.child = self.children[0] # use DaSone user modules default self.childpage = self.child.screenUI() self.childfill = urwid.Filler(self.childpage, 'top', 22) self.childbox = urwid.BoxAdapter(self.childfill, 22) # create col widget contain menubox and child box self.cols = urwid.Columns( [ ('fixed', 20, urwid.Pile([ urwid.AttrMap(self.menubox, 'body'), urwid.Divider(" ")])), ('weight', 3, urwid.Pile([ blank, self.childbox, blank])) ], 1) # top second widget -- Listbox self.listwalker = urwid.SimpleListWalker([self.cols]) self.listbox = urwid.ListBox(self.listwalker) #topmost widget --Frame self.frame = urwid.Frame(urwid.AttrMap(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', 'light 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'), ('padding', 'white', 'black', 'bold'), ('filler', 'white', '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() # handle unexpected signal def handle_extra_input(key): if key == 'f12': raise urwid.ExitMainLoop() if key == 'shift tab': self.child.walker.tab_prev() if key == 'tab': self.child.walker.tab_next() # begin mainloop self.mainloop = urwid.MainLoop(self.frame, palette, self.screen, unhandled_input=handle_extra_input) self.mainloop.run()
def __init__(self, caption, choices): header = urwid.AttrMap(urwid.Text(caption, align='center'), 'heading') self._w = urwid.AttrMap( urwid.ListBox( urwid.SimpleFocusListWalker([header, urwid.Divider()] + choices)), 'options', focus_map)
def flowtext(self): text = [] title = urwid.Text("Flow details") title = urwid.Padding(title, align="left", width=("relative", 100)) title = urwid.AttrWrap(title, "heading") text.append(title) if self.flow.server_conn: text.append(urwid.Text([("head", "Server Connection:")])) sc = self.flow.server_conn parts = [ ["Address", "%s:%s" % sc.address()], ["Start time", utils.format_timestamp(sc.timestamp_start)], [ "End time", utils.format_timestamp(sc.timestamp_end) if sc.timestamp_end else "active" ], ] text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) c = self.flow.server_conn.cert if c: text.append(urwid.Text([("head", "Server Certificate:")])) parts = [["Type", "%s, %s bits" % c.keyinfo], ["SHA1 digest", c.digest("sha1")], ["Valid to", str(c.notafter)], ["Valid from", str(c.notbefore)], ["Serial", str(c.serial)], [ "Subject", urwid.BoxAdapter( urwid.ListBox( common.format_keyvals(c.subject, key="highlight", val="text")), len(c.subject)) ], [ "Issuer", urwid.BoxAdapter( urwid.ListBox( common.format_keyvals(c.issuer, key="highlight", val="text")), len(c.issuer)) ]] if c.altnames: parts.append(["Alt names", ", ".join(c.altnames)]) text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) if self.flow.client_conn: text.append(urwid.Text([("head", "Client Connection:")])) cc = self.flow.client_conn parts = [ ["Address", "%s:%s" % cc.address()], ["Start time", utils.format_timestamp(cc.timestamp_start)], # ["Requests", "%s"%cc.requestcount], [ "End time", utils.format_timestamp(cc.timestamp_end) if cc.timestamp_end else "active" ], ] text.extend( common.format_keyvals(parts, key="key", val="text", indent=4)) return text
def main(self): self.fields = {} text_header = (u"OpenChronos config \u2503 " u"UP / DOWN / PAGE UP / PAGE DOWN scroll. F8 aborts.") self.list_content = list_content = [] for key,field in DATA.iteritems(): # generate gui forms depending on type if field.get("type", "bool") == "bool": f = urwid.AttrWrap(urwid.CheckBox(field["name"], state=field["value"]),'buttn','buttnf') f._datafield = field self.fields[key] = f list_content.append(f) elif field["type"] == "choices": try: value = field["values"].index(field["value"]) except ValueError: value = field["default"] field["radio_button_group"] = [] f = urwid.Text(field["name"]) f._datafield = field choice_items = [f] for dat in field["values"]: txt = value = dat if isinstance(dat, tuple): value, txt = dat f = urwid.AttrWrap(urwid.RadioButton(field["radio_button_group"], unicode(txt), state=value==field["value"]), 'buttn','buttnf') f._datafield = field f.value = value choice_items.append(f) hgf = HelpGridFlow(self, choice_items, 20, 3, 1, 'left') self.fields[key] = choice_items hgf.focus_cell = hgf.cells[1] list_content.append(hgf) elif field["type"] == "text": f = urwid.AttrWrap(urwid.Edit("%s: "%field["name"], field["value"]), 'editbx', 'editfc') f._datafield = field self.fields[key] = f list_content.append(f) elif field["type"] == "info": f = urwid.Text(field["name"]) f._datafield = field self.fields[key] = f list_content.append(f) def ok_pressed(*args, **kwargs): raise urwid.ExitMainLoop() def abort_pressed(*args, **kwargs): sys.exit(0) list_content.append(urwid.Divider(div_char=u"\u2550", top=1, bottom=1)) list_content.append( urwid.Padding(urwid.GridFlow( [urwid.AttrWrap(urwid.Button("Save", ok_pressed), 'buttn','buttnf'), urwid.AttrWrap(urwid.Button("Abort", abort_pressed), 'buttn','buttnf')], 15, 4, 4, 'center'), ('fixed left',4), ('fixed right',3))) header = urwid.AttrWrap(urwid.Text(text_header), 'header') #header = urwid.Padding(urwid.BigText("OpenChronos", urwid.HalfBlock5x4Font())) walker = HelpListWalker(self, list_content) listbox = urwid.ListBox(walker) self.help_widget = urwid.Text("") footer = urwid.AttrWrap(self.help_widget, 'footer') frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header, footer=footer) screen = urwid.raw_display.Screen() 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'), ] def unhandled(key): if key == 'f8': #raise urwid.ExitMainLoop() sys.exit(0) urwid.MainLoop(frame, palette, screen, unhandled_input=unhandled).run()
def set_title(self, title): if len(title) == 0: return title_text_w = urwid.Text(title, align="center") list_w = urwid.SimpleFocusListWalker([title_text_w]) self.title.original_widget = urwid.ListBox(list_w)
# Group buttons b_ready = urwid.Button("Change readyness") b_invite = urwid.Button("Invite") b_leave = urwid.Button("Leave") b_start = urwid.Button("Start") # Screens s_not_connected_home = urwid.Columns( [urwid.LineBox(f_register, "Sign up"), urwid.LineBox(f_login, "Sign in")]) s_connected_home = urwid.LineBox( urwid.Pile([t_connected_as, urwid.Divider(), t_user_id, t_user_type]), "Profile") s_new_group = urwid.LineBox(urwid.BoxAdapter(urwid.ListBox(f_new_group), 10), "Select a game") s_in_group = urwid.Pile([ urwid.LineBox(p_members, "Group"), urwid.Divider(), t_game_name, t_group_state, urwid.Divider(), urwid.Columns([b_ready, b_invite, b_leave, b_start]) ]) s_in_queue = urwid.Pile([ urwid.LineBox(p_members, "Group"), urwid.Divider(), t_game_name, t_group_state, urwid.Divider(), urwid.Columns([b_ready, b_leave]) ])
def BoxButton(label, callback): button = urwid.Button(label, callback) return urwid.ListBox(urwid.SimpleListWalker([button]))
def __init__(self, parname, theta, initsize=None): """Parameters ---------- parname : str Name of the list in ``theta``. It we be displayed to the user in the selection dialog. theta : 1-d array Sequence of values. If not an array, will be turned into an array. The values in this sequence will be presented to the user for interactive selection. Every value will have a checkbox. initsize : float | None If not None, it is the size (e.g. in GB, or simply in counts) associated with the full size of 'something', pre-selection. This size will be numerically reduced for every element removed during the selection. If None, no size computation will be performed. Returns ------- Nothing. But after running the interactive selection, see member self.idxes, it contains the selected indices. """ self.theta = theta if not isinstance(self.theta, N.ndarray): self.theta = N.array(self.theta) self.parname = parname self.initsize = initsize # set colors for bg, fg, and other elements # self.palette = [ ('header', 'white,bold', 'dark red'), # ('body', 'white,bold', 'light gray'), # ('buttn', 'black', 'light gray'), # ('buttnf', 'light green,bold', 'light gray'), # ('selected', 'white', 'dark blue') ] self.palette = [('header', 'white,bold', 'dark blue'), ('body', 'white,bold', 'dark cyan'), ('buttn', 'black', 'dark cyan'), ('buttnf', 'white,bold', 'dark cyan'), ('selected', 'white', 'dark blue')] self.ui = urwid.curses_display.Screen() self.HEADER = urwid.AttrWrap( urwid.Text("Use the keyboard arrows to move between checkboxes.\n" +\ "Hit SPACE to select/deselect. Hit ENTER when done.\n\n" +\ "Select values for parameter %s" % parname), 'header') strings = [str(e) for e in self.theta] len_ = int(N.max([len(e) for e in strings])) self.cells = [ urwid.AttrWrap(urwid.CheckBox(e, state=True), 'buttn', 'buttnf') for e in strings ] self.pad = urwid.Padding( urwid.GridFlow(self.cells, 4 + int(len_), 2, 0, 'left'), ('fixed left', 4), ('fixed right', 3)) self.listbox = urwid.ListBox([self.pad]) self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=self.HEADER) self.update_footer() self.ui.register_palette(self.palette) self.ui.run_wrapper(self.run)