예제 #1
0
    def _makeButtons(self, cancelTxt, okTxt, thirdButtTxt):
        """
        Args:
            okTxt:          The text to display in the first button
            cancelTxt:      The text to display in the second button
            thirdButtTxt:   The text to display in the third button

        Returns:  A row container with the appropriate buttons
        """
        butOk: Button = Button(okTxt, action=lambda x=okTxt: self.dismiss(x))
        butCancel: Button = Button(cancelTxt,
                                   action=lambda x=cancelTxt: self.dismiss(x))
        butThree: Button = cast(Button, None)

        if thirdButtTxt is not None:
            butThree = Button(thirdButtTxt,
                              action=lambda x=thirdButtTxt: self.dismiss(x))

        buttRowAttrs: AttrDict = {
            'spacing': self.margin,
            'margin': 4,
            'equalize': 'w',
        }
        if butThree is None:
            buttRow: Row = Row([butOk, butCancel], **buttRowAttrs)
        else:
            buttRow: Row = Row([butOk, butCancel, butThree], **buttRowAttrs)

        return buttRow
예제 #2
0
    def __init__(self, shell: Shell):

        self.logger = logging.getLogger(__name__)

        super().__init__(shell=shell)

        columnAttrs = {"align": "c", 'expand': 0}
        attrs = {'font': self.smallButtonFont}
        launchMusicDialogButt: Button = Button(
            text="Options Dialog",
            action=DemoMusicScreen.testOptionsDialog,
            **attrs)
        loadDemoMusicButt: Button = Button(
            text="Load Music", action=DemoMusicScreen.testLoadMusic, **attrs)
        playMusicButt: Button = Button(text="Play Music",
                                       action=DemoMusicScreen.playMusic,
                                       **attrs)
        stopMusicButt: Button = Button(text="Stop Music",
                                       action=DemoMusicScreen.stopMusic,
                                       **attrs)

        contents = Column([
            launchMusicDialogButt, loadDemoMusicButt, playMusicButt,
            stopMusicButt, self.backButton
        ], **columnAttrs)
        self.add_centered(contents)
        self.backButton.focus()
예제 #3
0
    def makeContents(cls, backButton: Button = None) -> Column:

        menu = Column([
            Button(text="Ask a Question", action=cls.test_ask),
            Button(text="Ask Old Filename", action=cls.test_old),
            Button(text="Ask New Filename", action=cls.test_new),
            Button(text="Look File/Directory", action=cls.test_lookfor),
            Button(text="Titled Dialog", action=cls.testTitledDialog),
        ],
                      align='l',
                      expand=3,
                      equalize='w')

        if backButton is None:
            contents = Column([
                menu,
            ], align='c', spacing=30)
        else:
            contents = Column([
                Label("File Dialogs",
                      font=ResourceUtility.get_font(18, "VeraBd.ttf")),
                menu,
                backButton,
            ],
                              align='c',
                              spacing=30)

        return contents
    def makeContents(cls, backButton: Button = None) -> Column:

        nameLabel: Label = Label("Name: ")
        raceLabel: Label = Label("Race: ")

        cls.nameField: TextField = TextField(width=150)
        cls.raceField: TextField = TextField(width=150)

        rows = [[nameLabel, cls.nameField], [raceLabel, cls.raceField]]
        fieldGrid: Grid = Grid(rows)

        cls.resultLabel = Label("")
        cls.resultLabel.width = 400

        minMaxAttrs = {'min': 50, 'max': 240}
        minMaxField: TextField = TextField(**minMaxAttrs)
        minMaxField.type = int
        minMaxField.set_text("222")

        okBtn = Button("OK", action=cls.ok)

        tbTestContainer = cls.makeTextBoxTesterContainer()
        contentAttrs = {"align": "c"}

        if backButton is None:
            contents: Column = Column([
                fieldGrid, cls.resultLabel, okBtn, minMaxField, tbTestContainer
            ], **contentAttrs)
        else:
            contents: Column = Column([
                fieldGrid, cls.resultLabel, okBtn, minMaxField,
                tbTestContainer, backButton
            ], **contentAttrs)

        return contents
예제 #5
0
    def screen_button(self, text: str, screen: Screen):

        # buttFont = ResourceUtility.get_font(DEMO_BUTTON_TEXT_SIZE, Theme.BUILT_IN_FONT)
        # buttAttrs = {
        #     'font': buttFont
        # }
        retButton = Button(text, action=lambda: self.shell.show_screen(screen))
        return retButton
예제 #6
0
    def __init__(self, shell: Shell):
        """

        :param shell:
        """
        self.logger = logging.getLogger(__name__)
        #
        # Python 3 update
        #
        # Screen.__init__(self, shell)
        super().__init__(shell)

        from albow.demo.DemoShell import DemoShell
        self.shell = cast(DemoShell, shell)
        f1 = ResourceUtility.get_font(DEMO_TITLE_TEXT_SIZE, Theme.BUILT_IN_FONT)

        title = Label("Albow Demonstration", font=f1)
        #  emptyButton = Button("Empty", enabled=False)

        menuArray = [
            [
                self.screen_button("R0C0"),
                self.screen_button("R0C1"),
                self.screen_button("R0C2"),
            ],
            # [
            #     self.screen_button("R1C0"),
            #     self.screen_button("R1Column1"),
            #     self.screen_button("R1C2"),
            # ],
            # [
            #     self.screen_button("R2C0"),
            #     self.screen_button("R2Column1"),
            #     self.screen_button("R2C2"),
            # ],
            # [
            #     self.screen_button("R3C0"),
            #     self.screen_button("R3Column1"),
            #     self.screen_button("R3C2")
            # ],
            # [
            #     self.screen_button("R4C0"),
            #     self.screen_button("R4Column1"),
            #     self.screen_button("R4C2")
            # ]
        ]

        menuGrid = Grid(rows=menuArray, column_spacing=10, row_spacing=2, margin=5)
        quitButton = Button("Quit", shell.quit)

        self.equallySizeButtons(menuArray)

        contents = Column([
            title,
            menuGrid,
            quitButton
        ], align='c', spacing=10, border_width=1, border_color=Theme.BLUE, margin=10)
        self.add_centered(contents)
예제 #7
0
    def __init__(self, shell, filename, **kwds):
        """"""
        text = ResourceUtility.get_text(filename)
        text_pages = text.split("\nPAGE\n")
        pages = []
        page_size = (0, 0)
        for text_page in text_pages:
            lines = text_page.strip().split("\n")
            page  = Page(self, lines[0], lines[1:])
            pages.append(page)
            page_size = maximum(page_size, page.size)
        self.pages = pages
        bf = self.button_font
        b1 = Button("Prev Page", font=bf, action=self.prev_page)
        b2 = Button("Menu",      font=bf, action=self.go_back)
        b3 = Button("Next Page", font=bf, action=self.next_page)
        b  = self.margin
        # page_rect = Rect((b, b), page_size)
        width_height  = list(map(lambda x: x, page_size))

        page_rect = Rect((b, b),(width_height[0],width_height[1]))

        gap = (0, 18)
        #
        # Python 3 update
        #
        # In Python 3 maps and list are not auto-converted
        #
        # b1.topleft  = add(page_rect.bottomleft,  gap)
        # b2.midtop   = add(page_rect.midbottom,   gap)
        # b3.topright = add(page_rect.bottomright, gap)
        b1.topleft  = list(add(page_rect.bottomleft,  gap))
        b2.midtop   = list(add(page_rect.midbottom,   gap))
        b3.topright = list(add(page_rect.bottomright, gap))

        # Screen.__init__(self, shell, **kwds)
        super().__init__(shell, **kwds)
        #
        # Python 3 update
        #
        # In Python 3 maps and list are not auto-converted
        #
        # self.size =  add(b3.bottomright, (b, b))
        self.size = list(add(b3.bottomright, (b, b)))
        self.add(b1)
        self.add(b2)
        self.add(b3)
        self.prev_button = b1
        self.next_button = b3
        self.set_current_page(0)
예제 #8
0
    def __init__(self, theShell: Shell, theSurface: Surface):
        """

        Args:
            self:

            theShell:  The shell that wraps this screen

            theSurface: The pygame surface to use to drawn on

        Returns:  An instance of itself

        """
        self.surface: Surface = theSurface
        super().__init__(theShell)

        self.logger: Logger = getLogger(__name__)
        self.chip8: Chip8 = Chip8()
        self.selectedSprite: Chip8SpriteType = cast(Chip8SpriteType, None)
        self.vXvalue: int = 0
        self.vYvalue: int = 0
        vxAttrRef: AttrRef = AttrRef(base=self, name="vXvalue")
        vyAttrRef: AttrRef = AttrRef(base=self, name="vYvalue")

        vXLabel: Label = Label("Vx:")
        vYLabel: Label = Label("Vy:")

        vXField: IntField = IntField(width=100, ref=vxAttrRef)
        vYField: IntField = IntField(width=100, ref=vyAttrRef)

        spriteSelector: ListBox = ListBox(nrows=2,
                                          theClient=self,
                                          theItems=Chip8SpriteType.toStrList(),
                                          selectAction=self.selectAction)
        self.logger.info(f"list box width: {spriteSelector.width}")
        drawButton: Button = Button("Draw", action=self.drawAction)
        widgetList: List[Widget] = [
            drawButton, vXLabel, vXField, vYLabel, vYField, spriteSelector
        ]

        rowAttrs = {'margin': 3}
        inputRow: Row = Row(items=widgetList, **rowAttrs)
        framedInputRow: Frame = Frame(client=inputRow)

        chip8Screen: Chip8Screen = Chip8Screen(Chip8.virtualScreen)

        columnAttrs = {"align": "l", 'expand': 0, 'margin': 3}
        contents = Column([framedInputRow, chip8Screen], **columnAttrs)

        self.logger.info(
            f"framedInputRow size: {framedInputRow.size}, shell width: {self.shell.width} shell.height: {self.shell.height}"
        )
        self.add(contents)
    def makeTextBoxTesterContainer(cls) -> Row:

        cls.textBox = TextBox(theNumberOfColumns=20, theNumberOfRows=10)

        checkBoxRow: Row = Row([CheckBox(), Label('Last Line Visible')])

        appendTextButton: Button = Button('Append', action=cls.appendText)
        insertTextButton: Button = Button('Insert', action=cls.insertText)
        deleteTextButton: Button = Button('Delete', action=cls.deleteText)
        clearTextButton: Button = Button('Clear ', action=cls.clearText)

        contentAttrs = {"align": "l"}
        buttHolder: Column = Column([
            appendTextButton, insertTextButton, deleteTextButton,
            clearTextButton
        ], **contentAttrs)
        textBoxControlHolder: Column = Column([checkBoxRow, buttHolder],
                                              **contentAttrs)

        container: Row = Row([cls.textBox, textBoxControlHolder])

        return container
예제 #10
0
    def __init__(self,
                 client=None,
                 responses=None,
                 default=0,
                 cancel=-1,
                 **kwds):
        """

        Args:
            client:    The widget the dialog is on top of

            responses: A list of responses

            default:   The index to the default response; Default is the first

            cancel:    The index to the cancel response; Default is None

            **kwds:
        """

        Widget.__init__(self, **kwds)
        if client or responses:
            rows = []
            w1 = 0
            w2 = 0
            if client:
                rows.append(client)
                w1 = client.width
            if responses:
                buttons = Row([
                    Button(text, action=lambda t=text: self.dismiss(t))
                    for text in responses
                ],
                              equalize='w')
                rows.append(buttons)
                w2 = buttons.width
            if w1 < w2:
                a = 'l'
            else:
                a = 'r'
            contents = Column(rows, align=a)
            m = self.margin
            contents.topleft = (m, m)
            self.add(contents)
            self.shrink_wrap()

        if responses and default is not None:
            self.enter_response = responses[default]
        if responses and cancel is not None:
            self.cancel_response = responses[cancel]
예제 #11
0
    def makeContents(cls, backButton: Button = None) -> Column:

        cls.images = ImageArray.get_image_array("fruit.png", shape=3, border=2)
        cls.image = Image(cls.images[0])
        cls.index = 0

        if backButton is None:
            contents: Column = Column(
                [cls.image,
                 Button("Next Fruit", action=cls.next_image)],
                spacing=10)
        else:
            contentAttrs = {"align": "c", "margin": 10, 'border_width': 1}

            contents: Column = Column([
                Label("Image Array"),
                cls.image,
                Button("Next Fruit", action=cls.next_image),
                backButton,
            ],
                                      spacing=10,
                                      **contentAttrs)

        return contents
예제 #12
0
    def __init__(self, shell: Shell):

        self.logger = logging.getLogger(__name__)

        super().__init__(shell=shell)

        self.smallButtonFont = ResourceUtility.get_font(
            BaseDemoScreen.SMALL_BUTTON_TEXT_SIZE, Theme.BUILT_IN_FONT)
        self.labelFont = ResourceUtility.get_font(
            BaseDemoScreen.SMALL_LABEL_TEXT_SIZE, Theme.BUILT_IN_FONT)

        self.backButton = Button("Back",
                                 action=shell.show_menu,
                                 font=self.smallButtonFont)
        self.logger.debug(f"{self.backButton}")
예제 #13
0
    def __init__(self, prompt=None, suffixes=None, **kwds):

        super().__init__(**kwds)

        label = None
        d = self.margin
        self.suffixes = suffixes or ()
        if self.up_button_text is None:
            self.up_button_text = ''

        up_button = Button(self.up_button_text, action=self.go_up)
        dir_box = DirectoryPathView(self.box_width - up_button.width - 10,
                                    self)
        self.dir_box = dir_box
        top_row = Row([dir_box, up_button])
        list_box = FileListView(self.box_width - 16, self)
        self.list_box = list_box
        ctrls = [top_row, list_box]
        prompt = prompt or self.default_prompt

        if prompt:
            label = Label(prompt)
        if self.saving:
            filename_box = TextField(self.box_width)
            filename_box.change_action = self.update
            self.filename_box = filename_box
            ctrls.append(Column([label, filename_box], align='l', spacing=0))
        else:
            if label:
                ctrls.insert(0, label)

        ok_button = Button(self.ok_label,
                           action=self.ok,
                           enable=self.ok_enable)
        self.ok_button = ok_button
        cancel_button = Button("Cancel", action=self.cancel)
        vbox = Column(ctrls, align='l', spacing=d)
        vbox.topleft = (d, d)
        y = vbox.bottom + d
        ok_button.topleft = (vbox.left, y)
        cancel_button.topright = (vbox.right, y)
        self.add(vbox)
        self.add(ok_button)
        self.add(cancel_button)
        self.shrink_wrap()
        self._directory = None
        self.directory = os.getcwd()
        # print "FileDialog: cwd =", repr(self.directory) ###
        if self.saving:
            filename_box.focus()
예제 #14
0
    def __init__(self):

        #
        # Python 3 update
        #
        super().__init__()
        emc = EnableMusicControl()
        mvc = MusicVolumeControl()
        controls = Grid([
            [Label("Enable Music"), emc],
            [Label("Music Volume"), mvc],
        ])
        buttons = Button("OK", self.ok)
        contents = Column([controls, buttons], align='r', spacing=20)
        contents.topleft = (20, 20)
        self.add(contents)
        self.shrink_wrap()
예제 #15
0
def ask(theMessage: str,
        theResponses=None,
        default=0,
        cancel=-1,
        wrap_width=60,
        **kwds):
    """
    Displays a message in a modal dialog with a set of buttons labelled with the specified responses. Clicking a
    button causes the ask function to return the corresponding response string as its value. The default and
    cancel parameters are indexes into the response list specifying the values to be returned by Return/Enter
    and Escape, respectively.

    Args:
        theMessage: The message to display

        theResponses:  Possible responses

        default:  The index to the default message

        cancel: The index to the cancel message

        wrap_width:  The wrap width in characters

        **kwds: Additional keyword parameters passed to the Dialog constructor.

    Returns:    The dialog modal result

    """

    #
    # Fix 'Mutable default arguments'
    #
    if theResponses is None:
        theResponses = DEFAULT_ASK_RESPONSES

    box = Dialog(**kwds)
    d = box.margin
    lb = wrapped_label(theMessage, wrap_width)

    lb.topleft = (d, d)
    buts = []
    for caption in theResponses:
        but = Button(caption, action=lambda x=caption: box.dismiss(x))
        buts.append(but)

    brow = Row(buts, spacing=d, equalize='w')
    lb.width = max(lb.width, brow.width)
    col = Column([lb, brow], spacing=d, align='r')
    col.topleft = (d, d)

    if default is not None:
        box.enter_response = theResponses[default]
    else:
        box.enter_response = None
    if cancel is not None:
        box.cancel_response = theResponses[cancel]
    else:
        box.cancel_response = None

    box.add(col)
    box.shrink_wrap()

    return box.present()
예제 #16
0
    def __init__(self, shell: Shell):
        """

        :param shell:
        """
        self.logger = logging.getLogger(__name__)
        #
        # Python 3 update
        #
        # Screen.__init__(self, shell)
        super().__init__(shell)

        from albow.demo.DemoShell import DemoShell
        self.shell = cast(DemoShell, shell)
        f1 = ResourceUtility.get_font(DEMO_TITLE_TEXT_SIZE,
                                      Theme.BUILT_IN_FONT)

        title = Label("Albow Demonstration", font=f1)
        #  emptyButton = Button("Empty", enabled=False)

        menuArray = [[
            self.screen_button("Text Screen", self.shell.text_screen),
            self.screen_button("Text Fields", self.shell.fields_screen),
            self.screen_button("Controls", self.shell.controls_screen),
        ],
                     [
                         self.screen_button("Animation",
                                            self.shell.anim_screen),
                         self.screen_button("Grid View",
                                            self.shell.grid_screen),
                         self.screen_button("Palette View",
                                            self.shell.palette_screen),
                     ],
                     [
                         self.screen_button("Image Array",
                                            self.shell.image_array_screen),
                         self.screen_button("Modal Dialogs",
                                            self.shell.dialog_screen),
                         self.screen_button("Tab Panel",
                                            self.shell.tab_panel_screen),
                     ],
                     [
                         self.screen_button("Table View",
                                            self.shell.table_screen),
                         self.screen_button("MultiChoice",
                                            self.shell.multiChoiceScreen),
                         self.screen_button("MenuBar",
                                            self.shell.menuBarScreen)
                     ],
                     [
                         self.screen_button("Music", self.shell.musicScreen),
                         self.screen_button("ListBox",
                                            self.shell.listBoxScreen),
                         self.screen_button("User Events",
                                            self.shell.userEventsScreen)
                     ]]

        menuGrid = Grid(rows=menuArray,
                        column_spacing=5,
                        row_spacing=2,
                        margin=5)
        quitButton = Button("Quit", shell.quit)

        self.equallySizeButtons(menuArray)

        contents = Column([title, menuGrid, quitButton], align='c', spacing=10)
        self.add_centered(contents)
예제 #17
0
    def screen_button(self, text: str):

        retButton = Button(text)
        return retButton