Esempio n. 1
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)
Esempio n. 2
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()