"Fossies" - the Fresh Open Source Software Archive

Member "sk1-2.0rc4/src/sk1/printing/propsdlg/pdfpropsdlg.py" (25 May 2019, 9559 Bytes) of package /linux/misc/sk1-2.0rc4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "pdfpropsdlg.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0rc3_vs_2.0rc4.

    1 # -*- coding: utf-8 -*-
    2 #
    3 #  Copyright (C) 2016 by Igor E. Novikov
    4 #
    5 #  This program is free software: you can redistribute it and/or modify
    6 #  it under the terms of the GNU General Public License as published by
    7 #  the Free Software Foundation, either version 3 of the License, or
    8 #  (at your option) any later version.
    9 #
   10 #  This program is distributed in the hope that it will be useful,
   11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 #  GNU General Public License for more details.
   14 #
   15 #  You should have received a copy of the GNU General Public License
   16 #  along with this program.  If not, see <https://www.gnu.org/licenses/>.
   17 
   18 import wal
   19 
   20 from uc2 import uc2const
   21 from uc2.formats.pdf import pdfconst
   22 
   23 from sk1 import _
   24 from sk1.resources import get_icon, icons
   25 from sk1.pwidgets import StaticUnitLabel, StaticUnitSpin
   26 
   27 from generic import PrnProsDialog
   28 
   29 CS = [uc2const.COLOR_GRAY, uc2const.COLOR_CMYK, uc2const.COLOR_RGB]
   30 
   31 
   32 class GenModePanel(wal.LabeledPanel):
   33     printer = None
   34 
   35     def __init__(self, parent, printer):
   36         self.printer = printer
   37         wal.LabeledPanel.__init__(self, parent, _('Generation options'))
   38 
   39         vpanel = wal.VPanel(self)
   40 
   41         grid = wal.GridPanel(vpanel, 2, 2, 2, 3)
   42         grid.add_growable_col(1)
   43 
   44         grid.pack(wal.Label(grid, _('PDF version:')))
   45 
   46         self.ver_combo = wal.Combolist(grid, items=pdfconst.PDF_VER_NAMES)
   47         grid.pack(self.ver_combo, fill=True)
   48 
   49         grid.pack(wal.Label(grid, _('Color space:')))
   50 
   51         self.cs_combo = wal.Combolist(grid, items=CS)
   52         grid.pack(self.cs_combo, fill=True)
   53 
   54         vpanel.pack(grid, fill=True)
   55 
   56         vpanel.pack((3, 3))
   57 
   58         self.use_spot = wal.Checkbox(vpanel, _('Use SPOT colors'))
   59         vpanel.pack(self.use_spot, align_center=False)
   60 
   61         self.compressed = wal.Checkbox(vpanel, _('Use compression'))
   62         vpanel.pack(self.compressed, align_center=False)
   63 
   64         self.pack(vpanel, fill=True, expand=True, padding_all=5)
   65 
   66         index = pdfconst.PDF_VERSIONS.index(self.printer.pdf_version)
   67         self.ver_combo.set_active(index)
   68         self.cs_combo.set_active(CS.index(self.printer.colorspace))
   69         self.use_spot.set_value(self.printer.use_spot)
   70         self.compressed.set_value(self.printer.compressed)
   71 
   72     def save(self):
   73         self.printer.use_spot = self.use_spot.get_value()
   74         self.printer.compressed = self.compressed.get_value()
   75         index = self.ver_combo.get_active()
   76         self.printer.pdf_version = pdfconst.PDF_VERSIONS[index]
   77         self.printer.colorspace = CS[self.cs_combo.get_active()]
   78 
   79 
   80 class PagePanel(wal.LabeledPanel):
   81     app = None
   82     printer = None
   83     items = []
   84 
   85     def __init__(self, parent, printer, app):
   86         self.app = app
   87         self.printer = printer
   88         wal.LabeledPanel.__init__(self, parent, _('Document page'))
   89 
   90         grid = wal.GridPanel(self, 3, 2, 3, 3)
   91         grid.add_growable_col(1)
   92 
   93         grid.pack(wal.Label(grid, _('Page size:')))
   94 
   95         self.size_combo = wal.Combolist(grid, onchange=self.on_change)
   96         grid.pack(self.size_combo, fill=True)
   97 
   98         grid.pack(wal.Label(grid, _('Width:')))
   99 
  100         hpanel = wal.HPanel(grid)
  101 
  102         self.wspin = StaticUnitSpin(self.app, hpanel)
  103         hpanel.pack(self.wspin)
  104 
  105         hpanel.pack((5, 5))
  106 
  107         hpanel.pack(wal.Label(grid, _('Height:')), padding=5)
  108 
  109         self.hspin = StaticUnitSpin(self.app, hpanel)
  110         hpanel.pack(self.hspin)
  111         hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5)
  112 
  113         grid.pack(hpanel)
  114 
  115         grid.pack(wal.Label(grid, _('Orientation:')))
  116 
  117         hpanel = wal.HPanel(grid)
  118 
  119         self.port_opt = wal.Radiobutton(hpanel, uc2const.ORIENTS_NAMES[0],
  120                                         group=True)
  121         self.land_opt = wal.Radiobutton(hpanel, uc2const.ORIENTS_NAMES[1])
  122 
  123         hpanel.pack(self.port_opt)
  124         hpanel.pack((15, 5))
  125         hpanel.pack(self.land_opt)
  126 
  127         grid.pack(hpanel)
  128 
  129         self.pack(grid, fill=True, expand=True, padding_all=7)
  130 
  131         self.set_data()
  132 
  133     def set_data(self):
  134         self.land_opt.set_value(True)
  135         if self.printer.page_orientation == uc2const.PORTRAIT:
  136             self.port_opt.set_value(True)
  137 
  138         self.items = self.printer.get_format_items()
  139         self.size_combo.set_items(self.items)
  140         if not self.printer.page_format[0] == 'Custom':
  141             index = self.items.index(self.printer.page_format[0])
  142         else:
  143             index = len(self.items) - 1
  144         self.size_combo.set_active(index)
  145 
  146         if self.printer.is_custom_supported():
  147             minw, minh = self.printer.customs[0]
  148             maxw, maxh = self.printer.customs[1]
  149             self.wspin.set_point_range((minw, maxw))
  150             self.hspin.set_point_range((minh, maxh))
  151         self.on_change()
  152 
  153     def on_change(self):
  154         index = self.size_combo.get_active()
  155         status = False
  156         if index == len(self.items) - 1:
  157             if not self.hspin.get_point_value() and \
  158                             self.printer.page_format[0] == 'Custom':
  159                 w, h = self.printer.page_format[1]
  160                 self.wspin.set_point_value(w)
  161                 self.hspin.set_point_value(h)
  162             status = True
  163         else:
  164             w, h = uc2const.PAGE_FORMATS[uc2const.PAGE_FORMAT_NAMES[index]]
  165             self.wspin.set_point_value(w)
  166             self.hspin.set_point_value(h)
  167         self.wspin.set_enable(status)
  168         self.hspin.set_enable(status)
  169 
  170     def save(self):
  171         index = self.size_combo.get_active()
  172         prn = self.printer
  173         if prn.is_custom_supported() and index == len(self.items) - 1:
  174             w = self.wspin.get_point_value()
  175             h = self.hspin.get_point_value()
  176             prn.page_format = ('Custom', (w, h))
  177         else:
  178             media = uc2const.PAGE_FORMAT_NAMES[index]
  179             w, h = uc2const.PAGE_FORMATS[media]
  180             prn.page_format = (media, (w, h))
  181         self.printer.page_orientation = uc2const.LANDSCAPE
  182         if self.port_opt.get_value():
  183             self.printer.page_orientation = uc2const.PORTRAIT
  184 
  185 
  186 class DocInfoPanel(wal.LabeledPanel):
  187     printer = None
  188 
  189     def __init__(self, parent, printer, app):
  190         self.printer = printer
  191         self.app = app
  192         wal.LabeledPanel.__init__(self, parent, _('Document metainfo'))
  193 
  194         grid = wal.GridPanel(self, 4, 2, 2, 5)
  195         grid.add_growable_col(1)
  196 
  197         grid.pack(wal.Label(grid, _('Title:')))
  198         self.title = wal.Entry(grid, self.printer.meta_title)
  199         grid.pack(self.title, fill=True)
  200 
  201         grid.pack(wal.Label(grid, _('Subject:')))
  202         self.subject = wal.Entry(grid, self.printer.meta_subject)
  203         grid.pack(self.subject, fill=True)
  204 
  205         grid.pack(wal.Label(grid, _('Author:')))
  206         self.author = wal.Entry(grid, self.printer.meta_author)
  207         grid.pack(self.author, fill=True)
  208 
  209         grid.pack(wal.Label(grid, _('Keywords:')))
  210         self.keywords = wal.Entry(grid, self.printer.meta_keywords)
  211         grid.pack(self.keywords, fill=True)
  212 
  213         self.pack(grid, fill=True, expand=True, padding_all=7)
  214 
  215     def is_metadata(self):
  216         metainfo = self.app.current_doc.model.metainfo
  217         if metainfo:
  218             return bool(metainfo[0] or metainfo[2])
  219         return False
  220 
  221     def import_data(self):
  222         metainfo = self.app.current_doc.model.metainfo
  223         self.title.set_value(self.app.current_doc.doc_name)
  224         self.author.set_value(metainfo[0])
  225         self.keywords.set_value(metainfo[2])
  226 
  227     def save(self):
  228         self.printer.meta_title = self.title.get_value()
  229         self.printer.meta_subject = self.subject.get_value()
  230         self.printer.meta_author = self.author.get_value()
  231         self.printer.meta_keywords = self.keywords.get_value()
  232 
  233 
  234 class MainPanel(wal.VPanel):
  235     app = None
  236     printer = None
  237     panels = []
  238 
  239     def __init__(self, parent, printer, app):
  240         self.app = app
  241         self.printer = printer
  242         wal.VPanel.__init__(self, parent)
  243 
  244         hpanel = wal.HPanel(self)
  245         icon = get_icon(icons.PD_PRINTER_PDF, size=wal.DEF_SIZE)
  246         hpanel.pack(wal.Bitmap(hpanel, icon), padding=5)
  247 
  248         self.prnmode_panel = GenModePanel(hpanel, self.printer)
  249         hpanel.pack(self.prnmode_panel, fill=True, expand=True)
  250 
  251         self.pack(hpanel, fill=True)
  252 
  253         self.page_panel = PagePanel(self, self.printer, self.app)
  254         self.pack(self.page_panel, fill=True)
  255 
  256         self.doc_info = DocInfoPanel(self, self.printer, self.app)
  257         self.pack(self.doc_info, fill=True, expand=True)
  258 
  259         self.panels = [self.prnmode_panel, self.page_panel, self.doc_info]
  260 
  261     def save(self):
  262         for item in self.panels:
  263             item.save()
  264 
  265 
  266 class PDF_PrnPropsDialog(PrnProsDialog):
  267     def build(self):
  268         PrnProsDialog.build(self)
  269         self.panel.pack((5, 5))
  270         self.main_panel = MainPanel(self.panel, self.printer, self.app)
  271         self.panel.pack(self.main_panel, fill=True, expand=True)
  272 
  273     def set_dialog_buttons(self):
  274         PrnProsDialog.set_dialog_buttons(self)
  275         self.import_btn = wal.Button(
  276             self.left_button_box, _('Set metainfo'),
  277             tooltip=_('Set metainfo from current document'),
  278             onclick=self.main_panel.doc_info.import_data)
  279         self.left_button_box.pack(self.import_btn)
  280         self.import_btn.set_enable(self.main_panel.doc_info.is_metadata())
  281 
  282     def get_result(self):
  283         self.main_panel.save()
  284         return True