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
Пример #2
0
    def makeContents(cls, client: Widget, backButton: Button = None) -> Column:

        labelFont = ResourceUtility.get_font(
            DemoListBoxScreen.DEMO_LABEL_TEXT_SIZE, Theme.BUILT_IN_FONT)

        demoListBoxLabel: Label = Label(text="Pick a good guy", font=labelFont)

        demoListBox: ListBox = ListBox(
            nrows=3,
            theClient=client,
            theItems=DemoListBoxScreen.DEMO_LIST_DATA,
            selectAction=cls.selectAction)

        cls.selectedLabel: Label = Label(text="No selection")
        lbColumnAttrs = {"align": "c", 'expand': 0}
        listBoxColumn = Column([demoListBoxLabel, demoListBox],
                               **lbColumnAttrs)

        columnAttrs = {"align": "l", 'expand': 0}
        if backButton is None:
            contents = Column([listBoxColumn, cls.selectedLabel],
                              **columnAttrs)
        else:
            contents = Column([listBoxColumn, cls.selectedLabel, backButton],
                              **columnAttrs)
        return contents
    def makeContents(cls, backButton: Button = None) -> Column:

        textLabel = Label("Make a choice: ")
        textMultiChoice = cls.makeTextMultiChoice()

        imageLabel = Label("Pick your ship: ")
        imageMultiChoice = cls.makeImageMultiChoice()

        rowAttrs = {'spacing': 2}
        textRow = Row([textLabel, textMultiChoice], **rowAttrs)
        imageRow = Row([imageLabel, imageMultiChoice], **rowAttrs)

        innerColumnAttrs = {"align": "l"}
        innerColumn: Column = Column([textRow, imageRow],
                                     spacing=10,
                                     **innerColumnAttrs)

        columnAttrs = {"align": "c", "margin": 5, 'border_width': 1}
        if backButton is None:
            # contents = Column([innerColumn, self.backButton], spacing=10, **columnAttrs)
            contents = innerColumn
        else:
            contents = Column([innerColumn, backButton],
                              spacing=10,
                              **columnAttrs)

        return contents
Пример #4
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)
Пример #5
0
    def makeRegisterDisplay(self) -> Row:

        leftList: List[Widget] = []
        rightList: List[Widget] = []
        for regName in Chip8RegisterName:
            itemRef: ItemRef = ItemRef(base=self.chip8.registers,
                                       index=regName)
            regLabel: Label = Label(regName.name + ':', **self.labelAttrs)
            regValue: ValueDisplay = ValueDisplay(ref=itemRef,
                                                  width=42,
                                                  **self.labelAttrs)
            regValue.format = '0x%04X'

            pairRow: Row = Row([regLabel, regValue], **self.rowColumnAttrs)
            if regName.value % 2:
                rightList.append(pairRow)
            else:
                leftList.append(pairRow)

        leftColumn: Column = Column(leftList, **self.rowColumnAttrs)
        rightColumn: Column = Column(rightList, **self.rowColumnAttrs)
        gridAttrs = {
            'bg_color': Theme.LAMAS_MEDIUM_BLUE,
            'margin': 2,
            'border_width': 1
        }
        retGrid: Row = Row([leftColumn, rightColumn], **gridAttrs)
        return retGrid
Пример #6
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
Пример #7
0
def input_text(thePrompt: str,
               theInputWidth: int,
               theDefaultInput: str = None,
               **kwds):
    """
    Presents a modal dialog containing the given prompt and a text field. The theInputWidth is the width of
    the text field, and the theDefaultInput, if any, is its initial contents. If the dialog is dismissed by pressing
    Return or Enter, the contents of the text field is returned. If it is dismissed by pressing Escape, None
    is returned.

    Args:
        thePrompt:      The message to prompt with

        theInputWidth:  The width of the input text widget

        theDefaultInput: A possible default input

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

    Returns:  The value that the user input
    """
    box = Dialog(**kwds)
    d = box.margin

    def ok():
        box.dismiss(True)

    def cancel():
        box.dismiss(False)

    lb = Label(thePrompt)
    lb.topleft = (d, d)
    tf = TextField(theInputWidth)
    if theDefaultInput:
        tf.set_text(theDefaultInput)
    tf.enter_action = ok
    tf.escape_action = cancel
    tf.top = lb.top
    tf.left = lb.right + 5
    box.add(lb)
    box.add(tf)
    tf.focus()
    box.shrink_wrap()
    if box.present():
        return tf.get_text()
    else:
        return None
    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()
Пример #9
0
    def makeStackDisplay(self) -> Column:

        stackLabel: Label = Label("Stack", **self.labelAttrs)
        stackBox: Chip8UIStack = Chip8UIStack(theChipStack=self.chip8.stack)

        stackContainer: Column = Column([stackLabel, stackBox],
                                        **self.rowColumnAttrs)
        return stackContainer
Пример #10
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)
Пример #11
0
    def __init__(self, shell: Shell):

        super().__init__(shell)

        grid        = DemoGridView()
        lbl         = Label("Cl1ck a Squ4r3")
        grid.output = lbl
        contents    = Column([grid, lbl, self.backButton], align='c', spacing=30)
        self.add_centered(contents)
Пример #12
0
    def makeInstructionListDisplay(self) -> Column:

        instrLabel: Label = Label("Instructions", **self.labelAttrs)
        instrBox: Chip8UIInstructionList = Chip8UIInstructionList(
            instructionList=self.chip8.instructionList)

        instrContainer: Column = Column([instrLabel, instrBox],
                                        **self.rowColumnAttrs)
        return instrContainer
Пример #13
0
    def __init__(self, text, action=None, enable=None, **kwds):
        """

        Args:
            text:   Initializes the button with the given text.

            action: The action should be a function with no arguments; it is called
                    when the mouse is clicked and released again inside the button.

            enable: If supplied, enable should be a function
                    that returns a boolean; it will be used to determine whether the button is enabled.
            **kwds:
        """
        self.logger = logging.getLogger(__name__)

        if action:
            kwds['action'] = action
        if enable:
            kwds['enable'] = enable
        Label.__init__(self, text, **kwds)
        self.border_color = Theme.BLACK
Пример #14
0
    def make_test_page(self, pageNumber: int) -> Widget:
        """

        :param pageNumber: Guess :-)

        :return:  The widget page
        """
        page_size = self.pages.content_size()
        page = Widget(size=page_size, border_width=1)
        lbl = Label(f"This is page {pageNumber}")
        page.add_centered(lbl)

        return page
Пример #15
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()
Пример #16
0
    def __init__(self, shell):
        """

        :param shell:
        """
        super().__init__(shell)

        title = Label("Norwegian Butter Exports", font=self.labelFont)
        table: DemoTableView = DemoTableView()

        contents = Column([title, table, self.backButton],
                          spacing=BaseDemoScreen.DEFAULT_CONTENT_SPACING)

        self.add_centered(contents)
Пример #17
0
    def makeContents(cls, backButton: Button = None) -> Column:

        DemoUserEventsScreen.classTextBox = TextBox()

        f1: Font = ResourceUtility.get_font(16, Theme.BUILT_IN_BOLD_FONT)
        textBoxTitle: Label = Label(text="User Events", font=f1)

        contentAttrs = {
            "align": "c"
        }
        if backButton is None:
            contents: Column = Column([textBoxTitle, DemoUserEventsScreen.classTextBox], **contentAttrs)
        else:
            contents: Column = Column([textBoxTitle, DemoUserEventsScreen.classTextBox, backButton], **contentAttrs)

        return contents
Пример #18
0
    def _makeLabelValueRow(self,
                           refName: str,
                           attrLabel: str,
                           attrFormat: str = None,
                           valueWidth: int = 100) -> Row:

        attrRef: AttrRef = AttrRef(base=self.chip8, name=refName)
        attrLabel: Label = Label(attrLabel, **self.labelAttrs)
        attrValue: ValueDisplay = ValueDisplay(ref=attrRef,
                                               width=valueWidth,
                                               **self.labelAttrs)
        if attrFormat is not None:
            attrValue.format = attrFormat

        retRow: Row = Row([attrLabel, attrValue], **self.rowColumnAttrs)

        return retRow
    def __init__(self, **kwds):

        super().__init__(**kwds)

        self.logger = logging.getLogger(__name__)
        self.textBox = TextBox()

        f1: Font = ResourceUtility.get_font(16, Theme.BUILT_IN_BOLD_FONT)
        textBoxTitle: Label = Label(text="Scheduled Events", font=f1)

        contentAttrs = {
            'align': 'c'
        }

        contents: Column = Column([textBoxTitle, self.textBox], **contentAttrs)
        self.token3 = None
        self.token6 = None
        self.add_centered(contents)
    def makeGridLikeTab(cls):

        gridTabAttrs = {
            'align': "c",
            'margin': 20
        }

        grid: DemoGridView = DemoGridView()
        lbl = Label("Cl1ck a Squ4r3")
        grid.output = lbl

        gridColumn: Column = Column([grid, lbl])

        table: DemoTableView = DemoTableView()
        palette: DemoPaletteView = DemoPaletteView()

        gridTab: Row = Row([table, palette, gridColumn], **gridTabAttrs)

        return gridTab
Пример #21
0
def wrapped_label(text: str, wrap_width: int, **kwds) -> Label:
    """
    Constructs a `albow.widgets.Label` widget from the given text after using the ``textwrap`` module to wrap it to
    the specified width in characters.

    Additional keyword parameters are passed to the Label constructor.

    Args:
        text:       The text to wrap in a label

        wrap_width: The wrap width

        **kwds:     Pass these to the Label constructor

    Returns:    A Label widget

    """
    paras = text.split("\n\n")
    text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])

    return Label(text, **kwds)
Пример #22
0
    def __init__(self, shell: Shell):

        #
        # Python 3 update
        #
        super().__init__(shell)

        w, h = self.size        # Extract from tuple

        grid = DemoPaletteView()
        lbl  = Label("Cl1ck a Squ4r3")

        grid.border_width = 1
        grid.center = (w/2, h/2)
        grid.output = lbl
        columnAttrs = {
            "align": "c",
            'expand': 0
        }

        contents = Column([grid, lbl, self.backButton], **columnAttrs)
        self.add_centered(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
Пример #24
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
Пример #25
0
    def makeContents(cls, backButton: Button = None) -> Column:

        model = DemoControlsModel()

        width_field = FloatField(ref=AttrRef(base=model, name='width'))
        height_field = FloatField(ref=AttrRef(base=model, name='height'))
        area_display = ValueDisplay(ref=AttrRef(base=model, name='area'),
                                    format="%.2f")
        shape = AttrRef(model, 'shape')
        shape_choices = Row([
            RadioButton(setting='rectangle', ref=shape),
            Label("Rectangle"),
            RadioButton(setting='triangle', ref=shape),
            Label("Triangle"),
            RadioButton(setting='ellipse', ref=shape),
            Label("Ellipse"),
        ])
        grid = Grid([
            [Label("Width"), width_field],
            [Label("Height"), height_field],
            [Label("Shape"), shape_choices],
            [Label("Value Area"), area_display],
        ])

        imgBtnBall: ImageButton = ImageButton(theImage="ball.gif")
        imgBtnHighlightedBall: ImageButton = ImageButton(
            theImage="ball.gif", highlightedBgImage="ball_highlighted.png")
        imgBtnDisabledBall: ImageButton = ImageButton(
            theImage="ball.gif",
            disabledBgImage="ball_disabled.png",
            enabled=False)
        imgBtnEnabledBall: ImageButton = ImageButton(
            theImage="ball.gif",
            enabledBgImage="ball_enabled.png",
            enabled=True)

        imgBtnTitle: Label = Label("Image Buttons")
        imgBtnGrid: Grid = Grid([[Label("Regular"), imgBtnBall],
                                 [Label("Highlighted"), imgBtnHighlightedBall],
                                 [Label("Disabled"), imgBtnDisabledBall],
                                 [Label("Enabled"), imgBtnEnabledBall]])

        width_field.focus()

        if backButton is None:
            contents = Column([grid, imgBtnTitle, imgBtnGrid])
        else:
            contents = Column([grid, imgBtnTitle, imgBtnGrid, backButton])
        return contents
Пример #26
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)