def title_menu(self): title_list = [self.div] for article in self.summed_articles: pre_title_btn = urwid.Button(article["title"]) urwid.connect_signal(pre_title_btn, "click", self.display_article, article) title_btn = urwid.AttrMap(pre_title_btn, "body", focus_map="reversed") title_list.extend([title_btn]) scene = urwid.Pile(title_list) return urwid.Filler(scene)
def __init__(self, col=list_dir): self.title = "Category / Package Tree" button_list = [] for i in col: button = urwid.AttrMap(urwid.Button(i), None, focus_map='reversed') urwid.connect_signal(button.original_widget, 'click', self.append_pkgcol, i) button_list.append(button) self.cat_col = urwid.AttrMap(urwid.ListBox( urwid.SimpleFocusListWalker(button_list)), None, focus_map='blue-bold') super(Miller_Pane, self).__init__([self.cat_col], dividechars=1)
def list_view(loop, title, description, items, callback=False, parent=False): body = [urwid.Text(description), urwid.Divider()] if parent: body += add_back_button(parent) for item in items: button = urwid.Button(item['title']) selection = item if 'callback' in item: callback = item['callback'] urwid.connect_signal(button, 'click', callback, selection) body.append(urwid.AttrMap(button, 'body', focus_map='focustext')) list_content = urwid.SimpleFocusListWalker(body) content = urwid.ListBox(list_content) loop.widget = prepare(content, title)
def __init__(self, key=None, value=('', '')): self.trigger = key self.yn = value[0] self.yn_but = MyButton([('attention', 'Fix it: '), self.yn], self.on_change) self.input_dns = urwid.Edit(('attention', u' \N{BULLET} DNS : '), edit_text=value[1], wrap='clip') exit_but = urwid.Padding(urwid.Button('OKay'.center(8), self.item_callback), 'center', 12) widgets = [self.yn_but] + [urwid.AttrMap(wid, None, 'popbgs') for wid in (self.input_dns, exit_but)] self.pile = urwid.Pile(widgets) fill = urwid.LineBox(urwid.Filler(self.pile)) self.__super.__init__(urwid.AttrWrap(fill, 'popbg')) self.chosen = value
def _rebuild_no_edit(self): def _allow_edit(_): self._allow_edit = True self.rebuild() lines = [ urwid.Text("We cannot reproduce this event's repetition rules."), urwid.Text( "Editing the repetition rules will destroy the current rules." ), urwid.Button("Edit anyway", on_press=_allow_edit), ] self._refill_contents(lines) self._pile.set_focus(2)
def button(self, button_text, fn, b=False, data=None): """ Adds button, with border if needed :t: str(text) :fn: function(callback) :b: bool(default:false) """ w = urwid.Button(button_text, on_press=fn, user_data=data) w = urwid.AttrMap(w, 'button normal', 'button select') if type(b) == str: w = urwid.LineBox(w, title=b) if b == True: w = urwid.LineBox(w) return w
def __init__(self, key=None, value=''): self.trigger = key info = urwid.Text("'ESC' to clear, leave blank or 'all' for all country and port", 'center') self.country = urwid.Edit(('attention', u' \N{BULLET} Country: '), edit_text=value[0], wrap='clip') self.port = urwid.Edit(('attention', u' \N{BULLET} Port : '), edit_text=value[1], wrap='clip') self.score = urwid.Edit(('attention', u' \N{BULLET} Score >: '), edit_text=value[2], wrap='clip') exit_but = urwid.Padding(urwid.Button('OKay'.center(8), self.item_callback), 'center', 12) filter_ = [urwid.AttrMap(wid, None, 'popbgs') for wid in (self.country, self.port, self.score, exit_but)] self.pile = urwid.Pile([info]+filter_) fill = urwid.LineBox(urwid.Filler(self.pile)) self.__super.__init__(urwid.AttrWrap(fill, 'popbg')) self.chosen = value
def __init__(self, search_func, abort_func): class Search(Edit): def keypress(self, size, key): if key == 'enter': search_func(self.text) else: return super().keypress(size, key) search_field = Search('') def this_func(_): search_func(search_field.text) lines = [] lines.append(urwid.Text('Please enter a search term (Escape cancels):')) lines.append(search_field) buttons = NColumns([urwid.Button('Search', on_press=this_func), urwid.Button('Abort', on_press=abort_func)]) lines.append(buttons) content = NPile(lines, outermost=True) urwid.WidgetWrap.__init__(self, urwid.LineBox(content))
def add_buttons(self, buttons): l = [] for name, exitcode, callback in buttons: b = urwid.Button(name, callback, user_data=exitcode) b.exitcode = exitcode b = urwid.AttrMap(b, attr_map=self.palette.button.name, focus_map=self.palette.reveal_focus.name) l.append(b) self.buttons = urwid.GridFlow(l, 10, 3, 1, const.CENTER) self.frame.footer = urwid.Pile([urwid.Divider('-'), self.buttons], focus_item=1) self.frame.footer = urwid.AttrMap(self.frame.footer, self.palette.dialog_footer.name)
def menu(title, choices): body = [ urwid.Text(title), urwid.Text( 'The longest playlist has ' + str(longest_playlistcount) + ' entries. Do you want to modify the selection or start the import?' ), 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 get_buttons(self): buttons = [] parentnode = self.get_node().get_parent() def on_press(button, user_data=None): parentnode.add_child_node(user_data['key']) jsonnode = self.get_node().get_parent().get_value() maxlen = 3 for key in jsonnode.get_available_keys(): fieldname = jsonnode.get_child_title(key) maxlen = max(len(fieldname), maxlen) buttons.append(urwid.Button(fieldname, on_press, {'key': key})) return urwid.GridFlow(buttons, maxlen + 4, 2, 0, 'left')
def playlistitems(title): global listitems bt_sv = urwid.Button("Save") urwid.connect_signal(bt_sv, 'click', showmenu) bt_ca = urwid.Button("Cancel") urwid.connect_signal(bt_ca, 'click', showmenu) bt_sa = urwid.Button("Select all") urwid.connect_signal(bt_sa, 'click', select_all) bt_da = urwid.Button("Deselect all") urwid.connect_signal(bt_da, 'click', deselect_all) footer = urwid.Columns([bt_sv, bt_sa, bt_da, bt_ca], 1) items = [] for item in playlist_names: items.append( urwid.CheckBox(item['name'], is_selected(item['id']), on_state_change=checkbox_callback, user_data=item['id'])) start.original_widget = TabFrame(urwid.ListBox( urwid.SimpleListWalker(items)), header=urwid.Text("Select Playlists"), footer=footer, focus_part='body')
def __init__(self, packets): text = [ "Export the selected packet (<e>)", "Export all the packets (pcap format) (<E>)" ] self.pack = packets opt = [] for i in text: opt.append( urwid.Button(i, on_press=self.Action, user_data=i.split('<')[1].split('>')[0])) super(ActionMenu, self).__init__(packets.main_frame, opt, 'Action menu')
def start_screen(self): #Ovrlay top screen at start add_library = urwid.Button("New library [Enter URL]") urwid.connect_signal(add_library, 'click', self.input_screen) txt1 = urwid.AttrMap(add_library, None, focus_map='reversed') load_library = urwid.Button("Load saved playlist") urwid.connect_signal(load_library, 'click', self.load_list_screen) txt2 = urwid.AttrMap(load_library, None, focus_map='reversed') start_list = urwid.SimpleFocusListWalker([txt1, txt2]) box = urwid.ListBox(start_list) selection = urwid.LineBox(box, title='', title_align='center', tlcorner='┌', tline='─', lline='│', trcorner='┐', blcorner='└', rline='│', bline='─', brcorner='┘') selection_with_padding = urwid.Padding(selection, left=2, right=2) return selection_with_padding
def __init__(self, this_func, abort_func, event): lines = [] lines.append(urwid.Text('Export event as ICS file')) lines.append(urwid.Text('')) export_location = ExtendedEdit(caption='Location: ', edit_text="~/%s.ics" % event.summary.strip()) lines.append(export_location) lines.append(urwid.Divider(' ')) lines.append( urwid.Button('Save', on_press=this_func, user_data=export_location)) content = NPile(lines) urwid.WidgetWrap.__init__(self, urwid.LineBox(content))
def setup_menu(self, title, choices): """ Creates and returns a dynamic ListBox object containing a title and the choices given as parameters. """ body = [urwid.Text(title), urwid.Divider()] for c in choices: button = urwid.Button(c) urwid.connect_signal(button, "click", self.station_chosen, c) body.append(urwid.AttrMap(button, None, focus_map="selected")) return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def addcontacts(self, contact, clickFun): name = '' if contact['UserName'] == self.owner: return if not contact['RemarkName']: name = contact['NickName'] else: name = contact['RemarkName'] newline = urwid.Button(name) nickname = contact['RemarkName'] if contact['RemarkName'] else contact[ 'NickName'] urwid.connect_signal(newline, 'click', clickFun, [contact['UserName'], nickname]) self.body.append(urwid.LineBox(newline))
def add_buttons(self, buttons): """ Add buttons. """ l = [] maxlen = 0 for name, exitcode in buttons: b = urwid.Button(name, self.button_press) b.exitcode = exitcode b = urwid.AttrWrap(b, 'body', 'focus') l.append(b) maxlen = max(len(name), maxlen) maxlen += 4 # because of '< ... >' self.buttons = urwid.GridFlow(l, maxlen, 3, 1, 'center') self.frame.footer = urwid.Pile([urwid.Divider(), self.buttons], focus_item=1)
def __init__(self): self.editor = self.make_editor() self.swarm = urwid.Pile([self.robot_box(), self.robot_box(), self.robot_box()]) self.output = urwid.Text("output\none\ntwo\n") self.col = urwid.Columns([urwid.Pile([urwid.Text("yarn"), urwid.Columns([self.compile_button(), self.switch_button(), urwid.Button(u'load'), urwid.Button(u'save')]), urwid.LineBox(self.editor), urwid.LineBox(self.output)]), (12,urwid.Pile([urwid.Text("swarm"),self.swarm]))]) self.top=urwid.Filler(self.col,valign='top') f = open("../scm/robot.scm") self.src_text = f.read() f.close() f = open("../compiler/out.asm") self.asm_text = f.read() f.close() self.show_src=True
def info(self, msg, b): self.exit_flag = False size = self.ui.get_cols_rows() exit_button = urwid.Padding(urwid.Button("Exit", self.exit_info), align="center", width=8) frame = urwid.Frame(urwid.Filler(urwid.AttrWrap( urwid.Text(msg), "help"), valign="top"), header=self.header, footer=exit_button) canvas = frame.render(size) self.ui.draw_screen(size, canvas) self.get_keys() # wait for keypress
def gen_page(self): friends = urwid.Button('Friends') urwid.connect_signal(friends, 'click', self.on_friends_clicked, user_args=[self]) chats = urwid.Button('Chats') logout = urwid.Button('Logout') urwid.connect_signal(logout, 'click', self.on_logout_clicked, user_args=[self]) exit = urwid.Button('Exit') urwid.connect_signal(exit, 'click', self.on_exit_clicked) listbox = urwid.ListBox( urwid.SimpleFocusListWalker([ self.gen_button_attrmap(friends, 'submit'), self.gen_button_attrmap(chats, 'submit'), self.gen_button_attrmap(logout, 'cancel'), self.gen_button_attrmap(exit, 'cancel') ])) return self.gen_top(self.gen_padding(listbox))
def add_new_secret(a, b): global timer_handle global main_loop main_loop.remove_alarm(timer_handle) original = main.original_widget name = urwid.Edit(('', u"Insert name of the new topt-token\n")) secret = urwid.Edit(('', u"Insert the secret\n")) done_btn = urwid.Button(u'Ok') urwid.connect_signal(done_btn, 'click', add_secret, [[name, secret]]) main.original_widget = urwid.Filler( urwid.Pile([ urwid.Pile([name, secret]), urwid.AttrMap(done_btn, None, focus_map='reversed') ]))
def __init__(self, parent): self.parent = parent buttons = [] for c in parent.choices: buttons.append( urwid.Button(parent._decorate(c), on_press=self.set_choice, user_data=c) ) pile = NPile(buttons, outermost=True) num = [num for num, elem in enumerate(parent.choices) if elem == parent.active][0] pile.set_focus(num) fill = urwid.Filler(pile) urwid.WidgetWrap.__init__(self, urwid.AttrMap(fill, 'popupbg'))
def do_help(self): helptext = "Trackma-curses " + utils.VERSION + " by z411 ([email protected])\n\n" helptext += "Trackma is an open source client for media tracking websites.\n" helptext += "http://github.com/z411/trackma\n\n" helptext += "This program is licensed under the GPLv3,\nfor more information read COPYING file.\n\n" helptext += "More controls:\n {prev_filter}/{next_filter}:Change Filter\n {search}:Search\n {addsearch}:Add\n {reload}:Change API/Mediatype\n" helptext += " {delete}:Delete\n {send}:Send changes\n {sort_order}:Change sort order\n {retrieve}:Retrieve list\n {details}: View details\n {open_web}: Open website\n {openfolder}: Open folder containing show\n {altname}:Set alternative title\n {neweps}:Search for new episodes\n {play_random}:Play Random\n {switch_account}: Change account" helptext = helptext.format(**self.keymap_str) ok_button = urwid.Button('OK', self.help_close) ok_button_wrap = urwid.Padding( urwid.AttrMap(ok_button, 'button', 'button hilight'), 'center', 6) pile = urwid.Pile([urwid.Text(helptext), ok_button_wrap]) self.dialog = Dialog(pile, self.mainloop, width=62, title='About/Help') self.dialog.show()
def __init__(self, popup_launcher, button_with_pop_up): self.button_with_pop_up = button_with_pop_up self.round_time_choices = [] self.popup_launcher = popup_launcher # Buttons list with time rounds for i in range(25, 65, 5): self.round_time_choices.append(urwid.Button(str(i))) # Connect each button to set_round_time() method for i in self.round_time_choices: urwid.connect_signal(i, 'click', lambda button: self.set_round_time(button.get_label())) pile = urwid.Pile(self.round_time_choices) fill = urwid.Filler(pile) self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def find_quotes(button, edit): if selected_movie == 'all': subs = [] for movie in movies: subs.extend([(movie, quote) for quote in pysrt.open(movie['subtitle_path'])]) else: subs = [(selected_movie, quote) for quote in pysrt.open(selected_movie['subtitle_path'])] search_text = edit.edit_text.lower() def seek(item, quote): for i in item.split(' '): if i in quote: return True return False matching = [(m, s) for (m, s) in subs if seek(search_text, s.text.lower())] if len(matching) > 0: body_text = "Select quote ({} matches found)".format(len(matching)) else: body_text = "No quotes found" body = [urwid.Text(body_text), urwid.Divider()] for movie_tuple in matching: (m, s) = movie_tuple if selected_movie == 'all': button = urwid.Button('{}: {}'.format(m['title'], s.text)) else: button = urwid.Button(s.text) urwid.connect_signal(button, 'click', add_custom_subtitle, movie_tuple) body.append(urwid.AttrMap(button, None, focus_map='reversed')) back_button = urwid.Button('Go back') urwid.connect_signal(back_button, 'click', search) body.append(urwid.AttrMap(back_button, None, focus_map='reversed')) main.original_widget = urwid.ListBox(urwid.SimpleFocusListWalker(body))
def main_body(): body = program_header() create_backup_button = urwid.Button('Backup') urwid.connect_signal(create_backup_button, 'click', show_lvm) body.append(urwid.AttrMap(create_backup_button, None, focus_map='reversed')) restore_backup_button = urwid.Button("Restore") urwid.connect_signal(restore_backup_button, 'click', restore_screen) body.append( urwid.AttrMap(restore_backup_button, None, focus_map='reversed')) merge_button = urwid.Button('Merge') urwid.connect_signal(merge_button, 'click', files_screen) body.append(urwid.AttrMap(merge_button, None, focus_map='reversed')) exit = urwid.Button('Exit') urwid.connect_signal(exit, 'click', exit_program) body.append(urwid.AttrMap(exit, None, focus_map='reversed')) test_area_button = urwid.Button('Test Area') urwid.connect_signal(test_area_button, 'click', test_screen) # body.append(urwid.AttrMap(test_area_button, None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) configSectionHeader = urwid.Text('===Config Section ===') body.append(urwid.AttrMap(configSectionHeader, None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) current_dir, working_dir = get_directories() working_dir_text = urwid.Text('Working directory is: "' + working_dir + '"') body.append(urwid.AttrMap(working_dir_text, None, focus_map='reversed')) if current_dir != working_dir: save_dir_button = urwid.Button('Save "' + current_dir + '" as working directory') urwid.connect_signal(save_dir_button, 'click', save_working_dir, current_dir) body.append(urwid.AttrMap(save_dir_button, None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) exclude = get_config_param('exclude_list').replace('|', '\n') excludes_header = 'Exclude List (directories, path relative to mounted partitions):\n' exclude_listArea = urwid.Edit(excludes_header, exclude, True) urwid.connect_signal(exclude_listArea, 'change', save_excludes) body.append(urwid.AttrMap(exclude_listArea, None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) body.append(urwid.AttrMap(urwid.Divider(), None, focus_map='reversed')) config_file_path_text = urwid.Text('Config File: "' + init_config() + '"') body.append( urwid.AttrMap(config_file_path_text, None, focus_map='reversed')) return body
def create_toolbar(self): return urwid.AttrMap( urwid.Columns([ urwid.Padding(urwid.AttrMap( urwid.CheckBox([('header_file', 'w'), 'ord wrap'], state=(self.wrapping[0] == 'space'), on_state_change=self.toggle_wrapping), 'header', 'plain_selected'), right=2), urwid.Padding(urwid.AttrMap( urwid.CheckBox([('header_file', 'b'), 'orders'], state=(self.border[0] == 'bordered'), on_state_change=self.toggle_border), 'header', 'plain_selected'), right=2), urwid.Padding(urwid.AttrMap( urwid.Button([('header_file', 'R'), 'eload'], on_press=self.reload_todos_from_file), 'header', 'plain_selected'), right=2), urwid.Padding(urwid.AttrMap( urwid.Button([('header_file', 'S'), 'ave'], on_press=self.save_todos), 'header', 'plain_selected'), right=2), urwid.Padding(urwid.AttrMap( urwid.Button([('header_file', 's'), 'ort: ' + self.sorting_display[self.sorting[0]]], on_press=self.toggle_sorting), 'header', 'plain_selected'), right=2), urwid.Padding(urwid.AttrMap( urwid.Button([('header_file', 'f'), 'ilter'], on_press=self.toggle_filter_panel), 'header', 'plain_selected'), right=2) ]), 'header')
def refresh_location_widget(self, player): def dream(button): player.protagonist.dream() def warp(button): player.protagonist.warp() l = player.location b1 = urwid.Button("Dream Stone") b1._label.align = "center" if l.dream_stone: urwid.connect_signal(b1, "click", dream) b1 = urwid.AttrMap(b1, None, focus_map="line") b2 = urwid.Button("Dimensional Warp") b2._label.align = "center" if l.dimensional_warp: urwid.connect_signal(b2, "click", warp) b2 = urwid.AttrMap(b2, None, focus_map="line") button_line = SelectableColumns([(20, b1), (20, b2)], dividechars=1) loots = ["Lootings: "] + [(loot.rarity, "{} ".format(loot.name)) for loot in l.inventory] widgets = [button_line, urwid.Text(loots)] try: index = self.active_screen["widget"].focus_position button_line.focus_position = self.active_screen["widget"].body[:][ index].focus_position except: pass villains = [ c for c in l.characters if c.__class__.__name__ == "Villain" ] for v in villains: widgets += [urwid.Text(self.print_status(v), wrap='clip')] self.active_screen["widget"].body[:] = widgets
def item_chosen(self, button, choice): if choice == 'Toggle ON/OFF': # if is enable, disable it if self.state: inverter.change_state('disable operation') new_id = inverter.check_state() # is it switched on state? if new_id == 4: self.state = False else: inverter.change_state('enable operation') # TODO add status word check self.state = True new_id = inverter.check_state() if new_id == 7: self.state = True else: self.state = False response = urwid.Text( ['Inverter is {0}'.format(inverter.state[new_id]), u'\n']) done = urwid.Button(u'Ok') urwid.connect_signal(done, 'click', self.return_main) self.main_menu.original_widget = urwid.Filler( urwid.Pile([ response, urwid.AttrMap(done, None, focus_map='reversed') ])) elif choice == 'Set Speed': response = urwid.Edit(caption='Enter RPMs\n', edit_text='0') done = urwid.Button(u'Ok') urwid.connect_signal(done, 'click', self.set_seed, response) self.main_menu.original_widget = urwid.Filler( urwid.Pile([ response, urwid.AttrMap(done, None, focus_map='reversed') ]))