예제 #1
0
    def setState(self):
        """
        Build the list of devices
        """
        self.li = snack.Listbox(5, returnExit=1)
        l = 0
        le = self.mscreen.width - 6
        if le <= 0:
            le = 5
        for dev in getDeviceList():
            if not hasattr(dev, "getDialog") or not dev.getDialog():
                #li.append("No dialog for %s" % dev.Device, None)
                continue

            l += 1
            for hw in getHardwareList():
                if hw.Name == dev.Device and hw.Description:
                    self.li.append(
                        ("%s (%s) - %s" %
                         (dev.DeviceId, dev.Device, hw.Description))[:le], dev)
                    break

            else:
                self.li.append(("%s (%s) - %s" %
                                (dev.DeviceId, dev.Device, dev.Type))[:le],
                               dev)

        if not l:
            return None

        self.li.append(_("<New Device>"), None)
예제 #2
0
 def get_target_page(self, screen):
     ignore = screen
     self.__targets = snack.Listbox(0)
     for connection in self.get_virt_manager_config().get_connection_list():
         self.__targets.append(connection, connection)
     return [snack.Label("Select A Target Host"),
             self.__targets]
예제 #3
0
파일: ventana.py 프로젝트: elcodigok/slGTD
 def mostrarListado(self):
     opcion = ""
     while (opcion != "back"):
         self.contenido = self.leerArchivo()
         self.label = snack.Label(self.texto)
         self.botones = snack.ButtonBar(
             self.screen, ((gettext.gettext("Add"), "add"),
                           (gettext.gettext("Delete"), "delete"),
                           (gettext.gettext("Back"), "back")))
         self.lista = snack.Listbox(height=13,
                                    width=60,
                                    returnExit=1,
                                    showCursor=0,
                                    scroll=1)
         for registro in self.contenido:
             fecha = registro.split("\t")[1]
             recordView = registro.split("\t")[0] + "(" + fecha.strip(
                 ":created") + ")"
             self.lista.append(recordView, registro)
         self.grid = snack.GridForm(self.screen, self.titulo, 1, 3)
         self.grid.add(self.label, 0, 0, growx=0, growy=0, anchorLeft=1)
         self.grid.add(self.lista, 0, 1)
         self.grid.add(self.botones, 0, 2, growx=1, growy=0)
         respuesta = self.grid.runOnce()
         opcion = self.botones.buttonPressed(respuesta)
         if (opcion == "add"):
             cargaDeValores = Datos.Datos(self.archivo,
                                          gettext.gettext("New"),
                                          self.texto, self.screen)
             cargaDeValores.altas()
         elif (opcion == "delete"):
             self.guardarArchivo(self.lista.current())
예제 #4
0
 def get_volume_format_page(self, screen):
     ignore = screen
     self.__formats = snack.Listbox(0)
     for fmt in self.__config.get_formats_for_pool():
         self.__formats.append(fmt, fmt)
     grid = snack.Grid(1, 1)
     grid.setField(self.__formats, 0, 0)
     return [snack.Label("Select The Volume Format"), grid]
예제 #5
0
def ConfirmGplv3Window(insScreen, packages):
    if insScreen == None:
        print "error ConfirmGplv3Window: the screen is None"
    # Create CheckboxTree instance
    (main_width, main_height) = GetHotKeyMainSize(insScreen)
    main_height -= 2

    if len(packages) > main_height:
        scroll = 1
    else:
        scroll = 0

    hotkey_base_text = "These GPLv3 packages are depended, do you want to install them? (y/n)"
    wrapper = textwrap.TextWrapper(width=main_width)
    hotkey_text = wrapper.fill(hotkey_base_text)
    if hotkey_text != hotkey_base_text:
        main_height -= 1
        hotkey_line = 2
    else:
        hotkey_line = 1

    li = snack.Listbox(main_height, scroll=scroll, width=main_width)

    idx = 0
    for x in packages:
        li.append(x.name, idx)
        idx += 1

    # Set position
    iPosition = 0
    li.setCurrent(iPosition)

    # Create Text instance
    t1 = snack.Textbox(main_width, 1, "-" * main_width)
    t4 = snack.Textbox(main_width, hotkey_line, hotkey_text)

    # Create Grid instance
    title = "GPLv3 that be depended"

    g = snack.GridForm(insScreen, title, 1, 5)
    g.add(li, 0, 0)
    g.add(t1, 0, 1, (-1, 0, -1, 0))
    g.add(t4, 0, 4, (0, 0, 0, -1))

    ############# append test key 'S' ####
    myhotkeys = {"y"     : "y", \
                 "Y"     : "y", \
                 "n"     : "n", \
                 "N"     : "n"}
    for x in myhotkeys.keys():
        g.addHotKey(x)
#####################################
    result = g.run()
    if myhotkeys.has_key(result):
        if myhotkeys[result] == "y" or \
            myhotkeys[result] == "n":
            insScreen.popWindow()
            return (myhotkeys[result])
예제 #6
0
 def __init__(self,
              height,
              scroll=0,
              returnExit=0,
              width=0,
              showCursor=0,
              multiple=0,
              border=0):
     BaseWidget.__init__(self)
     self._widget = snack.Listbox(height, scroll, returnExit, width,
                                  showCursor, multiple, border)
예제 #7
0
def PKGINSTActionWindow(insScreen, lstSubject, iPosition):

    # Create CheckboxTree instance
    (main_width, main_height) = GetHotKeyMainSize(insScreen)

    if len(lstSubject) > main_height:
        scroll = 1
    else:
        scroll = 0

    li = snack.Listbox(main_height, scroll=scroll, width=main_width)

    idx = 0
    for idx in range(len(lstSubject)):
        str = "%s" % lstSubject[idx][0]
        li.append(str, idx)

    num_subject = len(lstSubject)
    if num_subject > iPosition:
        li.setCurrent(iPosition)
    else:
        li.setCurrent(num_subject - 1)
    # Create Text instance
    t1 = snack.Textbox(main_width, 1, "-" * main_width)
    text = "SPACE/ENTER:select  I:Info  X:eXit"
    t2 = snack.Textbox(main_width, 1, text)

    # Create Grid instance
    g = snack.GridForm(insScreen, "Select your operation", 1, 3)
    g.add(li, 0, 0)
    g.add(t1, 0, 1, (-1, 0, -1, 0))
    g.add(t2, 0, 2, (0, 0, 0, -1))

    myhotkeys = {"ENTER" : "ENTER", \
                 " "     : " ", \
                 "i"     : "i", \
                 "I"     : "i", \
                 "x"     : "x", \
                 "X"     : "x"}
    for x in myhotkeys.keys():
        g.addHotKey(x)

    # Display window
    while True:
        result = g.run()
        if myhotkeys.has_key(result):
            idx = li.current()
            break

    insScreen.popWindow()
    return (myhotkeys[result], idx)
예제 #8
0
 def __init__(self,options,screen,title,height=5,width=20,ok_button=('Ok',1),cancel_button=('Cancel',0),**kargs):
     '''
     Initialize the menu and the BaseForm
     '''
     self.title=title
     self.SnackList=snack.Listbox(height=height,width=width)
     n=1
     for p in options:
          self.SnackList.append( "%d) %s"%(n,p[0]), p[1] )
          n+=1
     if kargs.get('Buttons',None):
         self.Buttons=kargs['Buttons']
     else:
         self.Buttons = snack.ButtonBar(screen, (ok_button,cancel_button))
     super(MenuForm,self).__init__(screen=screen,name=title,Widgets=[self.SnackList,self.Buttons],**kargs)
 def get_storage_pool_list_page(self, screen, defined=True, created=True):
     ignore = screen
     pools = self.get_libvirt().list_storage_pools(defined=defined,
                                                   created=created)
     if len(pools) > 0:
         self.__has_pools = True
         self.__pools_list = snack.Listbox(0)
         for pool in pools:
             self.__pools_list.append(pool, pool)
         result = self.__pools_list
     else:
         self.__has_pools = False
         result = snack.Label("There are no storage pools available.")
     grid = snack.Grid(1, 1)
     grid.setField(result, 0, 0)
     return [snack.Label("Storage Pool List"), grid]
예제 #10
0
    def get_connection_list_page(self, screen):
        ignore = screen
        connections = self.get_virt_manager_config().get_connection_list()
        result = None

        if len(connections) > 0:
            self.__has_connections = True
            self.__connection_list = snack.Listbox(0)
            for connection in connections:
                self.__connection_list.append(connection, connection)
            result = self.__connection_list
        else:
            self.__has_connections = False
            result = snack.Label("There are no defined connections.")
        grid = snack.Grid(1, 1)
        grid.setField(result, 0, 0)
        return [snack.Label("Host List"), grid]
    def get_network_list_page(self, screen, defined=True, started=True):
        ignore = screen
        uuids = self.get_libvirt().list_networks(defined, started)
        result = None

        if len(uuids) > 0:
            self.__has_networks = True
            self.__network_list = snack.Listbox(0)
            for uuid in uuids:
                network = self.get_libvirt().get_network(uuid)
                self.__network_list.append(uuid, network.get_name())
            result = self.__network_list
        else:
            self.__has_networks = False
            result = snack.Label("There are no networks available.")
        grid = snack.Grid(1, 1)
        grid.setField(result, 0, 0)
        return [snack.Label("Network List"), grid]
 def get_storage_volume_list_page(self, screen):
     '''Requires that self.__pools_list have a selected element.'''
     ignore = screen
     pool = self.get_libvirt().get_storage_pool(self.get_selected_pool())
     if len(pool.listVolumes()) > 0:
         self.__has_volumes = True
         self.__volumes_list = snack.Listbox(0)
         for volname in pool.listVolumes():
             volume = pool.storageVolLookupByName(volname)
             self.__volumes_list.append(
                 "%s (%0.2f GB)" % (volume.name(), volume.info()[2] /
                                    (1024**3)), volume.name())
         result = self.__volumes_list
     else:
         self.__has_volumes = False
         result = snack.Label("There are no storage volumes available.")
     grid = snack.Grid(1, 1)
     grid.setField(result, 0, 0)
     return [snack.Label("Storage Volume List"), grid]
예제 #13
0
    def get_domain_list_page(self, screen, defined=True, created=True):
        ignore = screen # pylint ignore since it is not used here
        domuuids = self.get_libvirt().list_domains(defined, created)
        self.__has_domains = bool(domuuids)
        result = None

        if self.__has_domains:
            self.__domain_list = snack.Listbox(0)
            for uuid in domuuids:
                domain = self.get_libvirt().get_domain(uuid)

                # dom is a vmmDomain
                self.__domain_list.append(domain.get_name(), domain)
            result = [self.__domain_list]
        else:
            grid = snack.Grid(1, 1)
            grid.setField(snack.Label("There are no domains available."), 0, 0)
            result = [grid]

        return result
예제 #14
0
    def newDevice(self, mscreen):
        """
        Displays the main screen
        @screen The snack screen instance
        """
        t = snack.TextboxReflowed(25,
                                  _("Which device type do you want to add?"))
        bb = snack.ButtonBar(mscreen,
                             ((_("Add"), "add"), (_("Cancel"), "cancel")))
        li = snack.Listbox(5, width=25, returnExit=1)
        li.append(_("Ethernet"), ETHERNET)

        machine = os.uname()[4]
        if machine == 's390' or machine == 's390x':
            li.append(_("QETH"), QETH)
        else:
            li.append(_("Modem"), MODEM)
            li.append(_("ISDN"), ISDN)

        g = snack.GridForm(mscreen, _("Network Configuration"), 1, 3)
        g.add(t, 0, 0)
        g.add(li, 0, 1)
        g.add(bb, 0, 2)
        res = g.run()
        mscreen.popWindow()
        if bb.buttonPressed(res) != 'cancel':
            todo = li.current()
            df = getDeviceFactory()
            dev = None
            devclass = df.getDeviceClass(todo)
            devlist = getDeviceList()
            if not devclass:
                return -1
            dev = devclass()
            if dev:
                devlist.append(dev)
                return dev
        return -2
예제 #15
0
    def __init__(self, screen, tui):

        self.tui = tui
        if not rhnreg.server_supports_eus():
            log.log_debug(
                "Server does not support EUS, skipping OSReleaseWindow")
            raise WindowSkipException()

        self.available_channels = rhnreg.getAvailableChannels(
            tui.userName, tui.password)
        if len(self.available_channels['channels']) < 1:
            log.log_debug(
                "No available EUS channels, skipping OSReleaseWindow")
            raise WindowSkipException()

        self.screen = screen
        self.size = snack._snack.size()

        self.selectChannel = False

        toplevel = snack.GridForm(self.screen,
                                  SELECT_OSRELEASE.encode('utf-8'), 1, 7)
        self.g = toplevel

        self.ostext = snack.TextboxReflowed(self.size[0] - 10,
                                            OS_VERSION.encode('utf-8'))
        toplevel.add(self.ostext, 0, 0, anchorLeft=1)
        optiontext1 = LIMITED_UPDATES.encode('utf-8')

        if self.tui.limited_updates_button:
            self.limited_updates_button = snack.SingleRadioButton(optiontext1,
                                                                  None,
                                                                  isOn=1)
        else:
            self.limited_updates_button = snack.SingleRadioButton(
                optiontext1, None)

        toplevel.add(self.limited_updates_button,
                     0,
                     1,
                     padding=(0, 1, 0, 1),
                     anchorLeft=1)

        self.sublabel = snack.Label(MINOR_RELEASE.encode('utf-8'))
        toplevel.add(self.sublabel, 0, 2, anchorLeft=1)

        self.channelList = snack.Listbox(self.size[1] - 22,
                                         1,
                                         width=self.size[0] - 10)
        toplevel.add(self.channelList, 0, 3)

        for key, value in sorted(self.available_channels['channels'].items(),
                                 key=lambda a: a[0]):
            if key in self.available_channels['receiving_updates']:
                value = value + "*"
            self.channelList.append(" " + value, key)

        self.tip = snack.TextboxReflowed(self.size[0] - 10,
                                         CHANNEL_PAGE_TIP.encode('utf-8'))
        toplevel.add(self.tip, 0, 4, anchorLeft=1)

        optiontext2 = ALL_UPDATES.encode('utf-8')

        if self.tui.all_updates_button:
            self.all_updates_button = snack.SingleRadioButton(
                optiontext2, self.limited_updates_button, isOn=1)
        else:
            self.all_updates_button = snack.SingleRadioButton(
                optiontext2, self.limited_updates_button)

        toplevel.add(self.all_updates_button,
                     0,
                     5,
                     padding=(0, 0, 0, 1),
                     anchorLeft=1)

        #self.warning = snack.TextboxReflowed(self.size[0]-10,
        #                     CHANNEL_PAGE_WARNING.encode('utf-8'))
        #toplevel.add(self.warning, 0, 9, anchorLeft = 1)

        self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"),
                                           (BACK.encode('utf-8'), "back"),
                                           (CANCEL.encode('utf-8'), "cancel")])
        toplevel.add(self.bb, 0, 6, growx=1)

        self.screen.refresh()
예제 #16
0
def PKGTypeSelectWindow(insScreen, pkgTypeList, position=0):

    iPosition = position
    # Create CheckboxTree instance
    (main_width, main_height) = GetHotKeyMainSize(insScreen)
    main_height -= 2

    #print " packages = %s" % len(packages)
    if len(pkgTypeList) > main_height:
        scroll = 1
    else:
        scroll = 0

    hotkey_base_text = "SPACE/ENTER:select/unselect  N:Next  B:Back  I:Info  X:eXit"
    wrapper = textwrap.TextWrapper(width=main_width)
    hotkey_text = wrapper.fill(hotkey_base_text)
    if hotkey_text != hotkey_base_text:
        main_height -= 1
        hotkey_line = 2
    else:
        hotkey_line = 1

    li = snack.Listbox(main_height, scroll=scroll, width=main_width)
    idx = 0
    for x in pkgTypeList:
        if x.status:
            status = "*"
        else:
            status = " "
        str = "%s [%s]" % (x.name, status)

        li.append(str, idx)
        idx += 1
    # Set position
    num_type = len(pkgTypeList)
    if num_type > 1:
        if num_type <= iPosition:
            iPosition = num_typr - 1
        if num_type > (iPosition + main_height / 2):
            before_position = (iPosition + main_height / 2)
        else:
            before_position = num_type - 1
    li.setCurrent(before_position)
    li.setCurrent(iPosition)

    t1 = snack.Textbox(main_width, 1, "-" * main_width)
    t2 = snack.Textbox(main_width, hotkey_line, hotkey_text)

    # Create Grid instance
    title = "Customize special type packages"

    g = snack.GridForm(insScreen, title, 1, 5)

    g.add(t1, 0, 2)
    g.add(t2, 0, 4, (0, 0, 0, -1))
    g.add(li, 0, 0)

    ############# append test key 'S' ####
    myhotkeys = {"ENTER" : "ENTER", \
                 " "     : " ", \
                 "n"     : "n", \
                 "N"     : "n", \
                 "b"     : "b", \
                 "B"     : "b", \
                 "i"     : "i", \
                 "I"     : "i", \
                 "x"     : "x", \
                 "X"     : "x"}

    for x in myhotkeys.keys():
        g.addHotKey(x)


#####################################
    while True:
        result = g.run()
        idx = li.current()
        if myhotkeys.has_key(result):
            if myhotkeys[result] == "ENTER" or \
               myhotkeys[result] == " ":
                curr_type = pkgTypeList[idx]
                if not curr_type.status:
                    curr_type.status = True
                    newsign = "*"
                else:
                    curr_type.status = False
                    newsign = " "
                item = "%s [%s]" % (curr_type.name, newsign)
                li.replace(item, idx)
                idx += 1

                if idx >= num_type:
                    idx = num_type - 1
                li.setCurrent(idx)
            else:
                break
    insScreen.popWindow()
    return (myhotkeys[result], idx, pkgTypeList)
예제 #17
0
def PKGINSTDebuginfoWindow(insScreen, lstDebugPkg, selected_packages, iPosition, \
                         lTargetSize, lHostSize):

    installed_pkgs = 0
    # Create CheckboxTree instance

    (main_width, main_height) = GetHotKeyMainSize(insScreen)
    main_height -= 2

    if len(lstDebugPkg) > main_height:
        scroll = 1
    else:
        scroll = 0

    hotkey_base_text = "SPACE/ENTER:select/unselect  N:Next  B:Back  I:Info  X:eXit"
    wrapper = textwrap.TextWrapper(width=main_width)
    hotkey_text = wrapper.fill(hotkey_base_text)
    if hotkey_text != hotkey_base_text:
        main_height -= 1
        hotkey_line = 2
    else:
        hotkey_line = 1

    li = snack.Listbox(main_height, scroll=scroll, width=main_width)

    idx = 0
    for x in lstDebugPkg:
        if x.installed:
            status = "I"
            installed_pkgs += 1
        elif x in selected_packages:
            status = "*"
        else:
            status = " "
        str = "[%s] %s " % (status, x.name)

        li.append(str, idx)
        idx += 1

    # Set position
    num_package = len(lstDebugPkg)
    if num_package <= iPosition:
        iPosition = num_package - 1
    if num_package > (iPosition + main_height / 2):
        before_position = (iPosition + main_height / 2)
    else:
        before_position = num_package - 1
    li.setCurrent(before_position)
    li.setCurrent(iPosition)

    # Create Text instance
    t1 = snack.Textbox(main_width, 1, "-" * main_width)
    text = "All Packages [%ld]    Installed Packages    [%ld] Selected Packages [%ld]" % \
          (num_package, installed_pkgs, len(selected_packages))

    t2 = snack.Textbox(main_width, 1, text)
    t3 = snack.Textbox(main_width, 1, "-" * main_width)
    t4 = snack.Textbox(main_width, hotkey_line, hotkey_text)

    # Create Grid instance
    g = snack.GridForm(insScreen, "Select debuginfo packages", 1, 5)
    g.add(li, 0, 0)
    g.add(t1, 0, 1, (-1, 0, -1, 0))
    g.add(t2, 0, 2)
    g.add(t3, 0, 3, (-1, 0, -1, 0))
    g.add(t4, 0, 4, (0, 0, 0, -1))

    ############# append test key 'S' ####
    myhotkeys = {"ENTER" : "ENTER", \
                 " "     : " ", \
                 "n"     : "n", \
                 "N"     : "n", \
                 "b"     : "b", \
                 "B"     : "b", \
                 "i"     : "i", \
                 "I"     : "i", \
                 "x"     : "x", \
                 "X"     : "x"}
    for x in myhotkeys.keys():
        g.addHotKey(x)


#####################################

# Display window
    while True:
        result = g.run()
        idx = li.current()
        if myhotkeys.has_key(result):
            if myhotkeys[result] == "ENTER" or \
               myhotkeys[result] == " ":
                li = _StatusToggle(li, myhotkeys[result], idx,
                                   selected_packages, lstDebugPkg)
                idx += 1
                if idx >= num_package:
                    idx = num_package - 1
                li.setCurrent(idx)
            else:
                break

    insScreen.popWindow()
    return (myhotkeys[result], idx, selected_packages)
예제 #18
0
def PKGINSTPackageWindow(insScreen, packages, selected_packages, iPosition, lTargetSize, lHostSize, search, \
                                                                                               install_type):
    installed_pkgs = 0
    numChange = True  #Select or unselect operation that lead selected number change

    # Create CheckboxTree instance
    (main_width, main_height) = GetHotKeyMainSize(insScreen)
    main_height -= 2

    #print " packages = %s" % len(packages)
    if len(packages) > main_height:
        scroll = 1
    else:
        scroll = 0

    hotkey_base_text = "SPACE/ENTER:select/unselect  A:select/unselect All  R:seaRch N:Next  B:Back  I:Info  X:eXit"
    wrapper = textwrap.TextWrapper(width=main_width)
    hotkey_text = wrapper.fill(hotkey_base_text)
    if hotkey_text != hotkey_base_text:
        main_height -= 1
        hotkey_line = 2
    else:
        hotkey_line = 1

    li = snack.Listbox(main_height, scroll=scroll, width=main_width)

    idx = 0
    for x in packages:
        if install_type == ACTION_INSTALL and x.installed:
            status = "I"
            installed_pkgs += 1
        elif x in selected_packages:
            status = SIGN_SELECT[install_type]
        else:
            status = " "
        str = "[%s] %s " % (status, x.name)

        li.append(str, idx)
        idx += 1
    # Set position
    num_package = len(packages)
    before_position = 0
    if num_package > 1:
        if num_package <= iPosition:
            iPosition = num_package - 1
        if num_package > (iPosition + main_height / 2):
            before_position = (iPosition + main_height / 2)
        else:
            before_position = num_package - 1
    li.setCurrent(before_position)
    li.setCurrent(iPosition)

    # Create Text instance
    text = ""
    t1 = snack.Textbox(main_width, 1, "-" * main_width)
    t2 = snack.Textbox(main_width, 1, text)
    t3 = snack.Textbox(main_width, 1, "-" * main_width)
    t4 = snack.Textbox(main_width, hotkey_line, hotkey_text)

    # Create Grid instance
    if search == None:
        title = "Select package"
    else:
        title = "Select package - (%s)" % search

    g = snack.GridForm(insScreen, title, 1, 5)
    g.add(li, 0, 0)
    g.add(t1, 0, 1, (-1, 0, -1, 0))
    g.add(t2, 0, 2)
    g.add(t3, 0, 3, (-1, 0, -1, 0))
    g.add(t4, 0, 4, (0, 0, 0, -1))

    ############# append test key 'S' ####
    myhotkeys = {"ENTER" : "ENTER", \
                 " "     : " ", \
                 "n"     : "n", \
                 "N"     : "n", \
                 "b"     : "b", \
                 "B"     : "b", \
                 "r"     : "r", \
                 "R"     : "r", \
                 "i"     : "i", \
                 "I"     : "i", \
                 "x"     : "x", \
                 "X"     : "x", \
                 "a"     : "a", \
                 "A"     : "a"}

    for x in myhotkeys.keys():
        g.addHotKey(x)

#####################################
    while True:

        if numChange:
            if install_type == ACTION_INSTALL:
                text = "All Packages [%ld]    Installed Packages [%ld]    Selected Packages [%ld]" % \
                       (num_package, installed_pkgs, len(selected_packages))
            else:
                text = "All Packages [%ld]    Selected Packages [%ld]" % \
                       (num_package, len(selected_packages))
            t2.setText(text)
            numChange = False

        result = g.run()
        idx = li.current()
        if myhotkeys.has_key(result):
            if myhotkeys[result] == "ENTER" or \
               myhotkeys[result] == " ":
                numChange = True
                li = _StatusToggle(li, myhotkeys[result], idx, selected_packages, \
                                                          packages, install_type)
                idx += 1
                if idx >= num_package:
                    idx = num_package - 1
                li.setCurrent(idx)
            elif myhotkeys[result] == "a":  ###
                li = _SelectAll(li, myhotkeys[result],num_package, selected_packages, \
                                                         packages, install_type)
                li.setCurrent(idx)
                numChange = True
            else:
                break

    insScreen.popWindow()
    return (myhotkeys[result], idx, selected_packages)
예제 #19
0
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import snack

screen = snack.SnackScreen()

lbox = snack.Listbox(height = 50, width = 90, returnExit = 1)
lbox.append("Fedora", 1)
lbox.append("Debian", 2)
lbox.append("Ubuntu", 3)
lbox.append("Arch Linux", 4)
lbox.append("ElementaryOS", 5)

grid = snack.GridForm(screen, "Select your favorite ditro", 1, 1)
grid.add(lbox, 0, 0)

result = grid.runOnce()

screen.finish()

#print "listbox:", lbox.current()
if lbox.current() == 1:
예제 #20
0
파일: xtui.py 프로젝트: manux81/helenos-1
def choice_window(screen, title, text, options, position):
    "Create options menu"

    maxopt = 0
    for option in options:
        length = len(option)
        if (length > maxopt):
            maxopt = length

    width = maxopt
    height = len(options)

    if (newt):
        width = width_fix(screen, width + width_extra)
        height = height_fix(screen, height)

        if (height > 3):
            large = True
        else:
            large = False

        buttonbar = snack.ButtonBar(screen, ('Done', 'Cancel'))
        textbox = snack.TextboxReflowed(width, text)
        listbox = snack.Listbox(height, scroll=large, returnExit=1)

        cnt = 0
        for option in options:
            listbox.append(option, cnt)
            cnt += 1

        if (position != None):
            listbox.setCurrent(position)

        grid = snack.GridForm(screen, title, 1, 3)
        grid.add(textbox, 0, 0)
        grid.add(listbox, 0, 1, padding=(0, 1, 0, 1))
        grid.add(buttonbar, 0, 2, growx=1)

        retval = grid.runOnce()

        return (buttonbar.buttonPressed(retval), listbox.current())
    elif (dialog):
        if (width < 35):
            width = 35

        args = []
        cnt = 0
        for option in options:
            args.append(str(cnt + 1))
            args.append(option)

            cnt += 1

        kw = {}
        if (position != None):
            kw['default-item'] = str(position + 1)

        status, data = call_dlg(dlgcmd, '--title', title, '--extra-button',
                                '--extra-label', 'Done', '--menu', text,
                                str(height + height_extra),
                                str(width + width_extra), str(cnt), *args,
                                **kw)

        if (status == 1):
            return ('cancel', None)

        try:
            choice = int(data) - 1
        except ValueError:
            return ('cancel', None)

        if (status == 0):
            return (None, choice)

        return ('done', choice)

    sys.stdout.write("\n *** %s *** \n%s\n\n" % (title, text))

    maxcnt = len(str(len(options)))
    cnt = 0
    for option in options:
        sys.stdout.write("%*s. %s\n" % (maxcnt, cnt + 1, option))
        cnt += 1

    sys.stdout.write("\n%*s. Done\n" % (maxcnt, '0'))
    sys.stdout.write("%*s. Quit\n\n" % (maxcnt, 'q'))

    while True:
        if (position != None):
            sys.stdout.write("Selection[%s]: " % str(position + 1))
        else:
            if (cnt > 0):
                sys.stdout.write("Selection[1]: ")
            else:
                sys.stdout.write("Selection[0]: ")
        inp = sys.stdin.readline()

        if (not inp):
            raise EOFError

        if (not inp.strip()):
            if (position != None):
                return (None, position)
            else:
                if (cnt > 0):
                    inp = '1'
                else:
                    inp = '0'

        if (inp.strip() == 'q'):
            return ('cancel', None)

        try:
            choice = int(inp.strip())
        except ValueError:
            continue

        if (choice == 0):
            return ('done', 0)

        if (choice < 1) or (choice > len(options)):
            continue

        return (None, choice - 1)
예제 #21
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)
예제 #22
0
 def ActionChoice(self,
                  header,
                  text,
                  options,
                  watches=None,
                  current=None,
                  timeout=None):
     if watches is None:
         watches = []
     with self:
         text, text_width, text_height = snack.reflow(text,
                                                      width=TEXT_WIDTH,
                                                      flexDown=FLEX_DOWN,
                                                      flexUp=FLEX_UP)
         width, height, scroll = self.__GetWidgetBounds(text_height,
                                                        nlines=len(options))
         items_width = [len(option) for option, item in options]
         scrolled = 3 if scroll else 0
         width = min(
             TEXT_WIDTH,
             max(items_width) + scrolled if items_width else TEXT_WIDTH)
         listbox = snack.Listbox(height,
                                 scroll=scroll,
                                 width=width,
                                 returnExit=1)
         for option, item in options:
             listbox.append(option, item)
         if current is not None:
             try:
                 listbox.setCurrent(current)
             except KeyError:
                 pass
         form = snack.GridForm(self.__screen, header, 1, 2)
         if text:
             textbox = snack.Textbox(width=text_width,
                                     height=text_height,
                                     text=text)
             form.add(textbox, 0, 0, padding=(0, 0, 0, 1))
         form.add(listbox, 0, 1)
         for watch in watches:
             form.form.watchFile(watch, 1)
         if timeout is not None:
             form.form.setTimer(timeout)
         form.addHotKey('ESC')
         form.addHotKey('+')
         form.addHotKey('-')
         form.addHotKey('LEFT')
         form.addHotKey('RIGHT')
         ret = form.runOnce()
         if ret is listbox:
             return listbox.current(), ACTION_SET
         elif ret == 'TIMER':
             return listbox.current() if options else None, None
         elif ret in watches:
             return listbox.current() if options else None, watch
         elif ret == 'F12':
             return listbox.current() if options else None, ACTION_SET
         elif ret == 'ESC':
             raise KeyboardInterrupt()
         elif ret == '-' or ret == 'LEFT':
             return listbox.current() if options else None, ACTION_DEC
         elif ret == '+' or ret == 'RIGHT':
             return listbox.current() if options else None, ACTION_INC
         else:
             raise NotImplementedError(
                 "Unexpected return value from form.runOnce: %s" % ret)