Exemple #1
0
 def __init__(self, shell, filename, **kwds):
     
     text = 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)
     
     self.b = ((shell.rect.width-page_size[0])/2, (shell.rect.height-page_size[1])/2)
     
     page_rect = Rect(self.b, page_size)
     gap = (0, 18)
     b1.topleft = add(page_rect.bottomleft, gap)
     b2.midtop = add(page_rect.midbottom, gap)
     b3.topright = add(page_rect.bottomright, gap)
     Screen.__init__(self, shell, **kwds)
     self.size =  add(b3.bottomright, self.b)
     self.add(b1)
     self.add(b2)
     self.add(b3)
     self.prev_button = b1
     self.next_button = b3
     self.set_current_page(0)
 def __init__(self, prompt=None, suffixes=None, **kwds):
     Dialog.__init__(self, **kwds)
     label = None
     d = self.margin
     self.suffixes = suffixes or ("", )
     up_button = Button(self.up_button_text, action=self.go_up)
     dir_box = DirPathView(self.box_width + 250, 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
     tree = FSTree(self, inner_width=250, directory='/')
     self.tree = tree
     row = Row((tree, list_box), margin=0)
     ctrls = [top_row, row]
     prompt = prompt or self.default_prompt
     if prompt:
         label = Label(prompt)
     if self.saving:
         filename_box = TextFieldWrapped(self.box_width)
         filename_box.change_action = self.update_filename
         filename_box._enter_action = filename_box.enter_action
         filename_box.enter_action = self.enter_action
         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.getcwdu()
     #print "FileDialog: cwd =", repr(self.directory) ###
     if self.saving:
         filename_box.focus()
 def __init__(self, prompt=None, suffixes=None, **kwds):
     Dialog.__init__(self, **kwds)
     label = None
     d = self.margin
     self.suffixes = suffixes or ("",)
     up_button = Button(self.up_button_text, action=self.go_up)
     dir_box = DirPathView(self.box_width + 250, 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
     tree = FSTree(self, inner_width=250, directory="/")
     self.tree = tree
     row = Row((tree, list_box), margin=0)
     ctrls = [top_row, row]
     prompt = prompt or self.default_prompt
     if prompt:
         label = Label(prompt)
     if self.saving:
         filename_box = TextFieldWrapped(self.box_width)
         filename_box.change_action = self.update_filename
         filename_box._enter_action = filename_box.enter_action
         filename_box.enter_action = self.enter_action
         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.getcwdu()
     # print "FileDialog: cwd =", repr(self.directory) ###
     if self.saving:
         filename_box.focus()
    def __init__(self,
                 prompt=None,
                 suffixes=None,
                 default_suffix=None,
                 **kwds):
        Dialog.__init__(self, **kwds)
        label = None
        d = self.margin
        self.suffixes = suffixes or ("", )
        self.file_type = self.suffixes[0]  # To be removed
        self.compute_file_types()
        self.default_suffix = default_suffix  # The default file extension. Will be searched in 'suffixes'.
        up_button = Button(self.up_button_text, action=self.go_up)
        dir_box = DirPathView(self.box_width + 250, 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
        tree = FSTree(self, inner_width=250, directory='/')
        self.tree = tree
        row = Row((tree, list_box), margin=0)
        ctrls = [top_row, row]
        prompt = prompt or self.default_prompt
        if prompt:
            label = Label(prompt)
        if suffixes:
            filetype_label = Label("File type", width=250)

            def set_file_type():
                self.file_type = self.filetype_button.get_value(
                )  # To be removed
                self.compute_file_types(self.filetype_button.get_value())
                self.list_box.update()

            filetype_button = ChoiceButton(choices=self.suffixes,
                                           width=250,
                                           choose=set_file_type)
            if default_suffix:
                v = next((s for s in self.suffixes
                          if ("*.%s;" % default_suffix in s or "*.%s)" %
                              default_suffix in s)), None)
                if v:
                    filetype_button.selectedChoice = v
                    self.compute_file_types(v)
            self.filetype_button = filetype_button
        if self.saving:
            filename_box = TextFieldWrapped(self.box_width)
            filename_box.change_action = self.update_filename
            filename_box._enter_action = filename_box.enter_action
            filename_box.enter_action = self.enter_action
            self.filename_box = filename_box
            if suffixes:
                ctrls.append(
                    Row([
                        Column([label, filename_box], align='l', spacing=0),
                        Column([filetype_label, filetype_button],
                               align='l',
                               spacing=0)
                    ], ))
            else:
                ctrls.append(
                    Column([label, filename_box], align='l', spacing=0))
        else:
            if label:
                ctrls.insert(0, label)
            if suffixes:
                ctrls.append(
                    Column([filetype_label, filetype_button],
                           align='l',
                           spacing=0))
        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()
    def __init__(self, prompt=None, suffixes=None, default_suffix=None, **kwds):
        Dialog.__init__(self, **kwds)
        label = None
        d = self.margin
        self.suffixes = suffixes or ("",)
        self.file_type = self.suffixes[0] # To be removed
        self.compute_file_types()
        self.default_suffix = default_suffix  # The default file extension. Will be searched in 'suffixes'.
        up_button = Button(self.up_button_text, action=self.go_up)
        dir_box = DirPathView(self.box_width + 250, 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
        tree = FSTree(self, inner_width=250, directory='/')
        self.tree = tree
        row = Row((tree, list_box), margin=0)
        ctrls = [top_row, row]
        prompt = prompt or self.default_prompt
        if prompt:
            label = Label(prompt)
        if suffixes:
            filetype_label = Label("File type", width=250)

            def set_file_type():
                self.file_type = self.filetype_button.get_value() # To be removed
                self.compute_file_types(self.filetype_button.get_value())
                self.list_box.update()

            filetype_button = ChoiceButton(choices=self.suffixes, width=250, choose=set_file_type)
            if default_suffix:
                v = next((s for s in self.suffixes if ("*.%s;"%default_suffix in s or "*.%s)"%default_suffix in s)), None)
                if v:
                    filetype_button.selectedChoice = v
                    self.compute_file_types(v)
            self.filetype_button = filetype_button
        if self.saving:
            filename_box = TextFieldWrapped(self.box_width)
            filename_box.change_action = self.update_filename
            filename_box._enter_action = filename_box.enter_action
            filename_box.enter_action = self.enter_action
            self.filename_box = filename_box
            if suffixes:
                ctrls.append(Row([Column([label, filename_box], align='l', spacing=0),
                                  Column([filetype_label, filetype_button], align='l', spacing=0)
                                  ],
                                 )
                             )
            else:
                ctrls.append(Column([label, filename_box], align='l', spacing=0))
        else:
            if label:
                ctrls.insert(0, label)
            if suffixes:
                ctrls.append(Column([filetype_label, filetype_button], align='l', spacing=0))
        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.getcwdu()
        #print "FileDialog: cwd =", repr(self.directory) ###
        if self.saving:
            filename_box.focus()