我们从Python开源项目中,提取了以下44个代码示例,用于说明如何使用urwid.Button()。
def quit_prompt(self): """Pop-up window that appears when you try to quit.""" # Nothing fancy here. question = ur.Text(("bold", "Really quit?"), "center") yes_btn = ur.AttrMap(ur.Button( "Yes", self.button_press, "quit"), "red", None) no_btn = ur.AttrMap(ur.Button( "No", self.button_press, "back"), "green", None) prompt = ur.LineBox(ur.ListBox(ur.SimpleFocusListWalker( [question, self.div, self.div, no_btn, yes_btn]))) # The only interesting thing in this method is this Overlay widget. overlay = MyOverlay( prompt, self.loop.baseWidget, "center", 20, "middle", 8, 16, 8, parent=self) self.loop.Widget = overlay
def reply_box(self, button, thr_id): subject = ur.Edit(("blue", "Subject: "), wrap="clip") name = ur.Edit(("blue", "Name: "), "Anonymous", wrap="clip") if thr_id == -1: text = ur.Edit(multiline=True) else: text = ur.Edit(edit_text=">>" + thr_id, multiline=True) post_btn = ur.AttrMap(ur.Button( "Post", self.add_post, (subject, name, text, thr_id)), "green", "b_green") box = ur.LineBox(ur.ListBox(ur.SimpleFocusListWalker( [name, subject, ur.LineBox(text, "Post text"), self.parent.div, post_btn]))) self.loop.Widget = MyOverlay( box, self.loop.baseWidget, "center", ("relative", 100), "top", ("relative", 100), None, None, self.parent.margin, self.parent.margin, int(self.loop.dimensions[1] * 0.3), int(self.loop.dimensions[1] * 0.3), self.parent)
def open_confirm_prompt(self, callback, title="", content="", yestxt="Yes", notxt="No", align="center"): def create_cb(bool): def res(*k, **a): callback(bool) self.close_pop_up() return res self.open_pop_up( urwid.Filler(urwid.Text(content, align=align)), header=urwid.Text( title, align='center'), footer=urwid.Columns([ (urwid.Button(yestxt, create_cb(True))), (urwid.Button(notxt, create_cb(False))), ]), height=6, width=50) self.pop_up.set_focus("footer") logger.debug("Confirm prompt text: " + str(content))
def menu(title, SSID): body = [urwid.Text(title), urwid.Divider()] options = [] for c in SSID: button = urwid.Button("[ ] " + c) options.append(button) #if SSID_DICT[c] == True: # button.set_label(u"DH") urwid.connect_signal(button, 'click', item_chosen, c) body.append(urwid.AttrMap(button, None, focus_map='reversed')) swarmify_button = urwid.Button("Swarmify") options.append(swarmify_button) urwid.connect_signal(swarmify_button, 'click', swarm_chosen, c) body.append(urwid.AttrMap(swarmify_button, None, focus_map='reversed')) return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def item_chosen(button, choice): if SSID_DICT[choice]: button.set_label(u"[ ] " + button.get_label()[4:]) SSID_DICT[choice] = False else: button.set_label(u"[*] " + button.get_label()[4:]) SSID_DICT[choice] = True ##response = urwid.Text([u'You chose ', str(SSID_DICT[choice]), u'\n']) ##done = urwid.Button(u'Ok') ##urwid.connect_signal(done, 'click', exit_program) ##main.original_widget = urwid.Filler(urwid.Pile([response, ##urwid.AttrMap(done, None, focus_map='reversed')]))
def menuAV(title, avail_stream_both): ###menu displaying formats with both audio and video ######### 2nd loop body = [urwid.Text(title), urwid.Divider()] for c in avail_stream_both: button = urwid.Button(str(c) + " ----->" + str(c.resolution) + "----->" + str((float(c.get_filesize())/1024)/1024)) urwid.connect_signal(button, 'click', chosen_URL, c) body.append(urwid.AttrMap(button, None, focus_map='reversed')) button = urwid.Button("Only Video/Audio Formats") urwid.connect_signal(button, 'click', menuVAOnly) body.append(urwid.AttrMap(button, None, focus_map='reversed')) button = urwid.Button("EXIT") urwid.connect_signal(button, 'click', exit_program) body.append(urwid.AttrMap(button, None, focus_map='reversed')) return urwid.ListBox(urwid.SimpleFocusListWalker(body)) ##########################################################################333
def menuVAOnlyMenu(title, avail_stream_VideoO,avail_stream_audioO): ###menu displaying formats with only audio or video ## must handle cases with audio and video alone ## for 3rd loop body = [urwid.Text(title), urwid.Divider()] for x in avail_stream_VideoO: button = urwid.Button(str(x).split('@',1)[0] + "---->" +x.resolution + "----->" + str((float(x.get_filesize())/1024)/1024)) urwid.connect_signal(button, 'click', chosen_URL, x) body.append(urwid.AttrMap(button, None, focus_map='reversed')) for x1 in avail_stream_audioO: button = urwid.Button(str(x1)) urwid.connect_signal(button, 'click', chosen_URL, x1) body.append(urwid.AttrMap(button, None, focus_map='reversed')) button = urwid.Button("EXIT") urwid.connect_signal(button, 'click', exit_program) body.append(urwid.AttrMap(button, None, focus_map='reversed')) return urwid.ListBox(urwid.SimpleFocusListWalker(body)) #################3333##################################################
def __init__(self, prompt_text=u"Input:", default_text=u""): close_button = urwid.Button("OK") prompt = urwid.Text(prompt_text) edit_field = CustomEdit(caption=u'', edit_text=default_text, multiline=False, align='left', wrap='space', allow_tab=False, edit_pos=None, layout=None, mask=None) prompt_wrap = urwid.AttrMap(prompt, 'header') close_button_wrap = urwid.AttrMap(close_button, 'buttn', 'buttnf') edit_field_wrap = urwid.AttrMap(edit_field, 'editcp') urwid.connect_signal(close_button, 'click', edit_field.on_finish) urwid.connect_signal(edit_field, 'done', self.on_close) pile = urwid.Pile([prompt_wrap, edit_field_wrap, urwid.Padding(close_button_wrap, 'center', 6)]) fill = urwid.Filler(urwid.Padding(pile, 'center', left=1, right=1)) self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def __init__(self, return_fn): self.return_fn = return_fn self.about_message = ABOUT_MESSAGE self.time_out_ctrl = urwid.Text(self.about_message) cancel_button = urwid.Button('Exit', on_press=self.on_cancel) cancel_button._label.align = 'center' if_buttons = urwid.Columns([cancel_button]) title = urwid.Text(('bold text', u" About Menu \n"), 'center') self.titles = [title, self.time_out_ctrl, if_buttons] self.main_window = urwid.LineBox(ViListBox(self.titles))
def __init__(self, return_fn): self.return_fn = return_fn self.help_message = HELP_MESSAGE self.time_out_ctrl = urwid.Text(self.help_message) cancel_button = urwid.Button('Exit', on_press=self.on_cancel) cancel_button._label.align = 'center' if_buttons = urwid.Columns([cancel_button]) title = urwid.Text(('bold text', u" Help Menu \n"), 'center') self.titles = [title, self.time_out_ctrl, if_buttons] self.main_window = urwid.LineBox(ViListBox(self.titles))
def __init__(self, label, on_press=None, user_data=None, align='right'): super(TextButton, self).__init__( label, on_press=on_press, user_data=user_data) self._label.align = align cols = urwid.Columns([self._label]) super(urwid.Button, self).__init__(cols)
def __init__(self, content, on_press=None, user_data=None): self.__super.__init__('', on_press=on_press, user_data=user_data) super(urwid.Button, self).__init__(content)
def show_help(self): """Create and return Frame object containing help docs.""" # Flags are gr8 against bugs. self.help_flag = True help_header = ur.Text(("green", "SSHCHAN HELP"), "center") pg1 = ur.Text( [("bold", "sshchan "), "is a textboard environment designed \ to run on remote SSH servers with multiple anonymous users simultaneously \ browsing and posting."], "center") pg2 = ur.Text(("bold", "Keybindings:")) pg3 = ur.Text([("green", "TAB"), ( None, " - switch focus between main body and top bar")]) pg4 = ur.Text( [("green", "H h"), (None, " - display this help dialog")]) pg5 = ur.Text( [("green", "B b"), (None, " - view available boards")]) pg6 = ur.Text( [("green", "ESC"), ( None, " - go back one screen (exits on MOTD screen)")]) back_btn = ur.AttrMap( ur.Button("Back", self.button_press, "back"), "red", "reverse") help_body = ur.Padding(ur.ListBox(ur.SimpleListWalker([ self.div, help_header, self.div, pg1, self.div, pg2, pg3, pg4, pg5, pg6, self.div, back_btn])), "center", self.width, 0, self.margin, self.margin) return ur.AttrMap(ur.Frame(help_body, self.header, self.footer, "body"), "bg")
def list_boards(self): """Display a column of buttons listing all available boards.""" boards = self.config.get_boardlist() btn_list = [] for board, desc in sorted(boards.items()): btn_list.append(ur.AttrMap(ur.Button( "/" + board + "/ - " + desc, self.button_press, board), None, "reverse")) btn_list.append(self.div) # boards_count is here so the list can be dynamically displayed. self.boards_count = len(btn_list) return btn_list
def __init__(self, *args, **kwargs): self.start = urwid.Edit('Start: ') self.end = urwid.Edit('End: ') self.server = kwargs["server"] self.calendar = kwargs["calendar"] del(kwargs['server']) del(kwargs["calendar"]) print (self.server, self.calendar) div = urwid.Divider() self.msg = urwid.Edit(caption="Event message: ", edit_text='', multiline=True) button_save = urwid.Button('save') urwid.connect_signal(button_save, 'click', self.on_save) self.pile = urwid.Pile([self.start, self.end, div, self.msg, div, button_save]) super(EventWidget, self).__init__(self.pile, *args, **kwargs)
def __init__(self): close_button = urwid.Button("that's pretty cool") urwid.connect_signal(close_button, 'click', lambda button:self._emit("close")) pile = urwid.Pile([urwid.Text( "^^ I'm attached to the widget that opened me. " "Try resizing the window!\n"), close_button]) fill = urwid.Filler(pile) self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def __init__(self): self.__super.__init__(urwid.Button("click-me")) urwid.connect_signal(self.original_widget, 'click', lambda button: self.open_pop_up())
def __init__(self, pubpen): self.pubpen = pubpen self.save_button = urwid.Button('(S)ave') self.load_button = urwid.Button('(L)oad') self.quit_button = urwid.Button('(Q)uit') self.continue_button = urwid.Button('(ESC) Continue Game') self.buttons = urwid.SimpleFocusListWalker(( urwid.AttrMap(self.save_button, None, focus_map='reversed'), urwid.AttrMap(self.load_button, None, focus_map='reversed'), urwid.AttrMap(self.quit_button, None, focus_map='reversed'), urwid.AttrMap(self.continue_button, None, focus_map='reversed'), )) self.entrybox = urwid.ListBox(self.buttons) # Draw a box around the widget and constrain the widget's size linebox = urwid.LineBox(self.entrybox, tlcorner='\u2554', tline='\u2550', trcorner='\u2557', blcorner='\u255A', bline='\u2550', brcorner='\u255D', lline='\u2551', rline='\u2551') padding = urwid.Padding(linebox, align='center', width=len(self.continue_button.get_label()) + 6) filler = urwid.Filler(padding, valign='middle', height=len(self.buttons) + 2) outer_layout = LineBox(filler, lline=None, blcorner='?', tlcorner='?', trcorner='\u252c', brcorner='\u2524') super().__init__(outer_layout) urwid.connect_signal(self.save_button, 'click', self.save_game) urwid.connect_signal(self.load_button, 'click', self.load_game) urwid.connect_signal(self.quit_button, 'click', self.quit_client) urwid.connect_signal(self.continue_button, 'click', self.continue_game)
def __init__(self, pubpen): self.pubpen = pubpen username_label = urwid.Text('Username: ', align='right') password_label = urwid.Text('Password: ', align='right') self.username = urwid.Edit() self.password = urwid.Edit() login_button = urwid.Button('Login') decorated_login_button = urwid.AttrMap(login_button, None, focus_map='reversed') quit_button = urwid.Button('Quit') decorated_quit_button = urwid.AttrMap(quit_button, None, focus_map='reversed') buttons = urwid.Columns(( (len('Login') + 4, decorated_login_button), (len('Quit') + 4, decorated_quit_button), ), focus_column=1) labels = urwid.Pile([username_label, password_label]) self.fields = urwid.Pile([self.username, self.password, buttons], focus_item=0) entry_box = urwid.Columns([labels, self.fields]) self.status_message = urwid.Text(' ', align='center') entry_with_status = urwid.Pile([entry_box, self.status_message]) padded_entry_with_status = urwid.Padding(entry_with_status, align='center') self.display = urwid.Filler(padded_entry_with_status, valign='middle') decorate = urwid.LineBox(self.display) super().__init__(decorate) self.focusable_widgets = (w for w in itertools.cycle(( ((self.fields, 1),), ((self.fields, 2), (buttons, 0)), ((self.fields, 2), (buttons, 1)), ((self.fields, 0),) ))) urwid.connect_signal(login_button, 'click', self.attempt_login) urwid.connect_signal(quit_button, 'click', self.quit) self.pubpen.subscribe('user.login_success', self.handle_login_success) self.pubpen.subscribe('user.login_failure', self.handle_login_failure)
def general_help(self): """ Show a general help dialog. In all honestly, its not very useful and will only help people who have never really used terminal software before =) """ widget = OptionsMenu( urwid.ListBox( urwid.SimpleFocusListWalker([ urwid_rainbows( "This is BBJ, a client/server textboard made for tilde.town!", True), urwid.Text(("dim", "...by ~desvox")), urwid.Divider("-"), urwid.Button("Post Formatting Help", self.formatting_help), urwid.Divider("-"), urwid.Text(general_help) ])), title="?????", **frame_theme() ) app.loop.widget = urwid.Overlay( widget, app.loop.widget, align=("relative", 50), valign=("relative", 50), width=30, height=("relative", 60) )
def cute_button(label, callback=None, data=None): """ Urwid's default buttons are shit, and they have ugly borders. This function returns buttons that are a bit easier to love. """ button = urwid.Button("", callback, data) super(urwid.Button, button).__init__( urwid.SelectableIcon(label)) return button
def swarm_chosen(button, choice): try: copters_chosen = [x+ " \n" for x in SSID_DICT.keys() if SSID_DICT[x] == True] response = urwid.Text([u'Swarmifying: \n', copters_chosen, u'\n']) done = urwid.Button(u'Ok') urwid.connect_signal(done, 'click', exit_program) main.original_widget = urwid.Filler(urwid.Pile([response, urwid.AttrMap(done, None, focus_map='reversed')])) except: pass
def __init__(self, mod: Mod, *callbacks: Iterable[ModItemCallback]): """Wrap mod in the set of display widgets. Keyword arguments: mod: The :class:`Mod` to be wrapped. callbacks: The functions to be called when this object is selected. """ btn_prefix = ' ? ' # Construct button (the selectable part) btn = urwid.Button('') btn._w = urwid.AttrMap( urwid.SelectableIcon([btn_prefix, mod.name], 2), 'title', 'title_focus', ) for callback in callbacks: urwid.connect_signal(btn, 'click', callback, user_args=[mod]) # Construct the mod summary text = urwid.Padding( urwid.AttrMap(urwid.Text(mod.summary), 'description'), left=len(btn_prefix)*2, ) pile = btn, text super().__init__(pile)
def choose(self, mod: Mod, btn: urwid.Button) -> None: """Record the choice. Keyword arguments: mod: The mod to record as the last choice. btn: Unused, exists for signature compatibility. """ self.chosen = mod
def chosen_URL(button,choice): #######show url of chosen format #####modify so that it calls axel to dowload the given url ############### called when a particular stream is selected v_chosen = urwid.Text([u'Video Format :- ', str(choice), u'\n']) #v_URL = urwid.Text([u'Downloadable URL :- ', str(choice.url), u'\n']) done = urwid.Button(u'Copy URL to Clipboard') down = urwid.Button(u'Download using aria') ext = urwid.Button(u'Exit') urwid.connect_signal(done, 'click', Copy_exit,choice) urwid.connect_signal(ext, 'click', exit_program) urwid.connect_signal(down,'click',Down_aria,choice) main1.original_widget = urwid.Filler(urwid.Pile([v_chosen,urwid.AttrMap(down, None, focus_map='reversed'),urwid.AttrMap(done, None, focus_map='reversed'),urwid.AttrMap(ext, None, focus_map='reversed')])) ##############################Displaying Video formats definitions########################
def __init__(self, *args, **kwargs): self.__super.__init__(urwid.Button(*args)) self.callback = None self.popup_kwargs = kwargs
def menu(title, choices): body = [urwid.Text(title), urwid.Divider()] for c in choices: button = urwid.Button(c) urwid.connect_signal(button, 'click', item_chosen, c) body.append(urwid.AttrMap(button, None, focus_map='reversed')) return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def item_chosen(button, choice): response = urwid.Text([u'You chose ', choice, u'\n']) done = urwid.Button(u'Ok') urwid.connect_signal(done, 'click', exit_program) main.original_widget = urwid.Filler(urwid.Pile([response, urwid.AttrMap(done, None, focus_map='reversed')]))
def menu_button(caption, callback): button = urwid.Button(caption) urwid.connect_signal(button, 'click', callback) return urwid.AttrMap(button, None, focus_map='reversed')
def button(self, t, fn): w = urwid.Button(t, fn) w = urwid.AttrWrap(w, 'button normal', 'button select') return w
def add_buttons(self, buttons): l = [] for name, exitcode in buttons: b = urwid.Button( name, self.button_press ) b.exitcode = exitcode b = urwid.AttrWrap( b, 'selectable','focus' ) l.append( b ) self.buttons = urwid.GridFlow(l, 10, 3, 1, 'center') self.frame.footer = urwid.Pile( [ urwid.Divider(), self.buttons ], focus_item = 1)
def test_buttons(self): self.fwstest(urwid.Button(u"hello")) self.fwstest(urwid.RadioButton([], u"hello"))
def button(t, fn, data=None): w = urwid.Button(t, fn, data) w = urwid.AttrWrap(w, 'button normal', 'button select') return w
def show_board(self): index = self.board.get_index() new_btn = ur.AttrMap( ur.Button("New thread", self.reply_box, -1), "green", "b_green") thread_list = ur.SimpleFocusListWalker( [ur.Padding(new_btn, "center", ("relative", 40)), self.parent.div]) for thread in index: # Check subject, because empty subject with set color attribute # produces wrong output. subject = ("reverse_red", thread[1]) if subject[1] == "": subject = (None, "") op = self.parse_post(thread[2]) post_info = ur.Text([("reverse_green", op["name"]), " " + op["stamp"] + " ", subject, " No. " + op["id"]]) reply_btn = ur.AttrMap(CleanButton( "Reply", self.print_thread, op["id"]), None, "reverse") replies = [] if len(thread) > 3: for i in range(3, 6): try: reply = self.parse_post(thread[i]) replies_info = ur.Text( [("green", reply["name"]), " " + reply["stamp"]]) no_btn = CleanButton( "No. " + reply["id"], self.print_thread, reply["id"]) replies_header = ur.Padding(ur.Columns( [("pack", replies_info), ("pack", no_btn)], 1), left=1) reply_text = ur.Padding(reply["text"], left=1) replies.extend( [replies_header, reply_text, self.parent.div]) except IndexError: break header = ur.AttrMap(ur.Columns( [("pack", post_info), ("pack", reply_btn)], 1), "reverse") thread_buf = [header, op["text"], self.parent.div] thread_buf.extend(replies) thread_list.extend(thread_buf) body = ur.ListBox(thread_list) if len(thread_list) > 0: body.set_focus(0) self.loop.Widget = ur.Frame( body, self.parent.header, self.parent.footer, "body")
def populate(self, fname): # this function populates the TextList and creates a new tabs # The same Textlist is used for each tab but when tabs are switched the # contents of the tab are grabbed from the files TabInfo instance if fname not in self.display.file_names: # grab the lines from the file and strip the newline char # then iterate through and create a new TextLine object for each line try: with open(fname) as f: content = [x.strip('\n') for x in f.readlines()] except: self.redraw_tabs() return # the short name is the file name without a path self.short_name = strip_fname(fname) self.display.file_names.append(fname) new_lines = [] # grab the lines from the file and strip the newline char # Then iterate through and create a new TextLine object for each line for line in content: text = TextLine(line, self.display) new_lines.append(text) # if the file is empty then add one empty line so it can be displayed if len(new_lines) < 1: text = TextLine(' ', self.display) new_lines.append(text) # create a new tab (button widget) with the correct attributes self.display.cur_tab = self.display.tab_info[fname] = TabInfo(self.display) new_tab_info = self.display.tab_info[fname] new_tab_info.lines = new_lines new_tab_info.undo = UndoStack(self.display) new_tab_info.cursor = (0, 0) self.display.line_nums.populate(new_lines) button = urwid.Button(self.short_name) button._label.align = 'center' attrib = urwid.AttrMap(button, 'footer') self.display.tabs.append(attrib) # switch to the new tab self.switch_tabs(fname) else: self.display.line_nums.populate(self.lines) self.redraw_tabs()
def on_post(self, button, message): quotes = self.get_quotes(message) author = self.usermap[message["author"]] buttons = [] if not self.window_split: buttons.append(urwid.Button("Reply", self.reply, message)) if quotes and message["post_id"] != 0: buttons.append(urwid.Button( "View %sQuote" % ("a " if len(quotes) != 1 else ""), self.quote_view_menu, quotes)) if network.can_edit(message["thread_id"], message["post_id"]) \ and not self.window_split: if message["post_id"] == 0: msg = "Thread" else: msg = "Post" raw = message["send_raw"] buttons.insert(0, urwid.Button("Delete %s" % msg, self.deletion_dialog, message)) buttons.insert(0, urwid.Button( "Enable Formatting" if raw else "Disable Formatting", self.toggle_formatting, message)) buttons.insert(0, urwid.Button("Edit Post", self.edit_post, message)) if not buttons: return widget = OptionsMenu( urwid.ListBox(urwid.SimpleFocusListWalker(buttons)), title=str(">>%d (%s)" % (message["post_id"], author["user_name"])), **frame_theme() ) size = self.loop.screen_size self.loop.widget = urwid.Overlay( urwid.AttrMap(widget, str(author["color"]*10)), self.loop.widget, align=("relative", 50), valign=("relative", 50), width=30, height=len(buttons) + 2 )
def __init__(self, output_prefix=None): self.exit_message = None self.output_prefix = output_prefix text_header = (u"Command Generation for 'rosbag record' ") buttons = OrderedDict() buttons['quit'] = urwid.Button(u"Quit(ESC/q)", self.on_quit) buttons['save'] = dialog.PopUpButton(u"Save(F2)", self.on_save, prompt_text=u"Input file name:", default_text=u"record.sh") buttons['mark'] = urwid.Button(u"Mark all(F3)", self.on_mark_all) buttons['unmark'] = urwid.Button(u"Unmark all(F4)", self.on_unmark_all) buttons['refresh'] = urwid.Button(u"Refresh(F5)", self.on_refresh) self.buttons = buttons # blank = urwid.Divider() header = urwid.AttrWrap(urwid.Text(text_header, align='center'), 'header') button_bar = urwid.GridFlow( [urwid.AttrWrap(btn, 'buttn', 'buttnf') for (key, btn) in buttons.iteritems()], 18, 3, 1, 'left') status_bar = urwid.AttrWrap(urwid.Text(u""), 'footer') footer = urwid.Pile([button_bar, status_bar]) self.listwalker = urwid.SimpleListWalker(self.create_listbox_from_ros()) listbox = urwid.ListBox(self.listwalker) body = urwid.AttrWrap(listbox, 'body') self.frame = urwid.Frame(body=body, header=header, footer=footer) self.frame_focus_table = dict() self.frame_focus_table[body] = 'footer' self.frame_focus_table[footer] = 'body' palette = [ ('body', 'white', 'black', 'standout'), ('reverse', 'light gray', 'black'), ('header', 'white', 'dark blue', 'bold'), ('footer', 'black', 'light gray'), ('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', 'light cyan'), ('buttnf', 'white', 'dark blue', 'bold'), ('popbg', 'white', 'dark gray'), ] self.show_msg = status_bar.set_text screen = urwid.raw_display.Screen() self.mainloop = urwid.MainLoop(self.frame, palette, screen, unhandled_input=self.unhandled, pop_ups=True) # UI functions
def __init__(self, return_fn): # What is shown in menu self.current_mode = None # Sensor Applied self.current_active_mode = None self.no_malloc = False title = urwid.Text(('bold text', u" Available Temperature Sensors \n"), 'center') self.available_sensors = [] sensors_dict = dict() try: sensors_dict = psutil.sensors_temperatures() except (AttributeError, IOError): logging.debug("Unable to create sensors dict") for key,value in sensors_dict.items(): sensor_name = key for itr in range(len(value)): sensor_label = "" try: sensor_label = value[itr].label logging.debug("Sensor Label") logging.debug(sensor_label) except (IndexError): pass self.available_sensors.append(sensor_name +\ "," +str(itr) +\ "," + sensor_label) group = [] self.sensor_buttons = [] for sensor in self.available_sensors: rb = radio_button(group, sensor, self.on_mode_button) self.sensor_buttons.append(rb) #rb = radio_button(group, "INVALID", self.on_mode_button) #self.sensor_buttons.append(rb) self.return_fn = return_fn cancel_button = urwid.Button('Cancel', on_press=self.on_cancel) cancel_button._label.align = 'center' apply_button = urwid.Button('Apply', on_press=self.on_apply) apply_button._label.align = 'center' if_buttons = urwid.Columns([apply_button,cancel_button]) self.titles = [title] + self.sensor_buttons + [if_buttons] self.main_window = urwid.LineBox(ViListBox(self.titles))