python类Button()的实例源码

cmenu.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def menu_button(caption, callback):
    button = urwid.Button(caption)
    urwid.connect_signal(button, 'click', callback)
    return urwid.AttrMap(button, None, focus_map='reversed')
pop_up.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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'))
pop_up.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        self.__super.__init__(urwid.Button("click-me"))
        urwid.connect_signal(self.original_widget, 'click',
            lambda button: self.open_pop_up())
pop_up.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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'))
pop_up.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self):
        self.__super.__init__(urwid.Button("click-me"))
        urwid.connect_signal(self.original_widget, 'click',
            lambda button: self.open_pop_up())
graph.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def button(self, t, fn):
        w = urwid.Button(t, fn)
        w = urwid.AttrWrap(w, 'button normal', 'button select')
        return w
dialog.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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)
test_container.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_buttons(self):
        self.fwstest(urwid.Button(u"hello"))
        self.fwstest(urwid.RadioButton([], u"hello"))
UiElements.py 文件源码 项目:s-tui 作者: amanusk 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def button(t, fn, data=None):
    w = urwid.Button(t, fn, data)
    w = urwid.AttrWrap(w, 'button normal', 'button select')
    return w
display.py 文件源码 项目:sshchan 作者: einchan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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")
main.py 文件源码 项目:scum 作者: CCareaga 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
main.py 文件源码 项目:bbj 作者: desvox 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
        )
rosbag-record-param-generator.py 文件源码 项目:my_ros_tools 作者: groundmelon 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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
TempSensorsMenu.py 文件源码 项目:s-tui 作者: amanusk 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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))


问题


面经


文章

微信
公众号

扫码关注公众号