Ejemplo n.º 1
0
def main():
    text_header = (u"hi!  "
                   u"UP / DOWN / PAGE UP / PAGE DOWN scroll.  F8 exits.")
    Radio_Text = [
        u"Select ",
        ('important', u"one"),
    ]
    Multiselect_Text = [
        u"Select ",
        ('important', u"many"),
    ]
    MultiSelect_Options = [
        u"Wax", u"Wash", u"Buff", u"Clear Coat", u"Dry", u"Racing Stripe"
    ]
    Radio_Options = [u"opt1", u"opt2", u"opt3"]

    def button_press(button):
        frame.footer = urwid.AttrWrap(
            urwid.Text([u"Pressed: ", button.get_label()]), 'header')

    radio_button_group = []

    blank = urwid.Divider()
    listbox_content = [
        blank,
        urwid.Padding(urwid.Text(Radio_Text), left=2, right=2, min_width=20),
        blank,
        urwid.Padding(urwid.GridFlow([
            urwid.AttrWrap(urwid.RadioButton(radio_button_group, txt), 'buttn',
                           'buttnf') for txt in Radio_Options
        ], 23, 7, 1, 'left'),
                      left=3,
                      right=3,
                      min_width=20),
        blank,
        urwid.Padding(urwid.Text(Multiselect_Text),
                      left=2,
                      right=2,
                      min_width=20),
        blank,
        urwid.Padding(urwid.GridFlow([
            urwid.AttrWrap(urwid.CheckBox(txt), 'buttn', 'buttnf')
            for txt in MultiSelect_Options
        ], 10, 3, 1, 'left'),
                      left=4,
                      right=3,
                      min_width=10),
        blank,
        blank,
    ]

    header = urwid.AttrWrap(urwid.Text(text_header), 'header')
    listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content))
    frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header)

    palette = [
        ('body', 'black', 'light gray', 'standout'),
        ('reverse', 'light gray', 'black'),
        ('header', 'white', 'dark red', 'bold'),
        ('important', 'dark blue', 'light gray', ('standout', 'underline')),
        ('editfc', 'white', 'dark blue', 'bold'),
        ('editbx', 'light gray', 'dark blue'),
        ('editcp', 'black', 'light gray', 'standout'),
        ('bright', 'dark gray', 'light gray', ('bold', 'standout')),
        ('buttn', 'black', 'dark cyan'),
        ('buttnf', 'white', 'dark blue', 'bold'),
    ]

    # use appropriate Screen class
    if urwid.web_display.is_web_request():
        screen = urwid.web_display.Screen()
    else:
        screen = urwid.raw_display.Screen()

    def unhandled(key):
        if key == 'f8':
            raise urwid.ExitMainLoop()

    urwid.MainLoop(frame, palette, screen, unhandled_input=unhandled).run()
Ejemplo n.º 2
0
 def __init__(self, session):
     self.session = session
     self.status = urwid.Text('Stopped')
     self.__super.__init__([urwid.Divider('─'), self.status])
Ejemplo n.º 3
0
    def handle_input(self, key):
        """Handle user input that was not handled by active urwid components.

        :param key: User input to process
        :type key: str
        :return: None
        """

        if key == 'F' or key == 'f':
            header_text = urwid.Text(u'%s' % self.cc.config['name'], align='center')
            if self.force_mode:
                header = urwid.Pile([
                    urwid.Divider(),
                    urwid.AttrMap(header_text, 'titlebar')
                ])
            else:
                header = urwid.Pile([
                    urwid.Divider(), urwid.AttrMap(header_text, 'titlebar'),
                    urwid.AttrMap(urwid.Text(u'FORCE MODE ACTIVE', align='center'), 'force_mode')
                ])
            self.force_mode = not self.force_mode
            self.layout.header = header

        if key == 'Q' or key == 'q':
            main_loop.widget = urwid.Frame(self.shutdown_overlay)

        if key == 'esc':
            self.dismiss_popup()

        if key == 'K' or key == 'k':
            if self.log_hidden:
                self.log_placeholder.original_widget = self.logger_section
                self.log_hidden = False
            else:
                if not self.tail_log:
                    self.layout.focus_position = 'body'
                    self.tail_log = True
                self.log_placeholder.original_widget = urwid.Pile([])
                self.log_hidden = True

        if key == 'C' or key == 'c':
            selection, index = self.content_walker.get_focus()
            if isinstance(selection, urwid.GridFlow):
                index = self.additional_content_grid.focus_position
                if index > 0:  # Not 'All Components/Host Stats' Pile in Grid flow
                    # Grants LogTextWalker
                    comp_id = self.additional_content_grid[index].body.title
                    log = self.comp_log_map[comp_id]
                    self.additional_content_grid.contents.remove((log, self.additional_content_grid.options()))
                    self.comp_log_map[comp_id] = None

        if key == 'L' or key == 'l':
            if not self.log_hidden:
                if self.tail_log:
                    self.layout.focus_position = 'footer'
                    self.tail_log = False
                else:
                    self.layout.focus_position = 'body'
                    self.tail_log = True

        if key == 'H' or key == 'h':
            main_loop.widget = urwid.Frame(self.help_overlay)
Ejemplo n.º 4
0
    def __init__(self, cc, event_queue, log_file_path):
        """Initialize StateController constructing the urwid UI.

        :param cc: Reference to core application
        :type cc: hyperion.ControlCenter
        """

        self.cc = cc
        self.selected_group = None
        self.groups = {}
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(config.DEFAULT_LOG_LEVEL)
        self.event_queue = event_queue
        self.log_viewer = LogTextWalker(log_file_path, "Main")
        self.tail_log = True
        self.states = {}
        self.host_stats = None
        self.log_hidden = False
        self.force_mode = False

        self.comp_log_map = {}

        header_text = urwid.Text(u'%s' % cc.config['name'], align='center')
        header = urwid.Pile([urwid.Divider(), urwid.AttrMap(header_text, 'titlebar')])

        self.load_groups_from_config()

        self.radio_button_log_group = []
        group_col = self.group_col = urwid.Columns([], 1)
        components_pile = self.components_pile = urwid.Pile([])
        host_pile = self.host_pile = urwid.Pile([
            urwid.Columns([
                urwid.AttrMap(SimpleButton('Host 1'), 'host', focus_map='reversed'),
                urwid.Text('16', align='center'),
                urwid.Text('100%', align='center'),
                urwid.Text('100%', align='center')
            ], 1),

            urwid.Columns([
                urwid.AttrMap(SimpleButton('Host 2'), 'host', focus_map='reversed'),
                urwid.Text('1.6', align='center'),
                urwid.Text('100%', align='center'),
                urwid.Text('100%', align='center')
            ], 1),

            urwid.Columns([
                urwid.AttrMap(SimpleButton('Host 3'), 'host', focus_map='reversed'),
                urwid.Text('4', align='center'),
                urwid.Text('100%', align='center'),
                urwid.Text('100%', align='center')
            ], 1)
        ])

        self.additional_content_grid = urwid.GridFlow([
            urwid.Columns([
                urwid.Pile([
                    urwid.LineBox(urwid.Pile([
                        urwid.Columns([
                            SimpleButton('Start', self.handle_start_all),
                            SimpleButton('Stop', self.handle_stop_all),
                            SimpleButton('Check', self.handle_check_all),
                            SimpleButton('Reload Config', self.handle_reload_config)
                        ], 1)
                    ]), 'All Components'),

                    urwid.LineBox(
                        urwid.Pile([
                            urwid.AttrMap(urwid.Text('Host Stats', align='center'), 'titlebar'),
                            urwid.Divider(),
                            urwid.Columns([
                                urwid.AttrMap(urwid.Text('Hostname', align='center'), 'important'),
                                urwid.AttrMap(urwid.Text('Load AVG', align='center'), 'important'),
                                urwid.AttrMap(urwid.Text('CPU', align='center'), 'important'),
                                urwid.AttrMap(urwid.Text('MEM', align='center'), 'important')
                            ], 1),
                            host_pile
                        ])
                    )
                ]),
            ], 1),
        ],
            80, 3, 1, 'center'
        )

        blank = urwid.Divider()
        list_box_contents = [
            blank,
            urwid.Divider('='),
            group_col,
            urwid.Divider('='),
            urwid.Padding(urwid.LineBox(components_pile), left=2, right=2),
            self.additional_content_grid,
        ]

        self.logger_section = urwid.Pile([
            urwid.Divider(),
            urwid.Padding(urwid.Divider('#'), left=10, right=10),
            urwid.Divider(),
            urwid.AttrMap(
                urwid.LineBox(urwid.BoxAdapter(urwid.ListBox(self.log_viewer), 10), 'Hyperion Log'),
                None,
                'simple_button'),
        ])

        self.log_placeholder = urwid.WidgetPlaceholder(self.logger_section)

        menu = urwid.Pile([
            self.log_placeholder,
            urwid.Text([
                u'Press (', ('refresh button', u'K'), u') to show or hide Hyperion log | ',
                u'Press (', ('refresh button', u'L'), u') to jump into or out of Hyperion log | ',
                u'Press (', ('quit button', u'Q'), u') to quit.'
            ])
        ])

        self.fetch_group_items()
        self.setup_component_states()
        self.fetch_components()
        self.fetch_host_items()

        self.content_walker = urwid.SimpleListWalker(list_box_contents)

        main_body = self.main_body = urwid.ListBox(self.content_walker)
        self.layout = urwid.Frame(header=header, body=main_body, footer=menu)

        help = [
            urwid.Divider('='),
            urwid.Text(('titlebar', u'Help Menu'), "center"),
            urwid.Divider('='),
            urwid.Divider(),
            urwid.Text([u'Navigate through menus by using the ', ('host', u'arrow keys')], "center"),
            urwid.Divider(),
            urwid.Text([u'Click buttons with ', ('host', u'Enter'), u', ', ('host', u'Space'),
                        u' or with your ', ('host', u'Mouse')], "center"),
            urwid.Divider(),
            urwid.Text([u'Jump to or out of the application log by pressing ', ('host', u'L')], "center"),
            urwid.Divider(),
            urwid.Text([u'Press ', ('host', u'K'), u' to hide or un-hide the application log'], "center"),
            urwid.Divider(),
            urwid.Text([u'When focussing a component log press ', ('host', u'C'), u' to close it'], "center"),
            urwid.Divider(),
            urwid.Text([u'Press ', ('host', u'F'), u' to toggle force mode (if active component start is tried even if '
                                                   u'dependencies failed)'], "center"),
            urwid.Divider(),
            urwid.Text([u'Press ', ('host', u'H'), u' to show this help and ',
                        ('host', u'Esc'), u' to dismiss it'], "center"),
            urwid.Divider(),
            urwid.Text([u'Press ', ('quit button', u'Q'), u' to close the application'], "center"),
        ]

        help_box = urwid.AttrMap(urwid.LineBox(urwid.ListBox(urwid.SimpleListWalker(help))), 'popup')
        self.help_overlay = urwid.Overlay(help_box, self.layout, align='center', width=('relative', 60),
                                          valign='middle', height=('relative', 60))

        shutdown_box = urwid.AttrMap(
            urwid.LineBox(
                urwid.ListBox(urwid.SimpleFocusListWalker([
                    urwid.Divider('='),
                    urwid.Text(('titlebar', u'Shutdown Menu'), "center"),
                    urwid.Divider('='),
                    urwid.Divider(),
                    urwid.Text('Do you want to close all running processes?', "center"),
                    urwid.Columns([
                        urwid.AttrMap(SimpleButton('Yes', self.handle_shutdown, True), 'quit button'),
                        urwid.AttrMap(SimpleButton('No', self.handle_shutdown, False), 'host'),
                        SimpleButton('Cancel', self.dismiss_popup)
                    ])
                ]))
            ),
            'popup'
        )

        self.shutdown_overlay = urwid.Overlay(shutdown_box, self.layout, align='center', width=('relative', 60),
                                          valign='middle', height=('relative', 60))
Ejemplo n.º 5
0
In very old versions of OS X, such as 10.1 you had to install Languages Kits from Apple in order to read Chinese, Japanese or Korean on the Internet. The Language Kit for CJK contains WorldScript software known as scripts which support the encoding for the character set of a particular language. Each language needs a separate script. In more recent versions of OS X, it is included with all installations of OS X.

Once you have installed the Language Kit, just select the particular language character set that you need to see on the Internet page either from View > Encoding (for Microsoft IE) or View > Character set (for Netscape).
"""


LOREM_IPSUM_C = [
    [(SLR,word), u" "] if u"u" in word else
    [(SLB,word), u" "] if u"r" in word else word+u" "
    for word in LOREM_IPSUM.split(u" ")]


COLOR_WIDGETS = [urwid.Columns([
    urwid.Text(urwid.AttrSpec("h%d"%n,"").foreground, align=urwid.CENTER),
    urwid.AttrWrap(urwid.Divider(), urwid.AttrSpec("", "h%d"%n))])
    for n in range(256)]

class ColorLoop(urwid.ListWalker):
    def __init__(self, focus):
        self._focus = focus

    def get_focus(self):
        return COLOR_WIDGETS[self._focus], self._focus

    def set_focus(self, focus):
        self._focus = focus % 256
        self._modified()

    def get_next(self, start_from):
        pos = (start_from + 1) % 256
Ejemplo n.º 6
0
    def __init__(self, taskName):

        MODE_KEYS_EMACS = ["esc"]

        MODE_KEYS_VI = ["esc", "tab", "ctrl u", "ctrl U", "ctrl t", "ctrl T"]

        TPAR_BINDINGS = {  # Page level bindings
                          "quit"   : self.QUIT,
                          "exit "  : self.EXIT,
                          "help"   : self.HELP,
                          "end" : self.MOVE_END,
                          "home" : self.MOVE_START,
                         }

        # Get the Iraftask object
        if isinstance(taskName, irafpar.IrafParList):
            # IrafParList acts as an IrafTask for our purposes
            self.taskObject = taskName
        else:
            # taskName must be a string or an IrafTask object
            self.taskObject = iraf.getTask(taskName)

        # Now go back and ensure we have the full taskname
        self.taskName = self.taskObject.getName()
        self.pkgName = self.taskObject.getPkgname()
        self.paramList = self.taskObject.getParList(docopy=1)

        # See if there exist any special versions on disk to load
        self.__areAnyToLoad = irafpar.haveSpecialVersions(
            self.taskName, self.pkgName)  # irafpar caches them

        # Ignore the last parameter which is $nargs
        self.numParams = len(self.paramList) - 1

        # Get default parameter values for unlearn
        self.get_default_param_list()
        self.make_entries()

        self.escape = False

        if URWID_PRE_9P9:
            self._createButtonsOld()
        else:
            self._createButtons()

        self.colon_edit = PyrafEdit("",
                                    "",
                                    wrap="clip",
                                    align="left",
                                    inform=self.inform)
        self.listitems = [urwid.Divider(" ")] + self.entryNo + \
                         [urwid.Divider(" "), self.colon_edit,
                          self.buttons]
        self.listbox = urwid.ListBox(self.listitems)

        self.listbox.set_focus(1)
        self.footer = urwid.Text("")
        self.header = TparHeader(self.pkgName, self.taskName)

        self.view = urwid.Frame(self.listbox,
                                header=self.header,
                                footer=self.footer)

        self._editor = iraf.envget("editor")
        BINDINGS = {}
        BINDINGS.update(TPAR_BINDINGS)
        if self._editor == "vi":
            BINDINGS.update(TPAR_BINDINGS_VI)
            MODE_KEYS = MODE_KEYS_VI
        else:
            BINDINGS.update(TPAR_BINDINGS_EMACS)
            MODE_KEYS = MODE_KEYS_EMACS
        Binder.__init__(self, BINDINGS, self.inform, MODE_KEYS)