Ejemplo n.º 1
0
    def action_preview(self, event):
        config = {}
        config['title'] = self.title.text
        config['font_name'] = self.font_name.get_selection()
        config['color'] = self.color_foreground
        config['background'] = self.color_background

        book = self.book.format(config)
        self.preview = Preview(book)
        self.ilabel.setPreferredSize(self.bookshelf.platform.canvasDimension)
        self.ilabel.set_image(self.preview.current())
        self.preview_button_up.enabled = 1
        self.preview_button_down.enabled = 1
Ejemplo n.º 2
0
 def action_preview(self, event):
     config = {}
     config['title'] = self.title.text
     config['font_name'] = self.font_name.get_selection()
     config['para_start'] = self.para_start.get_selection()
     config['interline'] = self.interline.get_selection()
     config['encoding'] = self.encoding.get_selection()
     config['language'] = self.language.get_selection()
     config['para_indent'] = self.para_indent.get_selection()
     config['hyphenate'] = self.hyphenate.selected
     config['justify'] = self.justify.selected        
     config['screen_border'] = self.screen_border.selected
     config['color'] = self.color_foreground
     config['background'] = self.color_background
     
     book = self.book.format(config)        
     self.preview = Preview(book)
     self.ilabel.setPreferredSize(self.bookshelf.platform.canvasDimension)
     self.ilabel.set_image(self.preview.current())
     self.preview_button_up.enabled = 1
     self.preview_button_down.enabled = 1
Ejemplo n.º 3
0
class FopView(JPanel):
    def __init__(self, bookshelf, fo_file):
        self.bookshelf = bookshelf
        self.book = bookshelf.add_fo_book(fo_file)
        self.preview = None
        self.r = r = c.resource('entry')
        self.layout = BorderLayout()
        # result
        self.title = JTextField(fo_file.getName().split('.')[0], 12)
        self.font_name = PyComboBox([(n, n) for n in bookshelf.font_fabric.list()])

        self.ilabel = PyLabel(None)
        self.ilabel.setPreferredSize(bookshelf.platform.canvasDimension)
        
        # defaults
        self.color_foreground = Color(c.config('DEFAULT_COLOR'))
        self.color_background = Color(c.config('DEFAULT_BACKGROUND_COLOR'))
        self.font_name.set_selection(c.config('DEFAULT_FONT_NAME'))

        self.button_color_foreground = PyColorButton(self.color_foreground, action=self.action_set_foreground)
        self.button_color_background = PyColorButton(self.color_background, action=self.action_set_background)
        
        buttons = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)])
        
        result_panel = PyPanel([
                PyLabel(r['name']), self.title,
                PyLabel(r['font']), self.font_name,
                PyLabel(r['color_foreground']), self.button_color_foreground,
                PyLabel(r['color_background']), self.button_color_background
                ], layout=GridLayout(4,2), title=r['result_title'])
        
        self.preview_button_up = JButton(r['up'], actionPerformed=self.action_up, enabled=0)
        self.preview_button_down = JButton(r['down'], actionPerformed=self.action_down, enabled=0)
        
        preview_buttons = PyPanel([
            self.preview_button_up,
            self.preview_button_down])

        buttons_panel = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)])
        
        preview_panel = PyBorderPanel(south=preview_buttons, center=PyPanel([self.ilabel]), title=r['preview_title'])
         
        self.add(PyBorderPanel(north=result_panel), BorderLayout.WEST)
        self.add(preview_panel, BorderLayout.EAST)
        self.add(buttons_panel, BorderLayout.SOUTH)        
        
    def action_up(self, event):
        self.ilabel.set_image(self.preview.previous())

    def action_down(self, event):
        self.ilabel.set_image(self.preview.next())
    
    def action_preview(self, event):
        config = {}
        config['title'] = self.title.text
        config['font_name'] = self.font_name.get_selection()
        config['color'] = self.color_foreground
        config['background'] = self.color_background

        book = self.book.format(config)
        self.preview = Preview(book)
        self.ilabel.setPreferredSize(self.bookshelf.platform.canvasDimension)
        self.ilabel.set_image(self.preview.current())
        self.preview_button_up.enabled = 1
        self.preview_button_down.enabled = 1
        
    def action_set_foreground(self, event):
        color = JColorChooser.showDialog(self.parent, self.r['select_foreground_color'], self.color_foreground)
        if color is not None:
            self.button_color_foreground.set_color(color)
            self.color_foreground = color
                    
    def action_set_background(self, event):
        color = JColorChooser.showDialog(self.parent, self.r['select_background_color'], self.color_background)
        if color is not None:
            self.button_color_background.set_color(color)
            self.color_background = color

    def action_close(self, event):
        pass

    def refresh_fonts(self):
        self.font_name.replace_items([(n, n) for n in self.bookshelf.font_fabric.list()])
        
    def validate(self):
        if self.title.text == "":
            return (self.r['save_noname_message'], self.r['save_noname_title'])
Ejemplo n.º 4
0
class BookView(JPanel):
    def __init__(self, bookshelf, text_file):
        self.bookshelf = bookshelf
        self.book = bookshelf.add_book(text_file)
        self.preview = None
        self.r = r = c.resource('entry')
        self.layout = BorderLayout()
        # source
        self.renderer = None
        self.language = PyLanguageComboBox(c.config('SUPPORTED_LOCALES'))
        self.encoding = PyComboBox(c.SUPPORTED_ENCODINGS)
        self.para_start = PyComboBox([(x, x) for x in range(11)])
        # result
        self.title = JTextField(text_file.getName().split('.')[0], 12)
        self.font_name = PyComboBox([(n, n) for n in bookshelf.font_fabric.list()])
        self.interline = PyComboBox([(x, x) for x in range(-c.MAX_INTERLINE_SPACING, c.MAX_INTERLINE_SPACING)])
        self.para_indent = PyComboBox([(x, x) for x in range(c.MAX_PARA_INDENT)])
        self.hyphenate = JCheckBox()
        self.justify = JCheckBox()
        self.screen_border = JCheckBox()

        # defaults
        self.color_foreground = Color(c.config('DEFAULT_COLOR'))
        self.color_background = Color(c.config('DEFAULT_BACKGROUND_COLOR'))

        self.button_color_foreground = PyColorButton(self.color_foreground, action=self.action_set_foreground)
        self.button_color_background = PyColorButton(self.color_background, action=self.action_set_background)

        if c.config('DEFAULT_TEXT_LANGUAGE') is not None:
            default_text_language = c.config('DEFAULT_TEXT_LANGUAGE')
        else:
            default_text_language = Locale.getDefault().language
            
        self.encoding.set_selection(c.config('DEFAULT_TEXT_ENCODING'))
        self.para_start.set_selection(c.config('DEFAULT_PARAGRAPH_START'))
        self.language.set_selection(default_text_language)
        self.para_indent.set_selection(c.config('DEFAULT_PARAGRAPH_INDENT'))
        self.font_name.set_selection(c.config('DEFAULT_FONT_NAME'))
        self.hyphenate.selected = c.config('DEFAULT_HYPHENATE_TEXT')
        self.justify.selected = c.config('DEFAULT_JUSTIFY_TEXT')
        self.screen_border.selected = c.config('DEFAULT_SCREEN_BORDER')
        self.interline.set_selection(c.config('DEFAULT_INTERLINE_SPACING'))
        
        self.ilabel = PyLabel(None)
        self.ilabel.setPreferredSize(bookshelf.platform.canvasDimension)
        
        buttons = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)])
        
        result_panel = PyPanel([
                PyLabel(r['name']), self.title,
                PyLabel(r['font']), self.font_name,
                PyLabel(r['interline_spacing']), self.interline,
                PyLabel(r['result_para_start']), self.para_indent,
                PyLabel(r['justify']), self.justify,
                PyLabel(r['hyphenate']), self.hyphenate,
                PyLabel(r['screen_border']), self.screen_border,
                PyLabel(r['color_foreground']), self.button_color_foreground,
                PyLabel(r['color_background']), self.button_color_background
                ], layout=GridLayout(9,2), title=r['result_title'])
        
        source_panel = PyPanel([
                PyLabel(r['language']), self.language,
                PyLabel(r['encoding']), self.encoding,
                PyLabel(r['source_para_start']), self.para_start
                ], layout=GridLayout(3,2), title=r['source_title'])
        
        self.preview_button_up = JButton(r['up'], actionPerformed=self.action_up, enabled=0)
        self.preview_button_down = JButton(r['down'], actionPerformed=self.action_down, enabled=0)
        
        preview_buttons = PyPanel([
            self.preview_button_up,
            self.preview_button_down])

        buttons_panel = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)])
        
        preview_panel = PyBorderPanel(south=preview_buttons, center=PyPanel([self.ilabel]), title=r['preview_title'])
         
        self.add(PyBorderPanel(north=result_panel, south=source_panel), BorderLayout.WEST)
        self.add(preview_panel, BorderLayout.EAST)
        self.add(buttons_panel, BorderLayout.SOUTH)
        
    def action_up(self, event):
        self.ilabel.set_image(self.preview.previous())

    def action_down(self, event):
        self.ilabel.set_image(self.preview.next())

    def action_preview(self, event):
        config = {}
        config['title'] = self.title.text
        config['font_name'] = self.font_name.get_selection()
        config['para_start'] = self.para_start.get_selection()
        config['interline'] = self.interline.get_selection()
        config['encoding'] = self.encoding.get_selection()
        config['language'] = self.language.get_selection()
        config['para_indent'] = self.para_indent.get_selection()
        config['hyphenate'] = self.hyphenate.selected
        config['justify'] = self.justify.selected        
        config['screen_border'] = self.screen_border.selected
        config['color'] = self.color_foreground
        config['background'] = self.color_background
        
        book = self.book.format(config)        
        self.preview = Preview(book)
        self.ilabel.setPreferredSize(self.bookshelf.platform.canvasDimension)
        self.ilabel.set_image(self.preview.current())
        self.preview_button_up.enabled = 1
        self.preview_button_down.enabled = 1

    def action_close(self, event):
        pass
        
    def action_set_foreground(self, event):
        color = JColorChooser.showDialog(self.parent, self.r['select_foreground_color'], self.color_foreground)
        if color is not None:
            self.button_color_foreground.set_color(color)
            self.color_foreground = color
                    
    def action_set_background(self, event):
        color = JColorChooser.showDialog(self.parent, self.r['select_background_color'], self.color_background)
        if color is not None:
            self.button_color_background.set_color(color)
            self.color_background = color
        
    def refresh_fonts(self):
        self.font_name.replace_items([(n, n) for n in self.bookshelf.font_fabric.list()])
        
    def validate(self):
        if self.title.text == "":
            return (self.r['save_noname_message'], self.r['save_noname_title'])