Ejemplo n.º 1
0
    def __init__(self,
                 disabledBgImage: str = None,
                 enabledBgImage: str = None,
                 highlightedBgImage: str = None,
                 **kwds):
        """
        You must as a minimum supply a single image via `theImage` parameter.  Optionally, you can supply
        enabled, disabled, and highlighted images

        Args:
            disabledBgImage:  The image to display when the button is disabled

            enabledBGImage:  The image to display when the button is enabled

            highlightedBgImage: The image to display when the button is highlighted

            **kwds:
        """
        Image.__init__(self, **kwds)

        self.logger = logging.getLogger(__name__)
        self._disabledBgImage = None
        self._enabledBgImage = None
        self._highlightedBgImage = None

        if disabledBgImage != None:
            self._disabledBgImage = ResourceUtility.get_image(disabledBgImage)

        if enabledBgImage != None:
            self._enabledBgImage = ResourceUtility.get_image(enabledBgImage)

        if highlightedBgImage != None:
            self._highlightedBgImage = ResourceUtility.get_image(
                highlightedBgImage)
Ejemplo n.º 2
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}")
Ejemplo n.º 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
Ejemplo n.º 4
0
    def __init__(self, theImage = None, theRect: Rect = None, **kwds):
        """
        TODO  Do a unit test on this class

        Initializes the widget to display the given image. The initial size is determined by the image.

        Args:
            theImage:  Either a string that is the image name and can be found via the resource lookup methods
            or an actual image.  (TBD) - I don't like this and will change the API to only accept image names

            theRect:   The pygame rectangle to draw in

            **kwds:
        """
        super().__init__(theRect, **kwds)

        if theImage:
            if isinstance(theImage, str):
                theImage = ResourceUtility.get_image(theImage)
            w, h = theImage.get_size()
            d = 2 * self.margin
            self.size = w + d, h + d
            self._image = theImage
        else:
            self._image = None
Ejemplo n.º 5
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
Ejemplo n.º 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)
    def testLoadSound(self):

        import pygame
        pygame.init()

        fqFileName: str = self.getFullResourcePath(TEST_SOUND_RELATIVE_PATH)

        dummySound = ResourceUtility.load_sound(fqFileName)
        self.logger.info(f"{dummySound}")
    def testLoadSoundFail(self):

        fqFileName: str = self.getFullResourcePath(TEST_SOUND_RELATIVE_PATH)

        ResourceUtility.sound_cache = None
        dummySound = ResourceUtility.load_sound(fqFileName)

        self.assertEqual(first=ResourceUtility.dummy_sound,
                         second=dummySound,
                         msg="Did not get the dummy sound")
Ejemplo n.º 9
0
    def get_music(*names, **kwds) -> str:
        """

        Args:
            *names:

            **kwds: Keyword/Value pairs passed along

        Returns:  The full pathname of a music file from the `music` resource subdirectory.
        """
        prefix = kwds.pop('prefix', "music")
        return ResourceUtility.resource_path(prefix, *names)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def testFindResourceDirSuccess(self):

        currentDirectory = os.getcwd()
        self.logger.info(f"cwd: '{currentDirectory}'")

        newDir = "resources"
        os.mkdir(newDir)
        resourceDir = ResourceUtility.find_resource_dir()

        self.assertIsNotNone(resourceDir, "Failed to return something")

        self.assertEqual(resourceDir.lower(),
                         f"{currentDirectory}/resources".lower(),
                         "Found in wrong place")
        os.rmdir("resources")
Ejemplo n.º 12
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
    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)
Ejemplo n.º 14
0
    def get_image_array(cls, name, shape, **kwds) -> 'ImageArray':
        """
        Creates and returns an ImageArray from an image resource with the given name. The ImageArray is cached, and
        subsequent calls with the same name will return the cached object. Additional keyword arguments are
        passed on to ``albow.core.ResourceUtility``.get_image().

        Args:
            name:   The image name

            shape:  The shape

            **kwds:

        Returns:

        """
        result = cls.image_array_cache.get(name)
        if result is None:
            result = ImageArray(ResourceUtility.get_image(name, **kwds), shape)
            cls.image_array_cache[name] = result
        return result
    def makeImageMultiChoice(cls):

        cls.classLogger.debug(
            f"Resource directory: {ResourceUtility.find_resource_dir()}")

        pathToImages = ResourceUtility.find_resource_dir(
        ) + "/" + IMAGE_RESOURCES_SUBDIR

        cls.classLogger.debug(f"Path to images: {pathToImages}")

        choiceImages = []
        for imageFileName in DEMO_IMAGES:

            imagePath = os.path.join(pathToImages, imageFileName)

            cls.classLogger.debug(f"Image Path: {imagePath}")
            choiceImage = pygame.image.load(imagePath)
            choiceImages.append(choiceImage)

        imageMultiChoice = ImageMultiChoice(images=choiceImages,
                                            values=DEMO_IMAGE_VALUES)

        return imageMultiChoice
Ejemplo n.º 16
0
 def testFindResourceDirFailure(self):
     ResourceUtility.find_resource_dir()
Ejemplo n.º 17
0
    def testGetImageFail(self):

        ResourceUtility.get_image("")
Ejemplo n.º 18
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)