Ejemplo n.º 1
0
 def insert_blank_page(self, width, height, position=None):
     view = MiniView(self.width, self.height)
     view.connect('selected', self.on_page_selected)
     view.connect('unselected', self.on_page_unselected)
     view.set_blank_page(width, height)
     view.show()
     self.pack_start(view, expand=True, fill=True, padding=0)
     self.set_homogeneous(True)
     if position != None:
         if position > 0:
             self.reorder_child(self.get_children()[-1], position)
         else:
             self.reorder_child(self.get_children()[-1], 1)
             self.reorder_child(self.get_children()[0], 1)
Ejemplo n.º 2
0
	def insert_blank_page(self,width,height,position=None):
		view = MiniView(self.width,self.height)
		view.connect('selected',self.on_page_selected)
		view.connect('unselected',self.on_page_unselected)
		view.set_blank_page(width,height)
		view.show()
		self.pack_start(view, expand=True, fill=True, padding=0)
		self.set_homogeneous(True)
		if position!=None:
			if position>0:
				self.reorder_child(self.get_children()[-1],position)
			else:
				self.reorder_child(self.get_children()[-1],1)
				self.reorder_child(self.get_children()[0],1)
Ejemplo n.º 3
0
    def init_ui(self):
        BasicDialog.init_ui(self)

        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(630, 630)
        self.grid.attach(self.scrolledwindow1, 0, 0, 1, 1)

        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)

        self.pages = {}

        self.scale = 100

        self.init_headerbar()

        if self.filename is not None:
            uri = "file://" + self.filename
            self.document = Poppler.Document.new_from_file(uri, None)
            self.hb.set_subtitle(os.path.basename(self.filename))
            self.set_page(0)

        self.show_all()
Ejemplo n.º 4
0
 def on_self_button1_clicked(self, widget):
     dialog = Gtk.FileChooserDialog(
         _('Select a pdf file'), self, Gtk.FileChooserAction.OPEN,
         (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
          Gtk.ResponseType.OK))
     dialog.set_default_response(Gtk.ResponseType.OK)
     filter = Gtk.FileFilter()
     filter.set_name(_('Pdf files'))
     filter.add_mime_type('application/pdf')
     filter.add_pattern('*.pdf')
     dialog.add_filter(filter)
     preview = MiniView(200, force=True)
     dialog.set_use_preview_label(False)
     dialog.set_preview_widget(preview)
     dialog.connect('update-preview', self.update_preview_cb, preview)
     response = dialog.run()
     if response == Gtk.ResponseType.OK:
         filename = dialog.get_filename()
         ans = os.path.split(filename)
         if len(ans) > 1:
             self.filename = filename
             self.button1.set_label(ans[1])
     dialog.destroy()
Ejemplo n.º 5
0
 def __init__(self, filename=None):
     Gtk.Dialog.__init__(
         self, _('Watermark'), None,
         Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
         (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
          Gtk.ResponseType.CANCEL))
     self.set_size_request(500, 140)
     self.set_resizable(False)
     self.set_icon_from_file(comun.ICON)
     self.connect('destroy', self.close_application)
     vbox0 = Gtk.VBox(spacing=5)
     vbox0.set_border_width(5)
     self.get_content_area().add(vbox0)
     #
     notebook = Gtk.Notebook()
     vbox0.add(notebook)
     #
     frame = Gtk.Frame()
     notebook.append_page(frame, tab_label=Gtk.Label(_('Watermark')))
     #
     table = Gtk.Table(rows=6, columns=2, homogeneous=False)
     table.set_border_width(5)
     table.set_col_spacings(5)
     table.set_row_spacings(5)
     frame.add(table)
     #
     frame1 = Gtk.Frame()
     table.attach(frame1,
                  0,
                  1,
                  0,
                  1,
                  xoptions=Gtk.AttachOptions.EXPAND,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.scrolledwindow1 = Gtk.ScrolledWindow()
     self.scrolledwindow1.set_size_request(320, 320)
     frame1.add(self.scrolledwindow1)
     self.viewport1 = MiniView()
     self.scrolledwindow1.add(self.viewport1)
     frame2 = Gtk.Frame()
     table.attach(frame2,
                  1,
                  2,
                  0,
                  1,
                  xoptions=Gtk.AttachOptions.EXPAND,
                  yoptions=Gtk.AttachOptions.SHRINK)
     scrolledwindow2 = Gtk.ScrolledWindow()
     scrolledwindow2.set_size_request(320, 320)
     frame2.add(scrolledwindow2)
     #
     self.viewport2 = MiniView()
     scrolledwindow2.add(self.viewport2)
     #
     self.scale = 100
     vertical_options = Gtk.ListStore(str, int)
     vertical_options.append([_('Top'), TOP])
     vertical_options.append([_('Middle'), MIDLE])
     vertical_options.append([_('Bottom'), BOTTOM])
     #
     horizontal_options = Gtk.ListStore(str, int)
     horizontal_options.append([_('Left'), LEFT])
     horizontal_options.append([_('Center'), CENTER])
     horizontal_options.append([_('Right'), RIGHT])
     #
     self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
     table.attach(self.rbutton0,
                  0,
                  2,
                  1,
                  2,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     vbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
     table.attach(vbox,
                  0,
                  2,
                  2,
                  3,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     label = Gtk.Label(_('Watermark') + ':')
     label.set_alignment(0, 0.5)
     vbox.pack_start(label, False, False, 0)
     self.entry = Gtk.Entry()
     self.entry.set_width_chars(10)
     self.entry.set_sensitive(False)
     vbox.pack_start(self.entry, True, True, 0)
     button = Gtk.Button(_('Choose File'))
     button.connect('clicked', self.on_button_clicked)
     vbox.pack_start(button, False, False, 0)
     #
     label = Gtk.Label(_('Horizontal position') + ':')
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  3,
                  4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     #
     self.horizontal = Gtk.ComboBox.new_with_model_and_entry(
         horizontal_options)
     self.horizontal.set_entry_text_column(0)
     self.horizontal.set_active(0)
     self.horizontal.connect('changed', self.update_preview)
     table.attach(self.horizontal,
                  1,
                  2,
                  3,
                  4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     label = Gtk.Label(_('Vertical position') + ':')
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  4,
                  5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     #
     self.vertical = Gtk.ComboBox.new_with_model_and_entry(vertical_options)
     self.vertical.set_entry_text_column(0)
     self.vertical.set_active(0)
     self.vertical.connect('changed', self.update_preview)
     table.attach(self.vertical,
                  1,
                  2,
                  4,
                  5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     #
     label = Gtk.Label(_('Watermark zoom') + ':')
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  5,
                  6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     #
     self.watermark_zoom = Gtk.SpinButton()
     self.watermark_zoom.connect('value-changed', self.update_preview)
     self.watermark_zoom.set_adjustment(
         Gtk.Adjustment(100, 0, 110, 1, 10, 10))
     table.attach(self.watermark_zoom,
                  1,
                  2,
                  5,
                  6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     #
     label = Gtk.Label(_('Set horizontal margin') + ':')
     label.set_alignment(0, .5)
     table.attach(label,
                  0,
                  1,
                  6,
                  7,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.horizontal_margin = Gtk.SpinButton()
     self.horizontal_margin.set_adjustment(
         Gtk.Adjustment(5, 0, 100, 1, 10, 10))
     table.attach(self.horizontal_margin,
                  1,
                  2,
                  6,
                  7,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.horizontal_margin.connect('value-changed', self.update_preview)
     label = Gtk.Label(_('Set vertical margin') + ':')
     label.set_alignment(0, .5)
     table.attach(label,
                  0,
                  1,
                  7,
                  8,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.vertical_margin = Gtk.SpinButton()
     self.vertical_margin.set_adjustment(
         Gtk.Adjustment(5, 0, 100, 1, 10, 10))
     table.attach(self.vertical_margin,
                  1,
                  2,
                  7,
                  8,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.vertical_margin.connect('value-changed', self.update_preview)
     self.show_all()
     if filename is not None:
         uri = "file://" + filename
         document = Poppler.Document.new_from_file(uri, None)
         if document.get_n_pages() > 0:
             self.viewport1.set_page(document.get_page(0))
             self.viewport2.set_page(document.get_page(0))
Ejemplo n.º 6
0
class WatermarkDialog(Gtk.Dialog):
    def __init__(self, filename=None):
        Gtk.Dialog.__init__(
            self, _('Watermark'), None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
             Gtk.ResponseType.CANCEL))
        self.set_size_request(500, 140)
        self.set_resizable(False)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close_application)
        vbox0 = Gtk.VBox(spacing=5)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        #
        notebook = Gtk.Notebook()
        vbox0.add(notebook)
        #
        frame = Gtk.Frame()
        notebook.append_page(frame, tab_label=Gtk.Label(_('Watermark')))
        #
        table = Gtk.Table(rows=6, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1,
                     0,
                     1,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(320, 320)
        frame1.add(self.scrolledwindow1)
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        frame2 = Gtk.Frame()
        table.attach(frame2,
                     1,
                     2,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(320, 320)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        #
        self.scale = 100
        vertical_options = Gtk.ListStore(str, int)
        vertical_options.append([_('Top'), TOP])
        vertical_options.append([_('Middle'), MIDLE])
        vertical_options.append([_('Bottom'), BOTTOM])
        #
        horizontal_options = Gtk.ListStore(str, int)
        horizontal_options.append([_('Left'), LEFT])
        horizontal_options.append([_('Center'), CENTER])
        horizontal_options.append([_('Right'), RIGHT])
        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0,
                     0,
                     2,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        vbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        table.attach(vbox,
                     0,
                     2,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        label = Gtk.Label(_('Watermark') + ':')
        label.set_alignment(0, 0.5)
        vbox.pack_start(label, False, False, 0)
        self.entry = Gtk.Entry()
        self.entry.set_width_chars(10)
        self.entry.set_sensitive(False)
        vbox.pack_start(self.entry, True, True, 0)
        button = Gtk.Button(_('Choose File'))
        button.connect('clicked', self.on_button_clicked)
        vbox.pack_start(button, False, False, 0)
        #
        label = Gtk.Label(_('Horizontal position') + ':')
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.horizontal = Gtk.ComboBox.new_with_model_and_entry(
            horizontal_options)
        self.horizontal.set_entry_text_column(0)
        self.horizontal.set_active(0)
        self.horizontal.connect('changed', self.update_preview)
        table.attach(self.horizontal,
                     1,
                     2,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        label = Gtk.Label(_('Vertical position') + ':')
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.vertical = Gtk.ComboBox.new_with_model_and_entry(vertical_options)
        self.vertical.set_entry_text_column(0)
        self.vertical.set_active(0)
        self.vertical.connect('changed', self.update_preview)
        table.attach(self.vertical,
                     1,
                     2,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Watermark zoom') + ':')
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     5,
                     6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.watermark_zoom = Gtk.SpinButton()
        self.watermark_zoom.connect('value-changed', self.update_preview)
        self.watermark_zoom.set_adjustment(
            Gtk.Adjustment(100, 0, 110, 1, 10, 10))
        table.attach(self.watermark_zoom,
                     1,
                     2,
                     5,
                     6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Set horizontal margin') + ':')
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     6,
                     7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin = Gtk.SpinButton()
        self.horizontal_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.horizontal_margin,
                     1,
                     2,
                     6,
                     7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin.connect('value-changed', self.update_preview)
        label = Gtk.Label(_('Set vertical margin') + ':')
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     7,
                     8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin = Gtk.SpinButton()
        self.vertical_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.vertical_margin,
                     1,
                     2,
                     7,
                     8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin.connect('value-changed', self.update_preview)
        self.show_all()
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))

    def on_value_changed(self, widget):
        self.update_preview()

    def get_watermark_zoom(self):
        return self.watermark_zoom.get_value()

    def get_horizontal_margin(self):
        return self.horizontal_margin.get_value()

    def get_vertical_margin(self):
        return self.vertical_margin.get_value()

    def get_image_filename(self):
        return self.entry.get_text()

    def get_horizontal_option(self):
        tree_iter = self.horizontal.get_active_iter()
        if tree_iter is not None:
            model = self.horizontal.get_model()
            return model[tree_iter][1]
        return 0

    def get_vertical_option(self):
        tree_iter = self.vertical.get_active_iter()
        if tree_iter is not None:
            model = self.vertical.get_model()
            return model[tree_iter][1]
        return 0

    def update_preview_cb(self, file_chooser, preview):
        filename = file_chooser.get_preview_filename()
        try:
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, 128, 128)
            preview.set_from_pixbuf(pixbuf)
            have_preview = True
        except:
            have_preview = False
        file_chooser.set_preview_widget_active(have_preview)
        return

    def on_button_clicked(self, button):
        dialog = Gtk.FileChooserDialog(
            _('Select one image'), self, Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
             Gtk.ResponseType.OK))
        dialog.set_default_response(Gtk.ResponseType.OK)
        dialog.set_select_multiple(False)
        dialog.set_current_folder(os.getenv('HOME'))
        for aMimetype in MIMETYPES_IMAGE.keys():
            filter = Gtk.FileFilter()
            filter.set_name(aMimetype)
            for mime_type in MIMETYPES_IMAGE[aMimetype]['mimetypes']:
                filter.add_mime_type(mime_type)
            for pattern in MIMETYPES_IMAGE[aMimetype]['patterns']:
                filter.add_pattern(pattern)
            dialog.add_filter(filter)
        preview = Gtk.Image()
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.entry.set_text(dialog.get_filename())
        dialog.destroy()
        ####
        file_watermark = self.entry.get_text()
        im = Image.open(file_watermark)
        width, height = im.size
        self.update_preview()

    def update_preview(self, widget=None):
        file_watermark = self.entry.get_text()
        if file_watermark and os.path.exists(file_watermark):
            self.viewport2.set_image(file_watermark)
            self.viewport2.image_zoom = float(self.watermark_zoom.get_value() /
                                              100.0)
            self.viewport2.set_image_position_vertical(
                self.get_vertical_option())
            self.viewport2.set_image_position_horizontal(
                self.get_horizontal_option())
            self.viewport2.image_margin_width =\
                self.horizontal_margin.get_value()
            self.viewport2.image_margin_height =\
                self.vertical_margin.get_value()
            self.viewport2.refresh()

    def close_application(self, widget):
        self.hide()
Ejemplo n.º 7
0
class BaseDialog(BasicDialog):
    def __init__(self, title='', filename=None, window=None):
        self.filename = filename
        self.no_page = None
        BasicDialog.__init__(self, title, window)
        self.set_default_size(600, 600)

    def init_ui(self):
        BasicDialog.init_ui(self)

        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(630, 630)
        self.grid.attach(self.scrolledwindow1, 0, 0, 1, 1)

        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)

        self.pages = {}

        self.scale = 100

        self.init_headerbar()

        if self.filename is not None:
            uri = "file://" + self.filename
            self.document = Poppler.Document.new_from_file(uri, None)
            self.hb.set_subtitle(os.path.basename(self.filename))
            self.set_page(0)

        self.show_all()

    def set_page(self, page):
        if self.document.get_n_pages() > 0 and \
                page < self.document.get_n_pages() and\
                page >= 0:
            self.no_page = page
            self.show_page.set_text(str(self.no_page + 1))
            self.show_title_page.set_text(str(self.no_page + 1))
            self.viewport1.set_page(self.document.get_page(self.no_page),
                                    PageOptions())

    def next_page(self, *_):
        self.set_page(self.no_page + 1)

    def previous_page(self, *_):
        self.set_page(self.no_page - 1)

    def first_page(self, *_):
        self.set_page(0)

    def last_page(self, *_):
        self.set_page(self.document.get_n_pages() - 1)

    def init_headerbar(self):
        self.hb = Gtk.HeaderBar()
        self.hb.set_show_close_button(True)
        self.hb.set_title(self.get_title())
        self.set_titlebar(self.hb)

        button0 = generate_button('go-first-symbolic', _('First page'),
                                  self.first_page)
        self.hb.pack_start(button0)
        button1 = generate_button('go-previous-symbolic', _('Previous page'),
                                  self.previous_page)
        self.hb.pack_start(button1)

        self.show_title_page = Gtk.Entry()
        self.show_title_page.set_width_chars(5)
        self.show_title_page.set_alignment(0.5)
        self.show_title_page.set_tooltip_text(_('Current_page'))
        self.show_title_page.connect('activate', self.on_current_page_activate)
        self.hb.pack_start(self.show_title_page)

        button2 = generate_button('go-next-symbolic', _('Next page'),
                                  self.next_page)
        self.hb.pack_start(button2)

        button3 = generate_button('go-last-symbolic', _('Last page'),
                                  self.last_page)
        self.hb.pack_start(button3)

        popover = self.create_popover()
        button4 = Gtk.MenuButton()
        button4.set_size_request(40, 40)
        button4.set_tooltip_text(_('Options'))
        button4.set_popover(popover)
        button4.set_image(
            Gtk.Image.new_from_gicon(Gio.ThemedIcon(name='pan-down-symbolic'),
                                     Gtk.IconSize.BUTTON))
        self.hb.pack_end(button4)

    def create_popover(self):
        popover = Gtk.Popover()
        self.popover_listbox = Gtk.ListBox()
        self.popover_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
        self.popover_listbox.set_margin_start(10)
        self.popover_listbox.set_margin_end(10)
        self.popover_listbox.set_margin_top(10)
        self.popover_listbox.set_margin_bottom(10)
        popover.add(self.popover_listbox)

        row = Gtk.ListBoxRow()
        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
        row.add(hbox)
        self.popover_listbox.add(row)

        button0 = generate_button('go-first-symbolic', _('First page'),
                                  self.first_page)
        hbox.pack_start(button0, True, True, 0)

        button1 = generate_button('go-previous-symbolic', _('Previous page'),
                                  self.previous_page)
        hbox.pack_start(button1, True, True, 0)

        self.show_page = Gtk.Entry()
        self.show_page.set_alignment(0.5)
        self.show_page.set_tooltip_text(_('Current_page'))
        self.show_page.connect('activate', self.on_current_page_activate)
        hbox.pack_start(self.show_page, True, True, 0)

        button2 = generate_button('go-next-symbolic', _('Next page'),
                                  self.next_page)
        hbox.pack_start(button2, True, True, 0)

        button3 = generate_button('go-last-symbolic', _('Last page'),
                                  self.last_page)
        hbox.pack_start(button3, True, True, 0)
        self.popover_listbox.add(generate_separator_row())

        self.init_adicional_popover()

        popover.show_all()
        popover.hide()
        return popover

    def init_adicional_popover(self):
        pass

    def on_current_page_activate(self, widget):
        page = str2int(widget.get_text()) - 1
        if page > -1 and page < self.document.get_n_pages():
            self.set_page(page)
        else:
            self.show_page.set_text(str(self.no_page + 1))
            self.show_title_page.set_text(str(self.no_page + 1))

    def get_options_for_pages(self):
        return self.pages
Ejemplo n.º 8
0
    def __init__(self, title, filename=None):
        Gtk.Dialog.__init__(
            self, title, None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
             Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.set_default_size(800, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=3, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 1, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2, 1, 2, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        #
        self.scale = 100

        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0, 0, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip vertical'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch1 = Gtk.Switch()
        self.switch1.set_name('switch1')
        self.switch1.connect("notify::active", self.slider_on_value_changed)
        hbox1 = Gtk.HBox()
        hbox1.pack_start(self.switch1, 0, 0, 0)
        table.attach(hbox1, 1, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip horizontal'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch2 = Gtk.Switch()
        self.switch2.set_name('switch2')
        self.switch2.connect("notify::active", self.slider_on_value_changed)
        hbox2 = Gtk.HBox()
        hbox2.pack_start(self.switch2, 0, 0, 0)
        table.attach(hbox2, 1, 2, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Rotate'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        table1 = Gtk.Table(rows=1, columns=4, homogeneous=False)
        table1.set_border_width(5)
        table1.set_col_spacings(5)
        table1.set_row_spacings(5)
        table.attach(table1, 1, 2, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton1 = Gtk.RadioButton.new_with_label_from_widget(None, '0')
        self.rbutton1.set_name('0')
        self.rbutton1.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton1, 0, 1, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton2 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '90')
        self.rbutton2.set_name('90')
        self.rbutton2.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton2, 1, 2, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton3 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '180')
        self.rbutton3.set_name('180')
        self.rbutton3.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton3, 2, 3, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton4 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '270')
        self.rbutton4.set_name('270')
        self.rbutton4.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton4, 3, 4, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        #
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))
        #
        print(1)
        self.show_all()
Ejemplo n.º 9
0
class PaginateDialog(Gtk.Dialog):
    def __init__(self, filename=None):
        Gtk.Dialog.__init__(
            self, _('Paginate'), None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
             Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.set_size_request(500, 140)
        self.set_resizable(False)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close_application)
        #
        vbox0 = Gtk.VBox(spacing=5)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        #
        notebook = Gtk.Notebook()
        vbox0.add(notebook)
        #
        frame = Gtk.Frame()
        notebook.append_page(frame, tab_label=Gtk.Label(_('Paginate')))
        #
        table = Gtk.Table(rows=4, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 1, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2, 1, 2, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        self.viewport2.set_text('1/1')
        #
        self.scale = 100

        #
        vertical_options = Gtk.ListStore(str, int)
        vertical_options.append([_('Top'), TOP])
        vertical_options.append([_('Middle'), MIDLE])
        vertical_options.append([_('Bottom'), BOTTOM])
        #
        horizontal_options = Gtk.ListStore(str, int)
        horizontal_options.append([_('Left'), LEFT])
        horizontal_options.append([_('Center'), CENTER])
        horizontal_options.append([_('Right'), RIGHT])
        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0, 0, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        # Font 2 3
        vbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        table.attach(vbox1, 0, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        button_font = Gtk.Button(_('Select font'))
        button_font.connect('clicked', self.on_button_font_activated)
        vbox1.pack_start(button_font, False, False, 0)
        button_color = Gtk.Button(_('Select color'))
        button_color.connect('clicked', self.on_button_color_activated)
        vbox1.pack_start(button_color, False, False, 0)
        #
        label = Gtk.Label(_('Horizontal position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.horizontal = Gtk.ComboBox.new_with_model_and_entry(
            horizontal_options)
        self.horizontal.set_entry_text_column(0)
        self.horizontal.set_active(0)
        self.horizontal.connect('changed', self.on_value_changed)
        table.attach(self.horizontal, 1, 2, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Vertical position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.vertical = Gtk.ComboBox.new_with_model_and_entry(vertical_options)
        self.vertical.set_entry_text_column(0)
        self.vertical.set_active(0)
        self.vertical.connect('changed', self.on_value_changed)
        table.attach(self.vertical, 1, 2, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Set horizontal margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin = Gtk.SpinButton()
        self.horizontal_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.horizontal_margin, 1, 2, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin.connect('value-changed',
                                       self.on_margin_changed)
        label = Gtk.Label(_('Set vertical margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin = Gtk.SpinButton()
        self.vertical_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.vertical_margin, 1, 2, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin.connect('value-changed',
                                     self.on_margin_changed)

        self.show_all()
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))

    def on_margin_changed(self, widget):
        self.viewport2.text_margin_width = self.horizontal_margin.get_value()
        self.viewport2.text_margin_height = self.vertical_margin.get_value()
        self.update_preview()

    def on_button_color_activated(self, widget):
        dialog = Gtk.ColorSelectionDialog(
            title=_('Select color'),
            flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
        dialog.get_color_selection().set_current_color(
            Gdk.Color(self.viewport2.color[0]*65535,
                      self.viewport2.color[1]*65535,
                      self.viewport2.color[2]*65535))
        dialog.get_color_selection().set_current_alpha(
            self.viewport2.color[3]*65535)
        response = dialog.run()
        print(response)
        if response == -5:
            color1 = dialog.get_color_selection().get_current_color()
            color2 = dialog.get_color_selection().get_current_alpha()
            self.viewport2.color = [color1.red/65535.0,
                                    color1.green/65535.0,
                                    color1.blue/65535.0,
                                    color2/65535.0]
            print(self.viewport2.color)
            self.update_preview()
        dialog.destroy()

    def on_button_font_activated(self, widget):
        dialog = Gtk.FontSelectionDialog(
            title=_('Select font'),
            flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
        print(self.viewport2.font+' '+str(int(self.viewport2.size)))
        dialog.set_font_name(
            self.viewport2.font+' '+str(int(self.viewport2.size)))
        answer = dialog.run()
        if answer == -5:
            fs = dialog.get_font_selection()
            self.viewport2.font = ' '.join(fs.get_font_name().split()[:-1])
            self.viewport2.size = float(fs.get_font_name().split()[-1])
            self.update_preview()
        dialog.destroy()

    def get_horizontal_margin(self):
        return self.horizontal_margin.get_value()

    def get_vertical_margin(self):
        return self.vertical_margin.get_value()

    def get_color(self):
        return self.viewport2.color

    def get_font(self):
        return self.viewport2.font

    def get_size(self):
        return self.viewport2.size

    def on_value_changed(self, widget):
        self.update_preview()

    def get_image_filename(self):
        return self.entry.get_text()

    def get_horizontal_option(self):
        tree_iter = self.horizontal.get_active_iter()
        if tree_iter is not None:
            model = self.horizontal.get_model()
            return model[tree_iter][1]
        return 0

    def get_vertical_option(self):
        tree_iter = self.vertical.get_active_iter()
        if tree_iter is not None:
            model = self.vertical.get_model()
            return model[tree_iter][1]
        return 0

    def update_preview(self):
        self.viewport2.set_image_position_vertical(
            self.get_vertical_option())
        self.viewport2.set_image_position_horizontal(
            self.get_horizontal_option())
        self.viewport2.refresh()

    def close_application(self, widget):
        self.hide()
Ejemplo n.º 10
0
class TextmarkDialog(Gtk.Dialog):
    def __init__(self, filename=None):
        Gtk.Dialog.__init__(
            self,
            _('Textmark'),
            None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
             Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.set_size_request(500, 140)
        self.set_resizable(False)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close_application)
        vbox0 = Gtk.VBox(spacing=5)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        notebook = Gtk.Notebook()
        vbox0.add(notebook)
        frame = Gtk.Frame()
        notebook.append_page(frame, tab_label=Gtk.Label(_('Textmark')))
        #
        table = Gtk.Table(rows=4, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 1, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        frame1.add(self.scrolledwindow1)
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        frame2 = Gtk.Frame()
        table.attach(frame2, 1, 2, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        frame2.add(scrolledwindow2)
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        self.scale = 100
        vertical_options = Gtk.ListStore(str, int)
        vertical_options.append([_('Top'), TOP])
        vertical_options.append([_('Middle'), MIDLE])
        vertical_options.append([_('Bottom'), BOTTOM])
        horizontal_options = Gtk.ListStore(str, int)
        horizontal_options.append([_('Left'), LEFT])
        horizontal_options.append([_('Center'), CENTER])
        horizontal_options.append([_('Right'), RIGHT])
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0, 0, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        vbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        table.attach(vbox1, 0, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        button_font = Gtk.Button(_('Select Font'))
        button_font.connect('clicked', self.on_button_font_activated)
        vbox1.pack_start(button_font, False, False, 0)
        button_color = Gtk.Button(_('Select color'))
        button_color.connect('clicked', self.on_button_color_activated)
        vbox1.pack_start(button_color, False, False, 0)
        vbox3 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        table.attach(vbox3, 0, 2, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        label = Gtk.Label(_('Text')+':')
        vbox3.pack_start(label, False, False, 0)
        self.entry = Gtk.Entry()
        self.entry.set_width_chars(50)
        self.entry.connect('changed', self.on_entry_changed)
        vbox3.pack_start(self.entry, True, True, 0)
        label = Gtk.Label(_('Horizontal position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal = Gtk.ComboBox.new_with_model_and_entry(
            horizontal_options)
        self.horizontal.set_entry_text_column(0)
        self.horizontal.set_active(0)
        self.horizontal.connect('changed', self.on_value_changed)
        table.attach(self.horizontal, 1, 2, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        label = Gtk.Label(_('Vertical position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.vertical = Gtk.ComboBox.new_with_model_and_entry(vertical_options)
        self.vertical.set_entry_text_column(0)
        self.vertical.set_active(0)
        self.vertical.connect('changed', self.on_value_changed)
        table.attach(self.vertical, 1, 2, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        label = Gtk.Label(_('Set horizontal margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin = Gtk.SpinButton()
        self.horizontal_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.horizontal_margin, 1, 2, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin.connect('value-changed',
                                       self.on_margin_changed)
        label = Gtk.Label(_('Set vertical margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin = Gtk.SpinButton()
        self.vertical_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.vertical_margin, 1, 2, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin.connect('value-changed',
                                     self.on_margin_changed)
        self.show_all()
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))

    def on_margin_changed(self, widget):
        self.viewport2.text_margin_width = self.horizontal_margin.get_value()
        self.viewport2.text_margin_height = self.vertical_margin.get_value()
        self.update_preview()

    def on_button_color_activated(self, widget):
        dialog = Gtk.ColorSelectionDialog(
            title=_('Select color'),
            flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
        dialog.get_color_selection().set_current_color(
            Gdk.Color(self.viewport2.color[0]*65535,
                      self.viewport2.color[1]*65535,
                      self.viewport2.color[2]*65535))
        dialog.get_color_selection().set_current_alpha(
            self.viewport2.color[3]*65535)
        response = dialog.run()
        print(response)
        if response == -5:
            color1 = dialog.get_color_selection().get_current_color()
            color2 = dialog.get_color_selection().get_current_alpha()
            self.viewport2.color = [color1.red/65535.0,
                                    color1.green/65535.0,
                                    color1.blue/65535.0,
                                    color2/65535.0]
            print(self.viewport2.color)
            self.update_preview()
        dialog.destroy()

    def on_button_font_activated(self, widget):
        dialog = Gtk.FontSelectionDialog(
            title=_('Select font'),
            flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
        print(self.viewport2.font+' '+str(int(self.viewport2.size)))
        dialog.set_font_name(
            self.viewport2.font+' '+str(int(self.viewport2.size)))
        answer = dialog.run()
        if answer == -5:
            fs = dialog.get_font_selection()
            self.viewport2.font = ' '.join(fs.get_font_name().split()[:-1])
            self.viewport2.size = float(fs.get_font_name().split()[-1])
            self.update_preview()
        dialog.destroy()

    def get_horizontal_margin(self):
        return self.horizontal_margin.get_value()

    def get_vertical_margin(self):
        return self.vertical_margin.get_value()

    def get_color(self):
        return self.viewport2.color

    def get_font(self):
        return self.viewport2.font

    def get_size(self):
        return self.viewport2.size

    def get_text(self):
        return self.entry.get_text()

    def on_value_changed(self, widget):
        self.update_preview()

    def get_image_filename(self):
        return self.entry.get_text()

    def get_horizontal_option(self):
        tree_iter = self.horizontal.get_active_iter()
        if tree_iter is not None:
            model = self.horizontal.get_model()
            return model[tree_iter][1]
        return 0

    def get_vertical_option(self):
        tree_iter = self.vertical.get_active_iter()
        if tree_iter is not None:
            model = self.vertical.get_model()
            return model[tree_iter][1]
        return 0

    def on_entry_changed(self, widget):
        self.update_preview()

    def update_preview(self):
        text = self.entry.get_text()
        if len(text) > 0:
            self.viewport2.set_text(self.entry.get_text())
            self.viewport2.set_image_position_vertical(
                self.get_vertical_option())
            self.viewport2.set_image_position_horizontal(
                self.get_horizontal_option())
            self.viewport2.refresh()

    def close_application(self, widget):
        self.hide()
Ejemplo n.º 11
0
 def __init__(self, title, filenames=[]):
     Gtk.Dialog.__init__(
         self, title, None,
         Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
         (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
          Gtk.ResponseType.CANCEL))
     self.set_default_size(400, 400)
     self.set_resizable(True)
     self.set_icon_from_file(comun.ICON)
     self.connect('destroy', self.close)
     #
     vbox = Gtk.VBox(spacing=5)
     vbox.set_border_width(5)
     self.get_content_area().add(vbox)
     #
     frame = Gtk.Frame()
     vbox.pack_start(frame, True, True, 0)
     #
     table = Gtk.Table(rows=2, columns=2, homogeneous=False)
     table.set_border_width(5)
     table.set_col_spacings(5)
     table.set_row_spacings(5)
     frame.add(table)
     #
     frame1 = Gtk.Frame()
     table.attach(frame1,
                  0,
                  2,
                  0,
                  1,
                  xoptions=Gtk.AttachOptions.EXPAND,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.scrolledwindow1 = Gtk.ScrolledWindow()
     self.scrolledwindow1.set_size_request(400, 400)
     self.connect('key-release-event', self.on_key_release_event)
     frame1.add(self.scrolledwindow1)
     #
     self.viewport1 = MiniView()
     self.scrolledwindow1.add(self.viewport1)
     #
     self.scale = 100
     #
     #
     label = Gtk.Label(_('Images per page'))
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  1,
                  2,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str, int)
     listStore.append(['1', 1])
     listStore.append(['2', 2])
     listStore.append(['4', 4])
     listStore.append(['6', 6])
     listStore.append(['8', 8])
     self.images_per_page = Gtk.ComboBox()
     self.images_per_page.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.images_per_page.pack_start(cell1, True)
     self.images_per_page.add_attribute(cell1, 'text', 0)
     table.attach(self.images_per_page,
                  1,
                  2,
                  1,
                  2,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     select_value_in_combo(self.images_per_page, 1)
     self.images_per_page.connect('changed',
                                  self.on_images_per_page_changed)
     label = Gtk.Label(_('Orientation'))
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  2,
                  3,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str, int)
     listStore.append([_('Portrait'), PORTRAIT])
     listStore.append([_('Landscape'), LANDSCAPE])
     self.orientations = Gtk.ComboBox()
     self.orientations.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.orientations.pack_start(cell1, True)
     self.orientations.add_attribute(cell1, 'text', 0)
     table.attach(self.orientations,
                  1,
                  2,
                  2,
                  3,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.orientations.connect('changed', self.on_orientation_changed)
     select_value_in_combo(self.orientations, PORTRAIT)
     label = Gtk.Label(_('Printer'))
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  3,
                  4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     for aprinter in list_printers():
         listStore.append([aprinter])
     self.printers = Gtk.ComboBox()
     self.printers.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.printers.pack_start(cell1, True)
     self.printers.add_attribute(cell1, 'text', 0)
     table.attach(self.printers,
                  1,
                  2,
                  3,
                  4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.printers.connect('changed', self.on_printer_changed)
     label = Gtk.Label(_('Paper size'))
     label.set_alignment(0, 0.5)
     table.attach(label,
                  0,
                  1,
                  4,
                  5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     self.papersizes = Gtk.ComboBox()
     self.papersizes.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.papersizes.pack_start(cell1, True)
     self.papersizes.add_attribute(cell1, 'text', 0)
     table.attach(self.papersizes,
                  1,
                  2,
                  4,
                  5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.papersizes.connect('changed', self.on_papersize_changed)
     '''
     label = Gtk.Label(_('Resolution'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 5, 6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     self.resolutions = Gtk.ComboBox()
     self.resolutions.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.resolutions.pack_start(cell1, True)
     self.resolutions.add_attribute(cell1, 'text', 0)
     table.attach(self.resolutions, 1, 2, 5, 6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     '''
     #
     self.filenames = filenames
     select_index_in_combo(self.printers, 0)
     #
     if len(self.filenames) == 0:
         self.images_per_page.set_sensitive(False)
     elif len(self.filenames) == 1:
         select_value_in_combo(self.images_per_page, 1)
         self.images_per_page.set_sensitive(False)
     #
     self.draw_images()
     self.show_all()
Ejemplo n.º 12
0
class PrintDialog(Gtk.Dialog):
    def __init__(self, title, filenames=[]):
        Gtk.Dialog.__init__(
            self, title, None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
             Gtk.ResponseType.CANCEL))
        self.set_default_size(400, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1,
                     0,
                     2,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(400, 400)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        self.scale = 100
        #
        #
        label = Gtk.Label(_('Images per page'))
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str, int)
        listStore.append(['1', 1])
        listStore.append(['2', 2])
        listStore.append(['4', 4])
        listStore.append(['6', 6])
        listStore.append(['8', 8])
        self.images_per_page = Gtk.ComboBox()
        self.images_per_page.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.images_per_page.pack_start(cell1, True)
        self.images_per_page.add_attribute(cell1, 'text', 0)
        table.attach(self.images_per_page,
                     1,
                     2,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        select_value_in_combo(self.images_per_page, 1)
        self.images_per_page.connect('changed',
                                     self.on_images_per_page_changed)
        label = Gtk.Label(_('Orientation'))
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str, int)
        listStore.append([_('Portrait'), PORTRAIT])
        listStore.append([_('Landscape'), LANDSCAPE])
        self.orientations = Gtk.ComboBox()
        self.orientations.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.orientations.pack_start(cell1, True)
        self.orientations.add_attribute(cell1, 'text', 0)
        table.attach(self.orientations,
                     1,
                     2,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.orientations.connect('changed', self.on_orientation_changed)
        select_value_in_combo(self.orientations, PORTRAIT)
        label = Gtk.Label(_('Printer'))
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        for aprinter in list_printers():
            listStore.append([aprinter])
        self.printers = Gtk.ComboBox()
        self.printers.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.printers.pack_start(cell1, True)
        self.printers.add_attribute(cell1, 'text', 0)
        table.attach(self.printers,
                     1,
                     2,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.printers.connect('changed', self.on_printer_changed)
        label = Gtk.Label(_('Paper size'))
        label.set_alignment(0, 0.5)
        table.attach(label,
                     0,
                     1,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        self.papersizes = Gtk.ComboBox()
        self.papersizes.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.papersizes.pack_start(cell1, True)
        self.papersizes.add_attribute(cell1, 'text', 0)
        table.attach(self.papersizes,
                     1,
                     2,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.papersizes.connect('changed', self.on_papersize_changed)
        '''
        label = Gtk.Label(_('Resolution'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        self.resolutions = Gtk.ComboBox()
        self.resolutions.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.resolutions.pack_start(cell1, True)
        self.resolutions.add_attribute(cell1, 'text', 0)
        table.attach(self.resolutions, 1, 2, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        '''
        #
        self.filenames = filenames
        select_index_in_combo(self.printers, 0)
        #
        if len(self.filenames) == 0:
            self.images_per_page.set_sensitive(False)
        elif len(self.filenames) == 1:
            select_value_in_combo(self.images_per_page, 1)
            self.images_per_page.set_sensitive(False)
        #
        self.draw_images()
        self.show_all()

    def draw_images(self):
        if self.filenames > 0:
            self.viewport1.set_images(self.filenames)

    def on_images_per_page_changed(self, widget):
        images_per_page = get_selected_value_in_combo(self.images_per_page, 1)
        print('*************************************************')
        print(images_per_page)
        print('*************************************************')

        self.viewport1.set_images_per_page(images_per_page)

    def on_orientation_changed(self, widget):
        orientation = get_selected_value_in_combo(self.orientations, 1)
        print('*************************************************')
        print(orientation)
        print('*************************************************')
        self.viewport1.set_orientation(orientation)

    def on_papersize_changed(self, widget):
        apapersize = get_selected_value_in_combo(self.papersizes)
        if apapersize == 'A0':
            self.viewport1.set_page(A0)
        elif apapersize == 'A1':
            self.viewport1.set_page(A1)
        elif apapersize == 'A2':
            self.viewport1.set_page(A2)
        elif apapersize == 'A3':
            self.viewport1.set_page(A3)
        elif apapersize == 'A4':
            self.viewport1.set_page(A4)
        elif apapersize == 'A5':
            self.viewport1.set_page(A5)

    def on_printer_changed(self, widget):
        aprinter = get_selected_value_in_combo(self.printers)
        model = self.papersizes.get_model()
        model.clear()
        for apapersize in list_pagesize(aprinter):
            if apapersize.startswith('*'):
                apapersize = apapersize[1:]
            if apapersize in ADMISIBLE_PAPER_SIZES:
                model.append([apapersize])
        select_index_in_combo(self.papersizes, 0)
        model = self.resolutions.get_model()
        model.clear()
        for aresolution in list_resolution(aprinter):
            if aresolution.startswith('*'):
                aresolution = aresolution[1:]
            model.append([aresolution])
        select_index_in_combo(self.resolutions, 0)

    def get_images_per_page(self):
        return get_selected_value_in_combo(self.images_per_page, 1)

    def get_printer(self):
        return get_selected_value_in_combo(self.printers)

    def get_orientation(self):
        return get_selected_value_in_combo(self.orientations, 1)

    def get_papersize(self):
        return get_selected_value_in_combo(self.papersizes)

    def pprint(self):
        images_per_page = get_selected_value_in_combo(self.images_per_page, 1)
        aprinter = get_selected_value_in_combo(self.printers)
        orientation = get_selected_value_in_combo(self.orientations, 1)
        apapersize = get_selected_value_in_combo(self.papersizes)
        if apapersize == 'A0':
            width, height = A0.get_size()
        elif apapersize == 'A1':
            width, height = A1.get_size()
        elif apapersize == 'A2':
            width, height = A2.get_size()
        elif apapersize == 'A3':
            width, height = A3.get_size()
        elif apapersize == 'A4':
            width, height = A4.get_size()
        elif apapersize == 'A5':
            width, height = A5.get_size()
        if orientation == PORTRAIT:
            twidth = height
            height = width
            width = twidth
        temp_pdf = create_temp_file()
        pdfsurface = cairo.PDFSurface(temp_pdf, width / 25.4 * 72.0,
                                      height / 25.4 * 72.0)
        context = cairo.Context(pdfsurface)
        if images_per_page == 1 and len(self.filenames) > 0:
            for filename in self.filenames:
                image1 = create_image_surface_from_file(filename)
                w1 = image1.get_width() / MMTOPIXEL
                h1 = image1.get_height() / MMTOPIXEL
                zw = w1 / width
                zh = h1 / height
                if zw > zh:
                    z = zw
                else:
                    z = zh
                print(w1, h1)
                context.save()
                x = abs(w1 / z - width) / 2.0
                y = abs(h1 / z - height) / 2.0
                print(x, y)
                context.translate(x * 2.8343, y * 2.8343)
                context.scale(2.8343 / MMTOPIXEL / z, 2.8343 / MMTOPIXEL / z)
                context.set_source_surface(image1)
                context.paint()
                context.restore()
                context.show_page()
        elif images_per_page == 2 and len(self.filenames) >= 2:
            for contador in range(0, len(self.filenames), 2):
                for i in range(0, 2):
                    if (contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 2.0)
                        zh = h / height
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i) * width / 2.0 +\
                            abs(w / z - width / 2.0) / 2.0
                        y = abs(h / z - height) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 4 and len(self.filenames) >= 4:
            for contador in range(0, len(self.filenames), 4):
                for i in range(0, 4):
                    if (contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 2.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 2) * width / 2.0 +\
                            abs(w / z - width / 2.0) / 2.0
                        y = float(i / 2) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        print(x, y)
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 6 and len(self.filenames) >= 6:
            for contador in range(0, len(self.filenames), 6):
                for i in range(0, 6):
                    if (contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 3.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 3) * width / 3.0 +\
                            abs(w / z - width / 3.0) / 2.0
                        y = float(i / 3) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 8 and len(self.filenames) >= 8:
            for contador in range(0, len(self.filenames), 8):
                for i in range(0, 8):
                    if (contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 4.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 4) * width / 4.0 +\
                            abs(w / z - width / 4.0) / 2.0
                        y = float(i / 4) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        pdfsurface.flush()
        pdfsurface.finish()
        if orientation == LANDSCAPE:
            printcommand = 'lp -d %s\
                            -o media=%s\
                            -o orientation-requested=4 "%s"' % (
                aprinter, apapersize, temp_pdf)
        else:
            printcommand = 'lp -d %s -o media=%s "%s"' % (aprinter, apapersize,
                                                          temp_pdf)
        print(printcommand)
        args = shlex.split(printcommand)
        p = subprocess.Popen(args,
                             bufsize=10000,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        ans = p.communicate()[0]
        if p.returncode == 0:
            print(ans)
        os.remove(temp_pdf)

    def on_key_release_event(self, widget, event):
        print((event.keyval))
        if event.keyval == 65451 or event.keyval == 43:
            self.scale = self.scale * 1.1
        elif event.keyval == 65453 or event.keyval == 45:
            self.scale = self.scale * .9
        elif event.keyval == 65456 or event.keyval == 48:
            pass
            '''
            factor_w = float(
                self.scrolledwindow1.get_allocation().width) /\
                float(self.pixbuf1.get_width())
            factor_h = float(
                self.scrolledwindow1.get_allocation().height) /\
                float(self.pixbuf1.get_height())
            if factor_w < factor_h:
                factor = factor_w
            else:
                factor = factor_h
            self.scale = int(factor * 100)
            w = int(self.pixbuf1.get_width() * factor)
            h = int(self.pixbuf1.get_height() * factor)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
        elif event.keyval == 65457 or event.keyval == 49:
            self.scale = 100
        if self.image1:
            w = int(self.pixbuf1.get_width() * self.scale / 100)
            h = int(self.pixbuf1.get_height() * self.scale / 100)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            '''

    def close(self, widget):
        self.destroy()
Ejemplo n.º 13
0
 def __init__(self, title, filenames=[]):
     Gtk.Dialog.__init__(self,
                         title,
                         None,
                         Gtk.DialogFlags.MODAL |
                         Gtk.DialogFlags.DESTROY_WITH_PARENT,
                         (Gtk.STOCK_OK,
                          Gtk.ResponseType.ACCEPT,
                          Gtk.STOCK_CANCEL,
                          Gtk.ResponseType.CANCEL))
     self.set_default_size(400, 400)
     self.set_resizable(True)
     self.set_icon_from_file(comun.ICON)
     self.connect('destroy', self.close)
     #
     vbox = Gtk.VBox(spacing=5)
     vbox.set_border_width(5)
     self.get_content_area().add(vbox)
     #
     frame = Gtk.Frame()
     vbox.pack_start(frame, True, True, 0)
     #
     table = Gtk.Table(rows=2, columns=2, homogeneous=False)
     table.set_border_width(5)
     table.set_col_spacings(5)
     table.set_row_spacings(5)
     frame.add(table)
     #
     frame1 = Gtk.Frame()
     table.attach(frame1, 0, 2, 0, 1, xoptions=Gtk.AttachOptions.EXPAND,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.scrolledwindow1 = Gtk.ScrolledWindow()
     self.scrolledwindow1.set_size_request(400, 400)
     self.connect('key-release-event', self.on_key_release_event)
     frame1.add(self.scrolledwindow1)
     #
     self.viewport1 = MiniView()
     self.scrolledwindow1.add(self.viewport1)
     #
     self.scale = 100
     #
     #
     label = Gtk.Label(_('Images per page'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 1, 2,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str, int)
     listStore.append(['1', 1])
     listStore.append(['2', 2])
     listStore.append(['4', 4])
     listStore.append(['6', 6])
     listStore.append(['8', 8])
     self.images_per_page = Gtk.ComboBox()
     self.images_per_page.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.images_per_page.pack_start(cell1, True)
     self.images_per_page.add_attribute(cell1, 'text', 0)
     table.attach(self.images_per_page, 1, 2, 1, 2,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     select_value_in_combo(self.images_per_page, 1)
     self.images_per_page.connect('changed',
                                  self.on_images_per_page_changed)
     label = Gtk.Label(_('Orientation'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 2, 3,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str, int)
     listStore.append([_('Portrait'), PORTRAIT])
     listStore.append([_('Landscape'), LANDSCAPE])
     self.orientations = Gtk.ComboBox()
     self.orientations.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.orientations.pack_start(cell1, True)
     self.orientations.add_attribute(cell1, 'text', 0)
     table.attach(self.orientations, 1, 2, 2, 3,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.orientations.connect('changed', self.on_orientation_changed)
     select_value_in_combo(self.orientations, PORTRAIT)
     label = Gtk.Label(_('Printer'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 3, 4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     for aprinter in list_printers():
         listStore.append([aprinter])
     self.printers = Gtk.ComboBox()
     self.printers.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.printers.pack_start(cell1, True)
     self.printers.add_attribute(cell1, 'text', 0)
     table.attach(self.printers, 1, 2, 3, 4,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.printers.connect('changed', self.on_printer_changed)
     label = Gtk.Label(_('Paper size'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 4, 5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     self.papersizes = Gtk.ComboBox()
     self.papersizes.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.papersizes.pack_start(cell1, True)
     self.papersizes.add_attribute(cell1, 'text', 0)
     table.attach(self.papersizes, 1, 2, 4, 5,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     self.papersizes.connect('changed', self.on_papersize_changed)
     '''
     label = Gtk.Label(_('Resolution'))
     label.set_alignment(0, 0.5)
     table.attach(label, 0, 1, 5, 6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     listStore = Gtk.ListStore(str)
     self.resolutions = Gtk.ComboBox()
     self.resolutions.set_model(listStore)
     cell1 = Gtk.CellRendererText()
     self.resolutions.pack_start(cell1, True)
     self.resolutions.add_attribute(cell1, 'text', 0)
     table.attach(self.resolutions, 1, 2, 5, 6,
                  xoptions=Gtk.AttachOptions.FILL,
                  yoptions=Gtk.AttachOptions.SHRINK)
     '''
     #
     self.filenames = filenames
     select_index_in_combo(self.printers, 0)
     #
     if len(self.filenames) == 0:
         self.images_per_page.set_sensitive(False)
     elif len(self.filenames) == 1:
         select_value_in_combo(self.images_per_page, 1)
         self.images_per_page.set_sensitive(False)
     #
     self.draw_images()
     self.show_all()
Ejemplo n.º 14
0
class PrintDialog(Gtk.Dialog):
    def __init__(self, title, filenames=[]):
        Gtk.Dialog.__init__(self,
                            title,
                            None,
                            Gtk.DialogFlags.MODAL |
                            Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            (Gtk.STOCK_OK,
                             Gtk.ResponseType.ACCEPT,
                             Gtk.STOCK_CANCEL,
                             Gtk.ResponseType.CANCEL))
        self.set_default_size(400, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 2, 0, 1, xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(400, 400)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        self.scale = 100
        #
        #
        label = Gtk.Label(_('Images per page'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str, int)
        listStore.append(['1', 1])
        listStore.append(['2', 2])
        listStore.append(['4', 4])
        listStore.append(['6', 6])
        listStore.append(['8', 8])
        self.images_per_page = Gtk.ComboBox()
        self.images_per_page.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.images_per_page.pack_start(cell1, True)
        self.images_per_page.add_attribute(cell1, 'text', 0)
        table.attach(self.images_per_page, 1, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        select_value_in_combo(self.images_per_page, 1)
        self.images_per_page.connect('changed',
                                     self.on_images_per_page_changed)
        label = Gtk.Label(_('Orientation'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str, int)
        listStore.append([_('Portrait'), PORTRAIT])
        listStore.append([_('Landscape'), LANDSCAPE])
        self.orientations = Gtk.ComboBox()
        self.orientations.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.orientations.pack_start(cell1, True)
        self.orientations.add_attribute(cell1, 'text', 0)
        table.attach(self.orientations, 1, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.orientations.connect('changed', self.on_orientation_changed)
        select_value_in_combo(self.orientations, PORTRAIT)
        label = Gtk.Label(_('Printer'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        for aprinter in list_printers():
            listStore.append([aprinter])
        self.printers = Gtk.ComboBox()
        self.printers.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.printers.pack_start(cell1, True)
        self.printers.add_attribute(cell1, 'text', 0)
        table.attach(self.printers, 1, 2, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.printers.connect('changed', self.on_printer_changed)
        label = Gtk.Label(_('Paper size'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        self.papersizes = Gtk.ComboBox()
        self.papersizes.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.papersizes.pack_start(cell1, True)
        self.papersizes.add_attribute(cell1, 'text', 0)
        table.attach(self.papersizes, 1, 2, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.papersizes.connect('changed', self.on_papersize_changed)
        '''
        label = Gtk.Label(_('Resolution'))
        label.set_alignment(0, 0.5)
        table.attach(label, 0, 1, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        listStore = Gtk.ListStore(str)
        self.resolutions = Gtk.ComboBox()
        self.resolutions.set_model(listStore)
        cell1 = Gtk.CellRendererText()
        self.resolutions.pack_start(cell1, True)
        self.resolutions.add_attribute(cell1, 'text', 0)
        table.attach(self.resolutions, 1, 2, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        '''
        #
        self.filenames = filenames
        select_index_in_combo(self.printers, 0)
        #
        if len(self.filenames) == 0:
            self.images_per_page.set_sensitive(False)
        elif len(self.filenames) == 1:
            select_value_in_combo(self.images_per_page, 1)
            self.images_per_page.set_sensitive(False)
        #
        self.draw_images()
        self.show_all()

    def draw_images(self):
        if self.filenames > 0:
            self.viewport1.set_images(self.filenames)

    def on_images_per_page_changed(self, widget):
        images_per_page = get_selected_value_in_combo(self.images_per_page, 1)
        print('*************************************************')
        print(images_per_page)
        print('*************************************************')

        self.viewport1.set_images_per_page(images_per_page)

    def on_orientation_changed(self, widget):
        orientation = get_selected_value_in_combo(self.orientations, 1)
        print('*************************************************')
        print(orientation)
        print('*************************************************')
        self.viewport1.set_orientation(orientation)

    def on_papersize_changed(self, widget):
        apapersize = get_selected_value_in_combo(self.papersizes)
        if apapersize == 'A0':
            self.viewport1.set_page(A0)
        elif apapersize == 'A1':
            self.viewport1.set_page(A1)
        elif apapersize == 'A2':
            self.viewport1.set_page(A2)
        elif apapersize == 'A3':
            self.viewport1.set_page(A3)
        elif apapersize == 'A4':
            self.viewport1.set_page(A4)
        elif apapersize == 'A5':
            self.viewport1.set_page(A5)

    def on_printer_changed(self, widget):
        aprinter = get_selected_value_in_combo(self.printers)
        model = self.papersizes.get_model()
        model.clear()
        for apapersize in list_pagesize(aprinter):
            if apapersize.startswith('*'):
                apapersize = apapersize[1:]
            if apapersize in ADMISIBLE_PAPER_SIZES:
                model.append([apapersize])
        select_index_in_combo(self.papersizes, 0)
        model = self.resolutions.get_model()
        model.clear()
        for aresolution in list_resolution(aprinter):
            if aresolution.startswith('*'):
                aresolution = aresolution[1:]
            model.append([aresolution])
        select_index_in_combo(self.resolutions, 0)

    def get_images_per_page(self):
        return get_selected_value_in_combo(self.images_per_page, 1)

    def get_printer(self):
        return get_selected_value_in_combo(self.printers)

    def get_orientation(self):
        return get_selected_value_in_combo(self.orientations, 1)

    def get_papersize(self):
        return get_selected_value_in_combo(self.papersizes)

    def pprint(self):
        images_per_page = get_selected_value_in_combo(self.images_per_page, 1)
        aprinter = get_selected_value_in_combo(self.printers)
        orientation = get_selected_value_in_combo(self.orientations, 1)
        apapersize = get_selected_value_in_combo(self.papersizes)
        if apapersize == 'A0':
            width, height = A0.get_size()
        elif apapersize == 'A1':
            width, height = A1.get_size()
        elif apapersize == 'A2':
            width, height = A2.get_size()
        elif apapersize == 'A3':
            width, height = A3.get_size()
        elif apapersize == 'A4':
            width, height = A4.get_size()
        elif apapersize == 'A5':
            width, height = A5.get_size()
        if orientation == PORTRAIT:
            twidth = height
            height = width
            width = twidth
        temp_pdf = create_temp_file()
        pdfsurface = cairo.PDFSurface(temp_pdf,
                                      width / 25.4 * 72.0,
                                      height / 25.4 * 72.0)
        context = cairo.Context(pdfsurface)
        if images_per_page == 1 and len(self.filenames) > 0:
            for filename in self. filenames:
                image1 = create_image_surface_from_file(filename)
                w1 = image1.get_width() / MMTOPIXEL
                h1 = image1.get_height() / MMTOPIXEL
                zw = w1 / width
                zh = h1 / height
                if zw > zh:
                    z = zw
                else:
                    z = zh
                print(w1, h1)
                context.save()
                x = abs(w1 / z - width) / 2.0
                y = abs(h1 / z - height) / 2.0
                print(x, y)
                context.translate(x * 2.8343, y * 2.8343)
                context.scale(2.8343 / MMTOPIXEL / z, 2.8343 / MMTOPIXEL / z)
                context.set_source_surface(image1)
                context.paint()
                context.restore()
                context.show_page()
        elif images_per_page == 2 and len(self.filenames) >= 2:
            for contador in range(0, len(self. filenames), 2):
                for i in range(0, 2):
                    if(contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                                self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 2.0)
                        zh = h / height
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i) * width / 2.0 +\
                            abs(w / z - width / 2.0) / 2.0
                        y = abs(h / z - height) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 4 and len(self.filenames) >= 4:
            for contador in range(0, len(self. filenames), 4):
                for i in range(0, 4):
                    if(contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 2.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 2) * width / 2.0 +\
                            abs(w / z - width / 2.0) / 2.0
                        y = float(i / 2) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        print(x, y)
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 6 and len(self.filenames) >= 6:
            for contador in range(0, len(self. filenames), 6):
                for i in range(0, 6):
                    if(contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 3.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 3) * width / 3.0 +\
                            abs(w / z - width / 3.0) / 2.0
                        y = float(i / 3) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        elif images_per_page == 8 and len(self.filenames) >= 8:
            for contador in range(0, len(self. filenames), 8):
                for i in range(0, 8):
                    if(contador + i < len(self.filenames)):
                        image = create_image_surface_from_file(
                            self.filenames[contador + i])
                        w = image.get_width() / MMTOPIXEL
                        h = image.get_height() / MMTOPIXEL
                        zw = w / (width / 4.0)
                        zh = h / (height / 2.0)
                        if zw > zh:
                            z = zw
                        else:
                            z = zh
                        context.save()
                        x = float(i % 4) * width / 4.0 +\
                            abs(w / z - width / 4.0) / 2.0
                        y = float(i / 4) * height / 2.0 +\
                            abs(h / z - height / 2.0) / 2.0
                        context.translate(x * 2.8343, y * 2.8343)
                        context.scale(2.8343 / MMTOPIXEL / z,
                                      2.8343 / MMTOPIXEL / z)
                        context.set_source_surface(image)
                        context.paint()
                        context.restore()
                context.show_page()
        pdfsurface.flush()
        pdfsurface.finish()
        if orientation == LANDSCAPE:
            printcommand = 'lp -d %s\
                            -o media=%s\
                            -o orientation-requested=4 "%s"' % (aprinter,
                                                                apapersize,
                                                                temp_pdf)
        else:
            printcommand = 'lp -d %s -o media=%s "%s"' % (aprinter,
                                                          apapersize,
                                                          temp_pdf)
        print(printcommand)
        args = shlex.split(printcommand)
        p = subprocess.Popen(args, bufsize=10000, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        ans = p.communicate()[0]
        if p.returncode == 0:
            print(ans)
        os.remove(temp_pdf)

    def on_key_release_event(self, widget, event):
        print((event.keyval))
        if event.keyval == 65451 or event.keyval == 43:
            self.scale = self.scale * 1.1
        elif event.keyval == 65453 or event.keyval == 45:
            self.scale = self.scale * .9
        elif event.keyval == 65456 or event.keyval == 48:
            pass
            '''
            factor_w = float(
                self.scrolledwindow1.get_allocation().width) /\
                float(self.pixbuf1.get_width())
            factor_h = float(
                self.scrolledwindow1.get_allocation().height) /\
                float(self.pixbuf1.get_height())
            if factor_w < factor_h:
                factor = factor_w
            else:
                factor = factor_h
            self.scale = int(factor * 100)
            w = int(self.pixbuf1.get_width() * factor)
            h = int(self.pixbuf1.get_height() * factor)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
        elif event.keyval == 65457 or event.keyval == 49:
            self.scale = 100
        if self.image1:
            w = int(self.pixbuf1.get_width() * self.scale / 100)
            h = int(self.pixbuf1.get_height() * self.scale / 100)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h,
                                          GdkPixbuf.InterpType.BILINEAR))
            '''

    def close(self, widget):
        self.destroy()
Ejemplo n.º 15
0
class FlipDialog(Gtk.Dialog):
    def __init__(self, title, filename=None):
        Gtk.Dialog.__init__(
            self, title, None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
             Gtk.ResponseType.CANCEL))
        self.set_default_size(800, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=3, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1,
                     0,
                     1,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2,
                     1,
                     2,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        #
        self.scale = 100

        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0,
                     0,
                     2,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip vertical'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch1 = Gtk.Switch()
        self.switch1.set_name('switch1')
        self.switch1.connect("notify::active", self.slider_on_value_changed)
        hbox1 = Gtk.HBox()
        hbox1.pack_start(self.switch1, 0, 0, 0)
        table.attach(hbox1,
                     1,
                     2,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip horizontal'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch2 = Gtk.Switch()
        self.switch2.set_name('switch2')
        self.switch2.connect("notify::active", self.slider_on_value_changed)
        hbox2 = Gtk.HBox()
        hbox2.pack_start(self.switch2, 0, 0, 0)
        table.attach(hbox2,
                     1,
                     2,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Rotate'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        table1 = Gtk.Table(rows=1, columns=4, homogeneous=False)
        table1.set_border_width(5)
        table1.set_col_spacings(5)
        table1.set_row_spacings(5)
        table.attach(table1,
                     1,
                     2,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton1 = Gtk.RadioButton.new_with_label_from_widget(None, '0')
        self.rbutton1.set_name('0')
        self.rbutton1.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton1,
                      0,
                      1,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton2 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '90')
        self.rbutton2.set_name('90')
        self.rbutton2.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton2,
                      1,
                      2,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton3 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '180')
        self.rbutton3.set_name('180')
        self.rbutton3.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton3,
                      2,
                      3,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton4 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '270')
        self.rbutton4.set_name('270')
        self.rbutton4.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton4,
                      3,
                      4,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        #
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))
        #
        print(1)
        self.show_all()

    def slider_on_value_changed(self, widget, calue):
        print(widget.get_name())
        if widget.get_name() == 'switch1':
            self.viewport2.set_flip_vertical(self.switch1.get_active())
        elif widget.get_name() == 'switch2':
            self.viewport2.set_flip_horizontal(self.switch2.get_active())
        elif widget.get_name() == '0':
            self.viewport2.set_rotation_angle(0.0)
        elif widget.get_name() == '90':
            self.viewport2.set_rotation_angle(1.0)
        elif widget.get_name() == '180':
            self.viewport2.set_rotation_angle(2.0)
        elif widget.get_name() == '270':
            self.viewport2.set_rotation_angle(3.0)

    def on_key_release_event(self, widget, event):
        print((event.keyval))
        if event.keyval == 65451 or event.keyval == 43:
            self.scale = self.scale * 1.1
        elif event.keyval == 65453 or event.keyval == 45:
            self.scale = self.scale * .9
        elif event.keyval == 65456 or event.keyval == 48:
            factor_w = (float(self.scrolledwindow1.get_allocation().width) /
                        float(self.pixbuf1.get_width()))
            factor_h = (float(self.scrolledwindow1.get_allocation().height) /
                        float(self.pixbuf1.get_height()))
            if factor_w < factor_h:
                factor = factor_w
            else:
                factor = factor_h
            self.scale = int(factor * 100)
            w = int(self.pixbuf1.get_width() * factor)
            h = int(self.pixbuf1.get_height() * factor)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
        elif event.keyval == 65457 or event.keyval == 49:
            self.scale = 100
        if self.image1:
            w = int(self.pixbuf1.get_width() * self.scale / 100)
            h = int(self.pixbuf1.get_height() * self.scale / 100)
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))

    def close(self, widget):
        self.destroy()
Ejemplo n.º 16
0
    def __init__(self, filename=None):
        Gtk.Dialog.__init__(
            self, _('Paginate'), None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
             Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.set_size_request(500, 140)
        self.set_resizable(False)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close_application)
        #
        vbox0 = Gtk.VBox(spacing=5)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        #
        notebook = Gtk.Notebook()
        vbox0.add(notebook)
        #
        frame = Gtk.Frame()
        notebook.append_page(frame, tab_label=Gtk.Label(_('Paginate')))
        #
        table = Gtk.Table(rows=4, columns=2, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 1, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2, 1, 2, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        self.viewport2.set_text('1/1')
        #
        self.scale = 100

        #
        vertical_options = Gtk.ListStore(str, int)
        vertical_options.append([_('Top'), TOP])
        vertical_options.append([_('Middle'), MIDLE])
        vertical_options.append([_('Bottom'), BOTTOM])
        #
        horizontal_options = Gtk.ListStore(str, int)
        horizontal_options.append([_('Left'), LEFT])
        horizontal_options.append([_('Center'), CENTER])
        horizontal_options.append([_('Right'), RIGHT])
        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0, 0, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        # Font 2 3
        vbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        table.attach(vbox1, 0, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        button_font = Gtk.Button(_('Select font'))
        button_font.connect('clicked', self.on_button_font_activated)
        vbox1.pack_start(button_font, False, False, 0)
        button_color = Gtk.Button(_('Select color'))
        button_color.connect('clicked', self.on_button_color_activated)
        vbox1.pack_start(button_color, False, False, 0)
        #
        label = Gtk.Label(_('Horizontal position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.horizontal = Gtk.ComboBox.new_with_model_and_entry(
            horizontal_options)
        self.horizontal.set_entry_text_column(0)
        self.horizontal.set_active(0)
        self.horizontal.connect('changed', self.on_value_changed)
        table.attach(self.horizontal, 1, 2, 5, 6,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Vertical position')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        self.vertical = Gtk.ComboBox.new_with_model_and_entry(vertical_options)
        self.vertical.set_entry_text_column(0)
        self.vertical.set_active(0)
        self.vertical.connect('changed', self.on_value_changed)
        table.attach(self.vertical, 1, 2, 6, 7,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Set horizontal margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin = Gtk.SpinButton()
        self.horizontal_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.horizontal_margin, 1, 2, 7, 8,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.horizontal_margin.connect('value-changed',
                                       self.on_margin_changed)
        label = Gtk.Label(_('Set vertical margin')+':')
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin = Gtk.SpinButton()
        self.vertical_margin.set_adjustment(
            Gtk.Adjustment(5, 0, 100, 1, 10, 10))
        table.attach(self.vertical_margin, 1, 2, 8, 9,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.vertical_margin.connect('value-changed',
                                     self.on_margin_changed)

        self.show_all()
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))
Ejemplo n.º 17
0
    def __init__(self, title, filename=None):
        Gtk.Dialog.__init__(
            self, title, None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL,
             Gtk.ResponseType.CANCEL))
        self.set_default_size(800, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=3, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1,
                     0,
                     1,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2,
                     1,
                     2,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        #
        self.scale = 100

        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0,
                     0,
                     2,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip vertical'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch1 = Gtk.Switch()
        self.switch1.set_name('switch1')
        self.switch1.connect("notify::active", self.slider_on_value_changed)
        hbox1 = Gtk.HBox()
        hbox1.pack_start(self.switch1, 0, 0, 0)
        table.attach(hbox1,
                     1,
                     2,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip horizontal'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch2 = Gtk.Switch()
        self.switch2.set_name('switch2')
        self.switch2.connect("notify::active", self.slider_on_value_changed)
        hbox2 = Gtk.HBox()
        hbox2.pack_start(self.switch2, 0, 0, 0)
        table.attach(hbox2,
                     1,
                     2,
                     3,
                     4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Rotate'))
        label.set_alignment(0, .5)
        table.attach(label,
                     0,
                     1,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        table1 = Gtk.Table(rows=1, columns=4, homogeneous=False)
        table1.set_border_width(5)
        table1.set_col_spacings(5)
        table1.set_row_spacings(5)
        table.attach(table1,
                     1,
                     2,
                     4,
                     5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton1 = Gtk.RadioButton.new_with_label_from_widget(None, '0')
        self.rbutton1.set_name('0')
        self.rbutton1.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton1,
                      0,
                      1,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton2 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '90')
        self.rbutton2.set_name('90')
        self.rbutton2.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton2,
                      1,
                      2,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton3 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '180')
        self.rbutton3.set_name('180')
        self.rbutton3.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton3,
                      2,
                      3,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton4 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '270')
        self.rbutton4.set_name('270')
        self.rbutton4.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton4,
                      3,
                      4,
                      0,
                      1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        #
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))
        #
        print(1)
        self.show_all()
Ejemplo n.º 18
0
class FlipDialog(Gtk.Dialog):
    def __init__(self, title, filename=None):
        Gtk.Dialog.__init__(
            self, title, None,
            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
            (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
             Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.set_default_size(800, 400)
        self.set_resizable(True)
        self.set_icon_from_file(comun.ICON)
        self.connect('destroy', self.close)
        #
        vbox = Gtk.VBox(spacing=5)
        vbox.set_border_width(5)
        self.get_content_area().add(vbox)
        #
        frame = Gtk.Frame()
        vbox.pack_start(frame, True, True, 0)
        #
        table = Gtk.Table(rows=2, columns=3, homogeneous=False)
        table.set_border_width(5)
        table.set_col_spacings(5)
        table.set_row_spacings(5)
        frame.add(table)
        #
        frame1 = Gtk.Frame()
        table.attach(frame1, 0, 1, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.scrolledwindow1 = Gtk.ScrolledWindow()
        self.scrolledwindow1.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame1.add(self.scrolledwindow1)
        #
        self.viewport1 = MiniView()
        self.scrolledwindow1.add(self.viewport1)
        #
        frame2 = Gtk.Frame()
        table.attach(frame2, 1, 2, 0, 1,
                     xoptions=Gtk.AttachOptions.EXPAND,
                     yoptions=Gtk.AttachOptions.SHRINK)
        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.set_size_request(420, 420)
        self.connect('key-release-event', self.on_key_release_event)
        frame2.add(scrolledwindow2)
        #
        self.viewport2 = MiniView()
        scrolledwindow2.add(self.viewport2)
        #
        self.scale = 100

        #
        self.rbutton0 = Gtk.CheckButton(_('Overwrite original file?'))
        table.attach(self.rbutton0, 0, 2, 1, 2,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip vertical'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch1 = Gtk.Switch()
        self.switch1.set_name('switch1')
        self.switch1.connect("notify::active", self.slider_on_value_changed)
        hbox1 = Gtk.HBox()
        hbox1.pack_start(self.switch1, 0, 0, 0)
        table.attach(hbox1, 1, 2, 2, 3,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Flip horizontal'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.switch2 = Gtk.Switch()
        self.switch2.set_name('switch2')
        self.switch2.connect("notify::active", self.slider_on_value_changed)
        hbox2 = Gtk.HBox()
        hbox2.pack_start(self.switch2, 0, 0, 0)
        table.attach(hbox2, 1, 2, 3, 4,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        #
        label = Gtk.Label(_('Rotate'))
        label.set_alignment(0, .5)
        table.attach(label, 0, 1, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        table1 = Gtk.Table(rows=1, columns=4, homogeneous=False)
        table1.set_border_width(5)
        table1.set_col_spacings(5)
        table1.set_row_spacings(5)
        table.attach(table1, 1, 2, 4, 5,
                     xoptions=Gtk.AttachOptions.FILL,
                     yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton1 = Gtk.RadioButton.new_with_label_from_widget(None, '0')
        self.rbutton1.set_name('0')
        self.rbutton1.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton1, 0, 1, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton2 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '90')
        self.rbutton2.set_name('90')
        self.rbutton2.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton2, 1, 2, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton3 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '180')
        self.rbutton3.set_name('180')
        self.rbutton3.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton3, 2, 3, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        self.rbutton4 = Gtk.RadioButton.new_with_label_from_widget(
            self.rbutton1, '270')
        self.rbutton4.set_name('270')
        self.rbutton4.connect("notify::active", self.slider_on_value_changed)
        table1.attach(self.rbutton4, 3, 4, 0, 1,
                      xoptions=Gtk.AttachOptions.EXPAND,
                      yoptions=Gtk.AttachOptions.SHRINK)
        #
        if filename is not None:
            uri = "file://" + filename
            document = Poppler.Document.new_from_file(uri, None)
            if document.get_n_pages() > 0:
                self.viewport1.set_page(document.get_page(0))
                self.viewport2.set_page(document.get_page(0))
        #
        print(1)
        self.show_all()

    def slider_on_value_changed(self, widget, calue):
        print(widget.get_name())
        if widget.get_name() == 'switch1':
            self.viewport2.set_flip_vertical(self.switch1.get_active())
        elif widget.get_name() == 'switch2':
            self.viewport2.set_flip_horizontal(self.switch2.get_active())
        elif widget.get_name() == '0':
            self.viewport2.set_rotation_angle(0.0)
        elif widget.get_name() == '90':
            self.viewport2.set_rotation_angle(1.0)
        elif widget.get_name() == '180':
            self.viewport2.set_rotation_angle(2.0)
        elif widget.get_name() == '270':
            self.viewport2.set_rotation_angle(3.0)

    def on_key_release_event(self, widget, event):
        print((event.keyval))
        if event.keyval == 65451 or event.keyval == 43:
            self.scale = self.scale*1.1
        elif event.keyval == 65453 or event.keyval == 45:
            self.scale = self.scale*.9
        elif event.keyval == 65456 or event.keyval == 48:
            factor_w = (float(self.scrolledwindow1.get_allocation().width) /
                        float(self.pixbuf1.get_width()))
            factor_h = (float(self.scrolledwindow1.get_allocation().height) /
                        float(self.pixbuf1.get_height()))
            if factor_w < factor_h:
                factor = factor_w
            else:
                factor = factor_h
            self.scale = int(factor*100)
            w = int(self.pixbuf1.get_width()*factor)
            h = int(self.pixbuf1.get_height()*factor)
            #
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
        elif event.keyval == 65457 or event.keyval == 49:
            self.scale = 100
        if self.image1:
            w = int(self.pixbuf1.get_width()*self.scale/100)
            h = int(self.pixbuf1.get_height()*self.scale/100)
            self.image1.set_from_pixbuf(
                self.pixbuf1.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))
            self.image2.set_from_pixbuf(
                self.pixbuf2.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR))

    def close(self, widget):
        self.destroy()