Exemple #1
0
 def __init__(self):
     if os.path.exists("zabbix_config.ini"):
         config = ConfigParser.ConfigParser()
         config.read("zabbix_config.ini")
         self.support = config.get("gui", "support")
         #self.output_debug = config.get("gui", "output_debug")
     else:
         sys.exit("Settings file not found.. exiting.")
     self.screen = snack.SnackScreen()
     self.screen.drawRootText(1, 1, "Zabbix tool%s"
                              % __version__)
     self.screen.drawRootText(int(c) - (10 + len(self.support)),
                              int(r) - 2,
                              "Support: %s" % self.support)
     self.screen.refresh()
     self.task_type = None
     self.action = None
     self.task_info = None
     self.task_usermod = None
     self.task_modcmt = None
     self.task_grpmod = None
     self.task_hosts = None
     self.task_hostsind = None
     self.user_comment = None
     self.task_debug = None
Exemple #2
0
def StartHotkeyScreen(sText):

    # Set screen mode
    os.environ['NEWT_MONO'] = "1"
    env_term = os.getenv("TERM").upper()
    if env_term == "VT100":
        print "\x1b[?25l"  # cursor off

    # Setup hotkey dictionary
    for x in string.ascii_letters:
        snack.hotkeys[x] = ord(x)
        snack.hotkeys[ord(x)] = x
    snack.hotkeys["ENTER"] = 0x0d
    snack.hotkeys[0x0d] = "ENTER"
    snack.hotkeys["PD"] = 0x800c
    snack.hotkeys[0x800c] = "PD"

    # Start snack's screen
    screen = snack.SnackScreen()
    screen.drawRootText(0, 0, sText)
    screen.pushHelpLine(" ")

    # Window size check
    (width, height) = GetWindowSize(screen)
    if width < 80 or height < 24:
        StopHotkeyScreen(screen)
        screen = None
        print "Your screen is too small! It must be at least 24 lines by 80 columns!"

    return screen
Exemple #3
0
def screen_init():
    "Initialize the screen"

    if (newt):
        return snack.SnackScreen()

    return None
Exemple #4
0
    def __init__(self):
        super().__init__(zmq.Context())

        self._screen = snack.SnackScreen()
        self._screen.pushHelpLine(" ")

        self._callback_data = OrderedDict()

        self.subscribe("discovery")
Exemple #5
0
def doit(jobthread):
    import snack

    class MyGridForm(snack.GridForm):  # {
        def __init__(self, screen, jobthread):
            snack.GridForm.__init__(self, screen, "hello", 1, 4)
            self.interval = 1000
            self.bb = snack.ButtonBar(screen, (
                (
                    "OK",
                    "ok",
                ),
                (
                    "Cancel",
                    "cancel",
                ),
            ))
            self.add(self.bb, 0, 2)
            self.jobthread = jobthread

            #self.jobthread.start()

            #print "started 0"
            self.screen.suspend()
            print "started 1"
            #time.sleep(3)
            select.select([1], [], [], 1000000)
            print "started 2"
            self.screen.resume()
            #print "started 3"

            self.setTimer(self.interval)

        def exec_loop(self):  # {
            result = "TIMER"
            while True:
                rc = self.run()
                if rc == "TIMER":
                    pass
                elif isinstance(rc, snack.Button):
                    button = self.bb.buttonPressed(rc)
                    if button == "ok":
                        #time.sleep(5)
                        break
                else:
                    raise Exception, "Unknown return code"
            self.jobthread.stop()
            #self.screen.suspend()
            #print "d0:", self.jobthread.quit
            #self.jobthread.join()
            #self.screen.resume()

    screen = snack.SnackScreen()
    form = MyGridForm(screen, jobthread)
    form.exec_loop()
    screen.finish()
Exemple #6
0
def main():
    test = 0
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    if len(sys.argv) > 1:
        if sys.argv[1] == "-t" or sys.argv[1] == "--test":
            test = 1

    screen = snack.SnackScreen()

    if geteuid() != 0 and not test:
        FatalErrorWindow(screen, _("You must run the RHN registration program as root."))

    tui = Tui(screen, test)
    tui.run()
    def __enter__(self):
        od = os.dup(sys.stdout.fileno())
        self.__stdout.append(od)

        try:
            if _errpt:
                raise OSError()
            nd = os.open('/dev/tty', os.O_WRONLY)
        except OSError:
            nd = os.dup(sys.stderr.fileno())

        os.dup2(nd, sys.stdout.fileno())
        os.close(nd)

        self.__screen = snack.SnackScreen()
Exemple #8
0
 def startGUI(self):
     self.screen = snack.SnackScreen()
Exemple #9
0
##################################################
#Written by Tal Potlog 24-oct-2012               #
#                                                #
#This Example will demonstrate how to create a   #
#menus and a wizard                              #
##################################################

import snack
import bissli


screen=snack.SnackScreen()

HANBURGERS=(('160g','160g'),('250g','250g'),('300g','300g'))
LEVEL=(('Well Done','Well Done'),('Medium Well','Medium Well'),('rare','rare'))
SIDES=(('French Fries','French Fries'),('Curly Fries','Curly Fries'))
DRINKS=(('Cola','Cola'),('Diet Cola','Diet Cola'),('Orange Juice','Orange Juice'),('Grape Juice','Grape Juice'),('Water','Water'))
SIZE=(('Normal','Normal'),('Large','Large'),('Super Size','Super Size'))

Burger_Menu=bissli.WizardMenuForm(screen=screen,options=HANBURGERS,title='Select Hamburger Size')
Wellness_Menu=bissli.WizardMenuForm(screen=screen,options=LEVEL,title='Burger Welness')
SideDish_Menu=bissli.WizardMenuForm(screen=screen,options=SIDES,title='Side Dish')
Drinks_Menu=bissli.WizardMenuForm(screen=screen,options=DRINKS,title='Select A drink')
Size_Menu=bissli.WizardMenuForm(screen=screen,options=SIZE,title='Meal Size')


my_wizard=bissli.FormFlow([Burger_Menu,Wellness_Menu,SideDish_Menu,Drinks_Menu,Size_Menu])
for f in my_wizard:
    f.run()
screen.finish()
Exemple #10
0
    def run_selector(self):
        """
        Compile and run the task selector.

        See: http://www.wanware.com/tsgdocs/snack.html for info on the
        python snack module.
        Also look at the code in snack.py to understand what it is doing.
        """
        wdays_short = "M  T  W  T  F  S  S  "

        extrahkeysdict = {
            '0': ' mod due:today',
            '1': ' mod due:1d',
            '2': ' mod due:2d',
            '3': ' mod due:3d',
            '4': ' mod due:4d',
            '5': ' mod due:5d',
            '6': ' mod due:6d',
            '7': ' mod due:7d',
            '8': ' mod due:1w',
            '9': ' mod due:2w',
            'd': ' done',
            'i': ' info',
            'h': ' HELP'
        }

        for key in extrahkeysdict.keys():
            snack.hotkeys[key] = ord(key)  # Add to the snack hkey library
            snack.hotkeys[ord(key)] = key
        screen = snack.SnackScreen()
        buttonlist = [("1d", "1d", "F1"), ("2d", "2d", "F2"),
                      ("3d", "3d", "F3"), ("1w", "1w", "F4"),
                      ("2w", "2w", "F5")]
        mybuttonbar = snack.ButtonBar(screen, buttonlist, 1)
        lbox = snack.Listbox(height=20,
                             width=90,
                             returnExit=1,
                             multiple=1,
                             border=1,
                             scroll=1)
        for task in self.tasks:  # Step through list of task dictionary objects
            taskline, tdate = self.compile_taskline(task)
            lbox.append(taskline, task["id"])
        grid = snack.GridForm(screen, wdays_short * self.weeks, 3, 3)
        # Note the padding option.  It is set to shift the lbox content one
        # position to the right so as to allign with the dayheader at the top
        grid.add(lbox, 0, 0, padding=(1, 0, 0, 0))
        grid.add(mybuttonbar, 0, 1, growx=1)
        grid.addHotKey('ESC')
        for key in extrahkeysdict.keys():
            grid.addHotKey(key)
        result = grid.runOnce()  # This is the key of the HotKey dict
        buttonpressed = mybuttonbar.buttonPressed(result)  # The Hotkey dict \
        # value of key in 'result'.  Returns None if no hotkey or button \
        # pressed
        selection = lbox.getSelection()  # This is a list

        # The first set of if options deals with all the exceptions while \
        # the last 'else' deals with actual task manupulations.
        if result == 'ESC':
            screen.finish()
            return (None, True)
        elif result == 'h':
            mytext = ''
            for mykey in sorted(extrahkeysdict):
                mytext = mytext + '\n' + mykey + ': ' + extrahkeysdict[mykey]
            snack.ButtonChoiceWindow(screen, 'Help', mytext, ['Ok'])
            screen.finish()
            return (None, False)
        elif result == 'i':
            basictaskstr = 'task ' + str(lbox.current()) + ' info'
            mytext = commands.getoutput(basictaskstr)
            snack.ButtonChoiceWindow(screen, 'Task information', mytext, \
                ['Ok'],width=80)
            screen.finish()
            return (None, False)
        else:
            # Get the selected or current task/s from the listbox
            if len(selection) > 0:
                # Joins the selections into comma seperated list, and suppresses
                # confirmation for this number of tasks
                # basictaskstr = 'task ' + ','.join(map(repr, lbox.getSelection())) \
                basictaskstr = 'task ' + ','.join(map(repr, selection)) \
                    + ' rc.bulk:' + str(len(selection) + 1)
            else:  # If no selections have been made use the current task
                basictaskstr = 'task ' + str(lbox.current())

            # Figure out what commands to add, if any given
            if buttonpressed:
                # TODO Change values in Buttonlist dict so that it provides the full command\
                #    so that it can be used in the same way as if any other hotkey was pressed
                basictaskstr = basictaskstr + ' mod due:' + buttonpressed
            elif result in extrahkeysdict:  # If a hotkey not linked to button.
                basictaskstr = basictaskstr + extrahkeysdict[result]
            else:  # Else type in the rest of the command.
                basictaskstr = basictaskstr + ' mod '

            result2 = snack.EntryWindow(screen, "Command details...", \
                "", [('Command to be executed:', basictaskstr)], width=50, \
                entryWidth=30, buttons=[('OK', 'OK', 'F1'), ('Cancel', 'Cancel',
                'ESC')])  # Look at the code for this function to understand this
            screen.finish()
            if result2[0] == 'Cancel':
                return (None, True)
            else:
                print '>' + result2[1][0]
                return (commands.getoutput(result2[1][0]), False)
Exemple #11
0
 def __init__(self):
     if not TextUI.screen:
         TextUI.screen = snack.SnackScreen()
Exemple #12
0
 def __init__(self, wrti, title):
     self._screen = snack.SnackScreen()
     self._screens = []
     self._wrti = wrti