Пример #1
0
 def factory_method():
     dialog = urwid.Text(u'\nLoading...', align='center')
     dialog = urwid.Filler(dialog)
     dialog = urwid.AttrMap(urwid.LineBox(dialog), 'linebox')
     return dialog
Пример #2
0
    def render(self, size, focus=False):
        """
        Render frame and return it.
        """
        (maxcol, maxrow) = size
        (htrim, ctrim, ftrim), (hrows, crows, frows) = self.frame_top_bottom(
            (maxcol, maxrow), focus)

        combinelist = []
        depends_on = []

        head = None
        if htrim and htrim < hrows:
            head = urwid.Filler(self.header, 'top').render(
                (maxcol, htrim), focus and self.focus_part == 'header')
        elif htrim:
            head = self.header.render((maxcol, ), focus
                                      and self.focus_part == 'header')
            assert head.rows() == hrows, "rows, render mismatch"
        if head:
            combinelist.append((head, 'header', self.focus_part == 'header'))
            depends_on.append(self.header)

        if ftrim + htrim + ctrim < maxrow:
            body = self.body.render((maxcol, maxrow - ftrim - htrim - ctrim),
                                    focus and self.focus_part == 'body')
            combinelist.append((body, 'body', self.focus_part == 'body'))
            depends_on.append(self.body)

        columns = None
        if ctrim and ctrim < crows:
            if self.focus_part == 'value':
                columns = urwid.Filler(self.columns_pile, 'columns').render(
                    (maxcol, ftrim),
                    #TODO Changeit it to return command or result
                    focus and self.focus_part == 'value')
                self.log.debug("render in value %s" %
                               (self.focus_part == 'value'))
            elif self.focus_part == 'result':
                columns = urwid.Filler(self.columns_pile, 'columns').render(
                    (maxcol, ftrim),
                    #TODO Changeit it to return command or result
                    focus and self.focus_part == 'result')
                self.log.debug("render in result %s" %
                               (self.focus_part == 'result'))
            else:
                columns = urwid.Filler(self.columns_pile, 'columns').render(
                    (maxcol, ftrim),
                    #TODO Changeit it to return command or result
                    focus and self.focus_part == 'command')
                self.log.debug("render in command %s" %
                               (self.focus_part == 'command'))
        elif ctrim:
            if self.focus_part == 'value':
                columns = self.columns_pile.render(
                    (maxcol, ), focus and self.focus_part == 'value')
                self.log.debug("render in value %s" %
                               (self.focus_part == 'value'))
            elif self.focus_part == 'result':
                columns = self.columns_pile.render(
                    (maxcol, ), focus and self.focus_part == 'result')
                self.log.debug("render in result %s" %
                               (self.focus_part == 'result'))
            else:
                columns = self.columns_pile.render(
                    (maxcol, ), focus and self.focus_part == 'command')
                self.log.debug("render in command %s" %
                               (self.focus_part == 'command'))
            assert columns.rows() == crows, "rows, render mismatch"
        if columns:
            newfocus = "%s" % self.focus_part
            combinelist.append((columns, 'columns',
                self.focus_part == "command" or self.focus_part == "value" \
                    or self.focus_part == "result"))
            depends_on.append(self.columns_pile)

        foot = None
        if ftrim and ftrim < frows:
            foot = urwid.Filler(self.footer, 'bottom').render(
                (maxcol, ftrim), focus and self.focus_part == 'footer')
        elif ftrim:
            foot = self.footer.render((maxcol, ), focus
                                      and self.focus_part == 'footer')
            assert foot.rows() == frows, "rows, render mismatch"
        if foot:
            combinelist.append((foot, 'footer', self.focus_part == 'footer'))
            depends_on.append(self.footer)

        return urwid.CanvasCombine(combinelist)
Пример #3
0
 def fetest(self, desc, valign, height):
     self.assertRaises(urwid.FillerError, lambda:
     urwid.Filler(None, valign, height))
Пример #4
0
 def __init__(self):
     # show message in the center of the screen
     super().__init__(
         urwid.Filler(urwid.Text('Connecting...', align='center')))
Пример #5
0
    def setTrace(self, trace, op_contracts=[], txhash=None, txinput=None):
        self.operations = trace
        self.op_contracts = op_contracts

        ops_view = urwid.Text(self.getOp())
        mem_view = urwid.Text(self.getMem())
        memref_view = urwid.Text(self.getMemref())
        stack_view = urwid.Text(self.getStack())
        trace_view = urwid.Text(self.getTrace())
        source_view = urwid.Text(self.getSource())
        help_view = urwid.Text(self.getHelp())
        # palettes are currently not used
        palette = [
            ('banner', 'black', 'light gray'),
            ('streak', 'black', 'dark red'),
            ('bg', 'black', 'dark blue'),
        ]
        palette = [
            ('headings', 'white,underline', 'black',
             'bold,underline'),  # bold text in monochrome mode
            ('body_text', 'dark cyan', 'light gray'),
            ('buttons', 'yellow', 'dark green', 'standout'),
            ('section_text', 'body_text'),  # alias to body_text
            ('source', 'white', 'black',
             'bold'),  # bold text in monochrome mode
        ]

        self.ops_view = ops_view
        self.mem_view = mem_view
        self.memref_view = memref_view
        self.stack_view = stack_view
        self.trace_view = trace_view
        self.source_view = source_view
        self.help_view = help_view

        # indicate the online lookup with a * at the end of decoded
        try:
            txinput_decoded = ethereum_input_decoder.AbiMethod.from_input_lookup(
                ethereum_input_decoder.Utils.str_to_bytes(txinput)
            ) if ethereum_input_decoder else "<input decoder not installed>"
        except Exception as e:  # not going to import from eth_abi to not make the code depending on it
            txinput_decoded = "!! DecodingError: %s" % e

        inp_view = urwid.Text("""
  > tx:       %s
  > input:    %s
  > decoded*: %s""" % (txhash, txinput, txinput_decoded))

        top = DebugViewer.wrap(
            urwid.Pile([
                DebugViewer.wrap(inp_view, ""),
                urwid.Columns([
                    urwid.Pile([
                        DebugViewer.wrap(ops_view, "Op"),
                        DebugViewer.wrap(trace_view, "Trace")
                    ]),
                    urwid.Pile([
                        DebugViewer.wrap(mem_view, "Memory"),
                        DebugViewer.wrap(memref_view,
                                         "Memory Reference by Opcode"),
                        DebugViewer.wrap(stack_view, "Stack"),
                        DebugViewer.wrap(source_view, "Source"),
                    ])
                ])
            ]), "Retromix")

        horiz = urwid.Pile([top, DebugViewer.wrap(help_view, "Help")])
        fill = urwid.Filler(horiz, 'top')

        # self.dbg("Loaded %d operations" % len(self.operations) )

        loop = urwid.MainLoop(
            fill,
            palette,
            unhandled_input=lambda input: self.show_or_exit(input))
        loop.run()
Пример #6
0
def create_main_view(user_info):
    #used to easily insert a blank line widget
    blank = urwid.Divider()

    #signal handler for the connect button
    def db_connect(button):
        if user_info.mysql == True:
            import mysqlDB as sqlDB  # for MySQL
            user_info.db_obj = sqlDB.MYsql()
        elif user_info.psql == True:
            import psqlDB as sqlDB  # for PostgreSQL
            user_info.db_obj = sqlDB.Psql()

        if (user_info.db_name and user_info.db_uname):
            # connect to the db
            user_info.db_conn = user_info.db_obj.connectdb(
                user_info.db_name, user_info.db_uname, user_info.db_pw)

            # if connection error returned
            if user_info.db_conn == -1:
                db_error_box.original_widget = urwid.AttrMap(
                    urwid.Text(
                        u" Incorrect username, database name, or password.\n Please try again"
                    ), 'error', 'error')

            # if good connection returned
            else:
                #build out and show the main app view on the screen
                mainview.show_main_view(frame, body, user_info)

        else:
            db_error_box.original_widget = urwid.AttrMap(
                urwid.Text(u" Please enter your username and database name"),
                'error', 'error')

    #signal handler for radio buttons, stores input information from user
    def radio_change(self, state):
        if self.label == "MySQL":
            if state == True:
                user_info.mysql = True
                user_info.psql = False
        elif self.label == "PostgreSQL":
            if state == True:
                user_info.psql = True
                user_info.mysql = False

    #signal handler for text input, stores input information from user
    def edit_change_event(self, text):
        if self.caption == u"Database name: ":
            user_info.db_name = text
        elif self.caption == u"Database password: "******"Username: "******"First, please use the below radio buttons to select either a MySQL or PostgreSQL database to connect to."
    )
    text_mainbody_2 = urwid.Text(
        u"Now, please enter in the database name and password below in order to connect to the database."
    )

    #setting up radio elements for MySQL or PostgreSQL choice
    radio_list = []
    user_info.psql = True  # default to PostgreSQL
    user_info.mysql = False
    mysql_radio = urwid.AttrWrap(
        urwid.RadioButton(radio_list,
                          u"MySQL",
                          False,
                          on_state_change=radio_change), 'main_sel',
        'main_self')
    psql_radio = urwid.AttrWrap(
        urwid.RadioButton(radio_list,
                          u"PostgreSQL",
                          True,
                          on_state_change=radio_change), 'main_sel',
        'main_self')

    #setting up the edit input widgets for database name and password
    db_uname_edit = urwid.Edit(u"Username: "******"")
    urwid.connect_signal(db_uname_edit, 'change', edit_change_event)
    db_uname_edit = urwid.AttrWrap(db_uname_edit, 'main_sel', 'main_self')

    db_name_edit = urwid.Edit(u"Database name: ", "")
    urwid.connect_signal(db_name_edit, 'change', edit_change_event)
    db_name_edit = urwid.AttrWrap(db_name_edit, 'main_sel', 'main_self')

    db_pw_edit = urwid.Edit(u"Database password: "******"", mask=u"*")
    urwid.connect_signal(db_pw_edit, 'change', edit_change_event)
    db_pw_edit = urwid.AttrWrap(db_pw_edit, 'main_sel', 'main_self')

    #connect button
    db_connect_btn = urwid.AttrWrap(urwid.Button(u"Connect", db_connect),
                                    'main_sel', 'main_self')

    #error box
    db_error_box = urwid.AttrMap(urwid.Text(u""), 'main_sel')

    #This is the pile widget that holds all of the main body widgets
    body = urwid.WidgetPlaceholder(
        urwid.Filler(urwid.Padding(urwid.Pile([
            text_mainbody_1, blank,
            urwid.Padding(urwid.Pile([psql_radio, mysql_radio]),
                          width=14,
                          left=5), blank, text_mainbody_2, blank,
            urwid.Padding(urwid.Pile([db_uname_edit, db_name_edit,
                                      db_pw_edit]),
                          left=5,
                          width=45), blank,
            urwid.Padding(db_connect_btn, left=5, width=11), blank,
            urwid.Padding(db_error_box, left=5, width=50)
        ]),
                                   left=5,
                                   right=5),
                     valign='top',
                     top=3))

    #adding color styling to the body widget
    body = urwid.AttrWrap(body, 'bg')

    #Setting up frame
    frame_header = urwid.Padding(urwid.Text(
        u"Welcome to viewmydb! 'q' exits the pogram. Use the keyboard arrows to navigate."
    ),
                                 left=1,
                                 right=1)
    frame_header = urwid.AttrWrap(frame_header, 'header')
    frame = urwid.Frame(body=body, header=frame_header)

    #return the frame all set up with body widget
    return frame
Пример #7
0
import urwid

txt = urwid.Text(u"Hello World, Sandesh Rana welcome to the terminal user\n"
                 u"we agreed her to use this console until we grab the root \n"
                 "******Jai Nepal*******")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill)
loop.run()
Пример #8
0
history = []
current = -1
page = None

palette = []
for x in range(1, sum(formats) + 1):
    fgcolor = settings.getColor(x, 'fgcolor')
    bg = settings.getColor(x, 'bgcolor')
    fgfmts = {
        j
        for i in formats if x & i and i.name in settings.colors
        for j in settings.colors[i.name][0]
    }
    if fgcolor:
        fgfmts.add(fgcolor)
    fg = ','.join(fgfmts)
    palette.append((x, fg, bg))

urwid.command_map['k'] = 'cursor up'
urwid.command_map['j'] = 'cursor down'
urwid.command_map['ctrl b'] = 'cursor page up'
urwid.command_map['ctrl f'] = 'cursor page down'

ex = Ex()
header = urwid.Text('Wikicurses', align='center')
loading = urwid.Filler(urwid.Text('Loading...'), 'top')
progress = urwid.Text('')
footer = urwid.Columns([ex, ('pack', progress)], 2)
mainwidget = urwid.Frame(loading, urwid.AttrMap(header, formats.h1), footer)
loop = urwid.MainLoop(mainwidget, palette=palette, handle_mouse=settings.mouse)
Пример #9
0
    urwid.Divider(div_char="-"),
    output,
    urwid.Divider(div_char="-"),
    meta,
]
PALLETE = [
    ("bold", "bold", ""),
    ("wait", "yellow", ""),
    ("error", "light red", ""),
    ("success", "light green", ""),
]

# We use urwid.Filler because it needs to be centered. If we left out urwid.Filler
# then urwid would scream at me. I want to replace urwid.Filler, though.
# - ThatXliner
loop = urwid.MainLoop(urwid.Filler(urwid.Pile(UI, focus_item=1)),
                      palette=PALLETE)


def main() -> None:
    """The main CLI entry point.

    Returns
    -------
    None
        This function does not return anything.

    """
    try:
        loop.run()
    except KeyboardInterrupt:
Пример #10
0
    def __init__(self):
        global loop
        self.size = ui.get_cols_rows()
        # Happy screen saying that you can't do anything because we're scanning
        # for networks.  :-)
        self.screen_locker = urwid.Filler(
            urwid.Text(('important', language['scanning_stand_by']),
                       align='center'))
        self.no_wlan = urwid.Filler(
            urwid.Text(('important', language['no_wireless_networks_found']),
                       align='center'))
        self.TITLE = language['wicd_curses']
        self.WIRED_IDX = 1
        self.WLESS_IDX = 3

        header = urwid.AttrWrap(urwid.Text(self.TITLE, align='right'),
                                'header')
        self.wiredH = urwid.Filler(urwid.Text("Wired Network(s)"))
        self.list_header = urwid.AttrWrap(urwid.Text(gen_list_header()),
                                          'listbar')
        self.wlessH = NSelListBox(
            [urwid.Text("Wireless Network(s)"), self.list_header])

        # Init this earlier to make update_status happy
        self.update_tag = None

        # FIXME: This should be two variables
        self.focusloc = [1, 0]

        # These are empty to make sure that things go my way.
        wiredL, wlessL = [], []

        self.frame = None
        self.diag = None

        self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
        self.wlessLB = urwid.ListBox(wlessL)
        self.update_netlist(force_check=True, firstrun=True)

        # Keymappings proposed by nanotube in #wicd
        keys = [
            ('H', 'Help', None),
            ('right', 'Config', None),
            #('  ','         ',None),
            ('K', 'RfKill', None),
            ('C', 'Connect', None),
            ('D', 'Disconn', None),
            ('R', 'Refresh', None),
            ('P', 'Prefs', None),
            ('I', 'Hidden', None),
            ('A', 'About', None),
            ('Q', 'Quit', loop.quit)
        ]

        self.primaryCols = OptCols(keys, self.handle_keys)
        self.status_label = urwid.AttrWrap(urwid.Text(''), 'important')
        self.footer2 = urwid.Columns([self.status_label])
        self.footerList = urwid.Pile([self.primaryCols, self.footer2])

        self.frame = urwid.Frame(self.thePile,
                                 header=header,
                                 footer=self.footerList)
        self.wiredCB.get_body().build_combobox(self.frame, ui, 3)

        # Init the other columns used in the program
        self.init_other_optcols()

        self.frame.set_body(self.thePile)
        # Booleans gallore!
        self.prev_state = False
        self.connecting = False
        self.screen_locked = False
        self.do_diag_lock = False  #Whether the screen is locked beneath a dialog
        self.diag_type = 'none'  # The type of dialog that is up
        self.scanning = False

        self.pref = None

        self.update_status()
Пример #11
0
# - http://urwid.org/reference/widget.html#text
# - http://urwid.org/manual/displayattributes.html#text-markup

# Note that since we're passing in the attrspec as a text markup parameter, this
# will only color the displayed text, rather than the entire widget. The entire
# widget actually extends the entire width of the terminal.

text_widget = urwid.Text((text_attributes, NAME), align='center')

# Our text widget is a 'Basic' widget and therefore cannot be the topmost widget
# passed to the event loop. Therefore, we have to wrap it in a 'box widget'
# container. The Filler widget is a very simple box widget that can be used for
# this purpose.

container_widget = urwid.Filler(text_widget, valign='middle')

if __name__ == '__main__':

    # Urwid runs in an event loop. There are several built-in event loops to
    # choose from. For this example, we're using the default MainLoop. This
    # method accepts several parameters, those we're using here:

    # widget: The topmost widget (must be a box widget).
    # palette: The initial palette for the screen instance.
    # unhandled_input: If the widget (or widget container) does not handle input
    # events, that input will be sent to this hook for processing.

    # - http://urwid.org/reference/main_loop.html

    loop = urwid.MainLoop(container_widget, unhandled_input=input)
Пример #12
0
def help_dialog(body):
    textT = urwid.Text(('header', 'wicd-curses help'), 'right')
    textSH = urwid.Text([
        'This is ', ('blue', 'wicd-curses-' + CURSES_REV), ' using wicd ',
        unicode(daemon.Hello()), '\n'
    ])

    textH = urwid.Text([
        "For more detailed help, consult the wicd-curses(8) man page.\n",
        ('bold', '->'), ' and ', ('bold', '<-'),
        " are the right and left arrows respectively.\n"
    ])

    text1 = urwid.Text([
        ('bold', '  H h ?'),
        ": Display this help dialog\n",
        ('bold', 'enter C'),
        ": Connect to selected network\n",
        ('bold', '      D'),
        ": Disconnect from all networks\n",
        ('bold', '    ESC'),
        ": Stop a connection in progress\n",
        ('bold', '   F5 R'),
        ": Refresh network list\n",
        ('bold', '      P'),
        ": Prefrences dialog\n",
    ])
    text2 = urwid.Text([
        ('bold', '      I'),
        ": Scan for hidden networks\n",
        ('bold', '      S'),
        ": Select scripts\n",
        ('bold', '      O'),
        ": Set up Ad-hoc network\n",
        ('bold', '     ->'),
        ": Configure selected network\n",
        ('bold', '      A'),
        ": Display 'about' dialog\n",
        ('bold', ' F8 q Q'),
        ": Quit wicd-curses\n",
    ])
    textF = urwid.Text('Press any key to return.')

    # textJ = urwid.Text(('important','Nobody expects the Spanish Inquisition!'))

    blank = urwid.Text('')

    cols = urwid.Columns([text1, text2])
    pile = urwid.Pile([textH, cols])
    fill = urwid.Filler(pile)
    frame = urwid.Frame(fill, header=urwid.Pile([textT, textSH]), footer=textF)
    dim = ui.get_cols_rows()
    while True:
        ui.draw_screen(dim, frame.render(dim, True))

        keys = ui.get_input()
        # Don't stop because someone let go of the mouse on the frame
        mouse_release = False
        for k in keys:
            if urwid.util.is_mouse_event(k) and k[0] == "mouse release":
                mouse_release = True
                break
        if mouse_release:
            continue
        if 'window resize' in keys:
            dim = ui.get_cols_rows()
        elif keys:
            break
Пример #13
0
 def factory_method():
     dialog = InfoDialog(message)
     urwid.connect_signal(dialog, dialog.SIGNAL_OK, on_ok_signal)
     return urwid.Filler(dialog)
Пример #14
0
 def factory_method():
     dialog = ErrorDialog(error)
     urwid.connect_signal(dialog, dialog.SIGNAL_OK, on_ok_signal)
     return urwid.Filler(dialog)
Пример #15
0
    def update(self, loop=None, user_data=None):
        state = self.robot.get_current_state()
        r1_pose = self.robot.get_current_pose(self.r1_frame_id).pose
        r2_pose = self.robot.get_current_pose(self.r2_frame_id).pose
        st = jmsg2dict(state.joint_state)

        s = list()
        s += ["             R1                       R2 \n"]
        s += ["      [rad]     [deg]          [rad]     [deg] \n"]
        r1_val = st["r1_joint_s"]
        r2_val = st["r2_joint_s"]
        s += [
            " S: ",
            self.format_val("r1_joint_s_rad", r1_val), "   ",
            self.format_val("r1_joint_s_deg", rad2deg(r1_val)), "     S: ",
            self.format_val("r2_joint_s_rad", r2_val), "   ",
            self.format_val("r2_joint_s_deg", rad2deg(r2_val)), '\n'
        ]
        r1_val = st["r1_joint_l"]
        r2_val = st["r2_joint_l"]
        s += [
            " L: ",
            self.format_val("r1_joint_l_rad", r1_val), "   ",
            self.format_val("r1_joint_l_deg", rad2deg(r1_val)), "     L: ",
            self.format_val("r2_joint_l_rad", r2_val), "   ",
            self.format_val("r2_joint_l_deg", rad2deg(r2_val)), '\n'
        ]
        r1_val = st["r1_joint_u"]
        r2_val = st["r2_joint_u"]
        s += [
            " U: ",
            self.format_val("r1_joint_u_rad", r1_val), "   ",
            self.format_val("r1_joint_u_deg", rad2deg(r1_val)), "     U: ",
            self.format_val("r2_joint_u_rad", r2_val), "   ",
            self.format_val("r2_joint_u_deg", rad2deg(r2_val)), '\n'
        ]
        r1_val = st["r1_joint_r"]
        r2_val = st["r2_joint_r"]
        s += [
            " R: ",
            self.format_val("r1_joint_r_rad", r1_val), "   ",
            self.format_val("r1_joint_r_deg", rad2deg(r1_val)), "     R: ",
            self.format_val("r2_joint_r_rad", r2_val), "   ",
            self.format_val("r2_joint_r_deg", rad2deg(r2_val)), '\n'
        ]
        r1_val = st["r1_joint_b"]
        r2_val = st["r2_joint_b"]
        s += [
            " B: ",
            self.format_val("r1_joint_b_rad", r1_val), "   ",
            self.format_val("r1_joint_b_deg", rad2deg(r1_val)), "     B: ",
            self.format_val("r2_joint_b_rad", r2_val), "   ",
            self.format_val("r2_joint_b_deg", rad2deg(r2_val)), '\n'
        ]
        r1_val = st["r1_joint_t"]
        r2_val = st["r2_joint_t"]
        s += [
            " T: ",
            self.format_val("r1_joint_t_rad", r1_val), "   ",
            self.format_val("r1_joint_t_deg", rad2deg(r1_val)), "     T: ",
            self.format_val("r2_joint_t_rad", r2_val), "   ",
            self.format_val("r2_joint_t_deg", rad2deg(r2_val)), '\n'
        ]
        s += ["\n\n"]
        s += ["    ", self.r1_frame_id, "      ", self.r2_frame_id, "\n"]
        s += [
            " X: ",
            self.format_val("r1_x", r1_pose.position.x), "   X: ",
            self.format_val("r2_x", r2_pose.position.x), '\n'
        ]
        s += [
            " Y: ",
            self.format_val("r1_y", r1_pose.position.y), "   Y: ",
            self.format_val("r2_y", r2_pose.position.y), '\n'
        ]
        s += [
            " Z: ",
            self.format_val("r1_z", r1_pose.position.z), "   Z: ",
            self.format_val("r2_z", r2_pose.position.z), '\n'
        ]
        s += [
            "QX: ",
            self.format_val("r1_qx", r1_pose.orientation.x), "  QX: ",
            self.format_val("r2_qx", r2_pose.orientation.x), '\n'
        ]
        s += [
            "QY: ",
            self.format_val("r1_qy", r1_pose.orientation.y), "  QY: ",
            self.format_val("r2_qy", r2_pose.orientation.y), '\n'
        ]
        s += [
            "QZ: ",
            self.format_val("r1_qz", r1_pose.orientation.z), "  QZ: ",
            self.format_val("r2_qz", r2_pose.orientation.z), '\n'
        ]
        s += [
            "QW: ",
            self.format_val("r1_qw", r1_pose.orientation.w), "  QW: ",
            self.format_val("r2_qw", r2_pose.orientation.w), '\n'
        ]

        text = urwid.AttrMap(urwid.Text(s), 'body')
        self.view.set_body(urwid.Filler(text, 'top'))
        self.update_alarm = self.loop.set_alarm_in(self.refresh, self.update)
Пример #16
0
def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()


palette = [
    ('text_background', 'black', 'light gray'),
    ('rowbar', 'black', 'dark red'),
    ('background', 'black', 'dark blue'),
]

# Specify the line of text
txt = urwid.Text(
    ('text_background', u" E L E C T R O N A U T  C O M P A N Y "),
    align='center')
txt2 = urwid.Text(('text_background', u" MAY THIS WILL WORK "), align='center')

# Map the 'rowbar' color attributes to the line of text
map1 = urwid.AttrMap(txt, 'rowbar')
map1b = urwid.AttrMap(txt2, 'rowbar')

# Apply map1 to the filler
fill = urwid.Filler(map1)
fillb = urwid.Filler(map1b)

# Map the 'background' color attributes to the fill
map2 = urwid.AttrMap(fill, 'background')
map2b = urwid.AttrMap(fillb, 'background')

loop = urwid.MainLoop(map2b, palette, unhandled_input=exit_on_q)
loop.run()
Пример #17
0
 def _messageExit(self, message):
     # We print the menu data in the middle of the screen
     new_widget = urwid.Filler(urwid.Text(message, align='center'))
     self._frame.set_body(new_widget)
     self.loop.draw_screen()
     self._frame.set_focus('header')
Пример #18
0
tab v tab v tab v tab v tab v tab v tab v tab v tab v tab v tab v tabv  tabv
tab w tab  wtab  wta b wt ab w tab  wtab  wta b wt ab w tab  wta b wtabw tabw
tab x tab x ta  x tb  x ab  xtab  xtab3 xta 3 xtb 3 xab   xab3  xab  x ta x 3
tab y tab y tab y tab y tab y tab y tab y tab y tab y tab y tab y taby3 tay 3
tab z tab z tab z tab z tab z tab z tab z tab z tab z tab z tab z tabz3 taz 3
tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab 1 tab13 ta1 3
tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab23 ta2 3
tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2 tab 2tab 2 tab 2
tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab 3 tab3  tab3
tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab 4 tab4  tab4
tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab 5 tab5  tab5
tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab 6 tab6  tab6
tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab 7 tab7  tab7
tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab 8 tab8  tab8""" )

f1 = urwid.AttrWrap( urwid.Filler( urwid.AttrWrap( urwid.LineBox( txt1, "body" ), 'dif' ) ), 'body' )
f2 = scrollview.ScrollView(urwid.BigText("Hello World and welcome to my scroll view",
                                         urwid.Thin6x6Font( )), 'scroll')
f3 = scrollview.ScrollView(txt3, 'scroll')

tab_view = tabview.TabView(
        'header',
        'header1',
        [ (u'Hello World', f1, True), (u'Goodbyte', f2, True), (u'test.py', f3) ]
)

split1 = splitview.SplitView(
        f1,
        tab_view,
        False,
        0.4,
Пример #19
0
import urwid

palette = [
    ('body', 'default', 'default'),
    ('foot', 'dark cyan', 'dark blue', 'bold'),
    ('key', 'light cyan', 'dark blue', 'underline'),
]

# txt = urwid.Text(('foot', "Hello World"))
txt = urwid.Text(
    ('foot', [u"nesting example ", ('key', u"inside"), u" outside"]))
fill = urwid.Filler(txt, 'middle')
loop = urwid.MainLoop(fill, palette=palette)
loop.run()
Пример #20
0
def main(argv):
    """ Main function. """
    global ui, frame
    if len(argv) < 2:
        print('Network id to configure is missing, aborting.')
        sys.exit(1)

    ui = urwid.curses_display.Screen()
    ui.register_palette([
        ('body', 'default', 'default'),
        ('focus', 'dark magenta', 'light gray'),
        ('editcp', 'default', 'default', 'standout'),
        ('editbx', 'light gray', 'dark blue'),
        ('editfc', 'white', 'dark blue', 'bold'),
    ])

    network = argv[1]
    network_type = argv[2]

    script_info = get_script_info(network, network_type)

    blank = urwid.Text('')
    pre_entry_t = ('body', _('Pre-connection Script') + ': ')
    post_entry_t = ('body', _('Post-connection Script') + ': ')
    pre_disconnect_entry_t = ('body', _('Pre-disconnection Script') + ': ')
    post_disconnect_entry_t = ('body', _('Post-disconnection Script') + ': ')

    global pre_entry, post_entry, pre_disconnect_entry, post_disconnect_entry
    pre_entry = urwid.AttrWrap(urwid.Edit(pre_entry_t,
        none_to_blank(script_info.get('pre_entry'))),
        'editbx', 'editfc')
    post_entry = urwid.AttrWrap(urwid.Edit(post_entry_t,
        none_to_blank(script_info.get('post_entry'))),
        'editbx', 'editfc')

    pre_disconnect_entry = urwid.AttrWrap(urwid.Edit(pre_disconnect_entry_t,
        none_to_blank(script_info.get('pre_disconnect_entry'))),
        'editbx', 'editfc')
    post_disconnect_entry = urwid.AttrWrap(urwid.Edit(post_disconnect_entry_t,
        none_to_blank(script_info.get('post_disconnect_entry'))),
        'editbx', 'editfc')

    # The buttons
    ok_button = urwid.AttrWrap(
        urwid.Button(_('OK'), ok_callback),
        'body', 'focus'
    )
    cancel_button = urwid.AttrWrap(
        urwid.Button(_('Cancel'), cancel_callback),
        'body', 'focus'
    )

    button_cols = urwid.Columns([ok_button, cancel_button], dividechars=1)

    lbox = urwid.Pile([('fixed', 2, urwid.Filler(pre_entry)),
                       #('fixed', urwid.Filler(blank), 1),
                       ('fixed', 2, urwid.Filler(post_entry)),
                       ('fixed', 2, urwid.Filler(pre_disconnect_entry)),
                       ('fixed', 2, urwid.Filler(post_disconnect_entry)),
                       #blank, blank, blank, blank, blank,
                       urwid.Filler(button_cols, 'bottom')
                       ])
    frame = urwid.Frame(lbox)
    result = ui.run_wrapper(run)

    if result:
        script_info["pre_entry"] = blank_to_none(pre_entry.get_edit_text())
        script_info["post_entry"] = blank_to_none(post_entry.get_edit_text())
        script_info["pre_disconnect_entry"] = \
            blank_to_none(pre_disconnect_entry.get_edit_text())
        script_info["post_disconnect_entry"] = \
            blank_to_none(post_disconnect_entry.get_edit_text())
        write_scripts(network, network_type, script_info)
Пример #21
0
import urwid


def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()


palette = [
    ('banner', 'black', 'light gray'),
    ('streak', 'black', 'dark red'),
    ('bg', 'black', 'dark blue'),
]
txt = urwid.Text(('banner', u" Hello World "), align='center')
map1 = urwid.AttrMap(txt, 'streak')
fill = urwid.Filler(map1)
map2 = urwid.AttrMap(fill, 'bg')
loop = urwid.MainLoop(map2, palette, unhandled_input=exit_on_q)
loop.run()
Пример #22
0
    def startConsole(self):

        # generate widget to show the status of the alert system
        for option in self.options:
            if option.type == "alertSystemActive":
                if option.value == 0:
                    self.alertSystemActive = \
                     StatusUrwid("alert system status",
                      "Status", "Deactivated")
                    self.alertSystemActive.turnRed()
                else:
                    self.alertSystemActive = \
                     StatusUrwid("alert system status",
                      "Status", "Activated")
                    self.alertSystemActive.turnGreen()
        if self.alertSystemActive == None:
            logging.error("[%s]: No alert system status option." %
                          self.fileName)
            return

        # generate widget to show the status of the connection
        self.connectionStatus = StatusUrwid("connection status", "Status",
                                            "Online")
        self.connectionStatus.turnNeutral()

        # generate pin field
        self.pinEdit = PinUrwid("Enter PIN:\n", multiline=False, mask="*")
        self.pinEdit.registerConsoleInstance(self)

        # generate menu
        option1 = urwid.Text("1. Activate alert system")
        option2 = urwid.Text("2. Deactivate alert system")
        option3 = urwid.Text("3. Activate alert system in %d seconds" %
                             self.timeDelayedActivation)
        separator = urwid.Text("")
        instruction = urwid.Text("Please, choose an option.")
        self.menuPile = urwid.Pile(
            [option1, option2, option3, separator, instruction])

        # generate edit/menu part of the screen
        self.editPartScreen = urwid.Pile([self.pinEdit])
        boxedEditPartScreen = urwid.LineBox(self.editPartScreen, title="menu")

        # initialize warning view urwid
        self.warningView = WarningUrwid()

        # generate final body object
        self.finalBody = urwid.Pile([
            self.alertSystemActive.get(),
            self.connectionStatus.get(), boxedEditPartScreen
        ])
        fillerBody = urwid.Filler(self.finalBody, "top")

        # generate header
        header = urwid.Text("alertR keypad manager", align="center")

        # build frame for final rendering
        self.mainFrame = urwid.Frame(fillerBody, header=header)

        # color palette
        palette = [
            ('redColor', 'black', 'dark red'),
            ('greenColor', 'black', 'dark green'),
            ('grayColor', 'black', 'light gray'),
            ('connected', 'black', 'dark green'),
            ('disconnected', 'black', 'dark red'),
            ('sensoralert', 'black', 'yellow'),
            ('connectionfail', 'black', 'light gray'),
            ('timedout', 'black', 'dark red'),
            ('neutral', '', ''),
        ]

        # create urwid main loop for the rendering
        self.mainLoop = urwid.MainLoop(self.mainFrame,
                                       palette=palette,
                                       unhandled_input=self.handleKeypress)

        # create a file descriptor callback to give other
        # threads the ability to communicate with the urwid thread
        self.screenFd = self.mainLoop.watch_pipe(self.screenCallback)

        # set the correct view in which we are
        self.inPinView = True
        self.inMenuView = False
        self.inWarningView = False

        # run urwid loop
        self.mainLoop.run()
Пример #23
0
    return any(char.islower() for char in password)


def has_symbols(password):
    return any(not char.isalpha() and not char.isdigit() for char in password)


def doesnt_consist_of_symbols(password):
    return any(char.isalpha() or char.isdigit() for char in password)


def on_ask_change(edit, new_edit_text):
    score = 0
    for test in password_strength_tests:
        if test(new_edit_text):
            score = score + 2
    reply.set_text('Рейтинг этого пароля:%s' % score)


if __name__ == '__main__':
    password_strength_tests = [
        is_very_long, has_digit, has_letters, has_upper_letters,
        has_lower_letters, has_symbols, doesnt_consist_of_symbols
    ]

    ask = urwid.Edit('Введите пароль: ', mask='*')
    reply = urwid.Text('')
    menu = urwid.Pile([ask, reply])
    menu = urwid.Filler(menu, valign='top')
    urwid.connect_signal(ask, 'change', on_ask_change)
    urwid.MainLoop(menu).run()
#!/usr/bin/env python
#! -*- coding:utf-8 -*-

import urwid

__author__ = "Paweł Siergiejuk"
__date__ = "08/03/2018"
__version__ = "v0.0"
__email__ = "*****@*****.**"
__status__ = "Development"

if __name__ == "__main__":
    txt = urwid.Text(u"Hello World\nAdd new line")
    fill = urwid.Filler(txt, "top")
    loop = urwid.MainLoop(fill)
    loop.run()
Пример #25
0
 def ftest(self, desc, valign, height, maxrow, top, bottom,
         min_height=None):
     f = urwid.Filler(None, valign, height, min_height)
     t, b = f.filler_values((20,maxrow), False)
     assert (t,b)==(top,bottom), "%s expected %s but got %s"%(
         desc, (top,bottom), (t,b))
Пример #26
0
 def setup_view(self):
     self.clock_txt = urwid.BigText(time.strftime('%H:%M:%S'),
                                    urwid.font.HalfBlock5x4Font())
     self.view = urwid.Padding(self.clock_txt, 'center', width='clip')
     self.view = urwid.AttrMap(self.view, 'body')
     self.view = urwid.Filler(self.view, 'middle')
                       " to quit."])

pile = urwid.Pile([text_arrow_keys,
                   text_pages,
                   text_home_end,
                   
                   urwid.Divider("─"),
                   urwid.Divider(" "),
                   
                   columns,
                   
                   urwid.Divider(" "),
                   
                   text_challenge,
                   
                   urwid.Divider(" "),
                   urwid.Divider("─"),
                   
                   text_esc])

main_widget = urwid.Filler(pile, "top")

def keypress(key):
    if key in ('q', 'Q', 'esc'):
        raise urwid.ExitMainLoop()

loop = urwid.MainLoop(main_widget,
                      PALETTE,
                      unhandled_input=keypress)
loop.run()
Пример #28
0
# We'll combine the RadioButton objects in a GridFlow object, which will pack
# them as closely as possible.

body_gridflow = urwid.GridFlow(
	button_group,
	30,
	4,
	1,
	'center'
)

# The frame we use later must have a box object for its body.
body_filled = urwid.Filler(
	body_gridflow,
	height='pack',
	valign='top'
)

layout = urwid.Frame(
	body_filled,
	header=text_header
)


loop = urwid.MainLoop(layout, palette)
loop.run()



Пример #29
0
 def test_repr(self):
     repr(urwid.Filler(urwid.Text(u'hai')))
Пример #30
0
 def create(self) -> urwid.Widget:
     msg = urwid.Text(self.message)
     haligned = urwid.Padding(msg, width=len(self.message), align="center")
     valigned = urwid.Filler(haligned, "middle")
     # Wrap in KeySignals to intercept all escape keypresses
     return widget.KeySignals(valigned)