Example #1
0
 def addPages(self, issue):
     zf = zipfile.ZipFile(issue.containing_directory + "/" + issue.file)
     for file_in_zip in zf.namelist():
         if ".jpg" in file_in_zip.lower() or ".png" in file_in_zip.lower():
             print(file_in_zip)
             loader = PixbufLoader()
             loader.write(zf.read(file_in_zip))
             loader.close()
             thumbnail = loader.get_pixbuf()
             h = thumbnail.get_height()
             w = thumbnail.get_width()
             r = h/w  # Preserve Aspect Ratio
             windowwidth= self.get_size()[0]
             pixbuf = Pixbuf.scale_simple(thumbnail, windowwidth, windowwidth*r, True)
             self.get_child().get_child().get_child().add(Gtk.Image.new_from_pixbuf(pixbuf))
Example #2
0
def scale_pixbuf(pixbuf: GdkPixbuf.Pixbuf, outer_width: int, outer_height):
    # Get original size
    ow = pixbuf.get_width()
    oh = pixbuf.get_height()
    # Get aspect ration
    ratio = Fraction(ow, oh)
    # Try scaling to outer_height
    scaled_height = outer_height
    scaled_width = int(ratio * outer_height)
    # If it is larger than outer_width, fixed by width
    if scaled_width > outer_width:
        scaled_width = outer_width
        scaled_height = int(scaled_width / ratio)
    # Now scale with calculated size
    return pixbuf.scale_simple(scaled_width, scaled_height, GdkPixbuf.InterpType.BILINEAR)
Example #3
0
 def set_thumbnail_to_image(self, image_to_use):
     try:
         loader = PixbufLoader()
         loader.write(image_to_use)
         loader.close()
         thumbnail = loader.get_pixbuf()
         h = thumbnail.get_height()
         w = thumbnail.get_width()
         r = h/w  # Preserve Aspect Ratio
         pixbuf = Pixbuf.scale_simple(thumbnail, cover_width, cover_width*r, True)
         self.thumbnail = pixbuf
         return True
     except Exception:
         print(Exception)
         return False
Example #4
0
    def set_image(self, filename):
        Gtk.Window.set_title(self, filename)
        self.remove(self.image)

        pb = Pixbuf.new_from_file(filename)

        iw = Pixbuf.get_width(pb)
        ih = Pixbuf.get_height(pb)
        ar = (float)(iw) / ih

        (w, h) = Gtk.Window.get_size(self)
        if iw > ih:
            nw = w
            nh = (int)(nw / ar)
        else:
            nh = h
            nw = (int)(nh * ar)

        pb2 = Pixbuf.scale_simple(pb, nw, nh, InterpType.BILINEAR)

        self.image.set_from_pixbuf(pb2)
        self.add(self.image)
Example #5
0
    def set_image(self, filename, event=None):
        Gtk.Window.set_title(self, filename)
        self.remove(self.image)

        pb = Pixbuf.new_from_file(filename)

        iw = Pixbuf.get_width(pb)
        ih = Pixbuf.get_height(pb)
        ar = (float)(iw) / ih

        (w, h) = Gtk.Window.get_size(self)
        if (iw > ih):
            nw = w
            nh = (int)(nw / ar)
        else:
            nh = h
            nw = (int)(nh * ar)

        pb2 = Pixbuf.scale_simple(pb, nw, nh, InterpType.BILINEAR)

        self.image.set_from_pixbuf(pb2)
        self.add(self.image)

        self.image.show_all()
Example #6
0
    def __init__(self):
        Gtk.Window.__init__(self, title="Gpasteboard")
        self.connect("destroy", lambda w: self.destroy())
        self.connect("destroy", self.cclose)
        self.set_icon_from_file("clipman.svg")
        self.set_border_width(5)
        self.set_default_size(800, 800)
        self.set_resizable(True)
        self.set_position(1)
        
        self.hbox = Gtk.Box(spacing=10)
        self.hbox.set_homogeneous(False)
        self.add(self.hbox)

        self.grid = Gtk.Grid()
        self.grid.set_column_homogeneous(True)
        self.hbox.pack_start(self.grid, False, False, 1)

        self.label1 = Gtk.Label(label="<b>0</b> in history")
        self.label1.set_use_markup(True)
        self.grid.attach(self.label1, 0, 0, 1, 1)
        self.grid.set_row_spacing(30)
        
        self.label0 = Gtk.Label(label="<b>0</b> image(s)")
        self.label0.set_use_markup(True)
        self.grid.attach(self.label0, 0, 1, 1, 1)
      
        self.button1 = Gtk.Button(label="Empty history")
        self.button1.connect("clicked", self.on_empty_clicked)
        self.grid.attach(self.button1, 0, 2, 1, 1)
        
        self.button2 = Gtk.Button(label="Quit")
        self.button2.connect("clicked", lambda w: self.destroy())
        self.button2.connect("clicked", self.cclose)
        self.button2.props.valign = 2
        self.button2.props.vexpand = True
        self.grid.attach(self.button2, 0, 3, 1, 1)
        
        self.notebook = Gtk.Notebook()
        self.notebook.set_scrollable(True)
        self.hbox.pack_start(self.notebook, True, True, 0)
        
        self.page1 = Gtk.Box()
        self.page1.set_border_width(10)
        self.notebook.append_page(self.page1, Gtk.Label(label='Text'))

        self.scrolledwindow = Gtk.ScrolledWindow()
        self.scrolledwindow.set_hexpand(True)
        self.scrolledwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scrolledwindow.set_placement(Gtk.CornerType.TOP_RIGHT)
        self.page1.add(self.scrolledwindow)     

        self.listbox = Gtk.ListBox()
        self.listbox.set_selection_mode(Gtk.SelectionMode.NONE)
        self.scrolledwindow.add(self.listbox)
       
        aa = []
        cc = []       

        ccdir = os.getcwd()
        
        tree = ET.parse('history.xml')
        root = tree.getroot()
        
        for iitem in root.iter('item'):
            if list(iitem.attrib.values())[0] == 'Text':
                ttext = iitem.text.strip()
                if len(ttext) < 51:
                    aa.append(ttext.replace('\n', " "+u'\u00AC'+" "))
                else:
                    aa.append(ttext[:51].replace('\n', " "+u'\u00AC'+" ")+" [...]")

        os.chdir(images_path)
        aaa = sorted(os.listdir())
        for iitem in aaa[:]:

            if os.path.splitext(iitem)[1] == '.tiff':
                cc.append(iitem)

        os.chdir(ccdir)    

        q = 0   
        iq = 0   

        for iitem in aa:
            row = Gtk.ListBoxRow()
            hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
            row.add(hbox)
            n_label = Gtk.Label(label=XALIGN)
            # n_label.modify_font(Pango.FontDescription.from_string("Mono"))
            label = Gtk.Label(xalign=0)
            label.set_single_line_mode(True)
            n_label.set_text("{0:>3n}.".format(q+1))
            label.set_text(str(iitem))
            button = Gtk.Button()
            iicon = Gio.ThemedIcon(name="list-remove")
            iimage = Gtk.Image.new_from_gicon(iicon, Gtk.IconSize.BUTTON)
            button.add(iimage)
            button.set_tooltip_text("Delete this item.")
            button.connect("clicked", self.on_tdelbutton_clicked, row)
            button2 = Gtk.Button()
            iicon2 = Gio.ThemedIcon(name="document-page-setup")
            iimage2 = Gtk.Image.new_from_gicon(iicon2, Gtk.IconSize.BUTTON)
            button2.add(iimage2)
            button2.set_tooltip_text("Preview.")
            button2.connect("clicked", self.on_preview_dialog, row)
            hbox.pack_start(n_label, False, False, 4)
            hbox.pack_start(label, True, True, 10)
            hbox.pack_start(button2, False, False, 0)
            hbox.pack_start(button, False, False, 0)
            self.listbox.add(row)
            q += 1
        
        for iitem in reversed(cc):
            grid0 = Gtk.Grid(hexpand=True, vexpand=True)
            grid0.set_column_homogeneous(True)
            hbox0 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
            button0 = Gtk.Button()
            button0.set_tooltip_text("Copy this image.")
            button0.connect("clicked", self.on_copy_image, cc[:])
            iicon = Gio.ThemedIcon(name="dialog-ok")
            iimage = Gtk.Image.new_from_gicon(iicon, Gtk.IconSize.BUTTON)
            button0.add(iimage)
            pixbuf = Pixbuf.new_from_file("images/"+iitem)
            image = Gtk.Image()
            image.set_hexpand(True)
            image.set_vexpand(True)
            ws_p = Pixbuf.get_width(pixbuf)
            hs_p = Pixbuf.get_height(pixbuf)
            if ws_p > 600 or hs_p > 600:
                if ws_p > hs_p:
                    c_ws_p = 600
                    c_hs_p = hs_p*600/ws_p
                else:
                    c_hs_p = 600
                    c_ws_p = ws_p*600/hs_p
                pixbuf = Pixbuf.scale_simple(pixbuf, c_ws_p, c_hs_p, 2)
            image.set_from_pixbuf(pixbuf)
            button = Gtk.Button()
            iicon = Gio.ThemedIcon(name="list-remove")
            iimage = Gtk.Image.new_from_gicon(iicon, Gtk.IconSize.BUTTON)
            button.add(iimage)
            button.set_tooltip_text("Delete this image.")
            button.connect("clicked", self.on_idelbutton_clicked, cc[:])
            button2 = Gtk.Button()
            iicon2 = Gio.ThemedIcon(name="stock_save")
            iimage2 = Gtk.Image.new_from_gicon(iicon2, Gtk.IconSize.BUTTON)
            button2.add(iimage2)
            button2.set_tooltip_text("Save this image.")
            button2.connect("clicked", self.on_isavebutton_clicked,  cc[:])
            hbox0.pack_start(button0, True, True, 0)
            hbox0.pack_start(button2, True, True, 0)
            hbox0.pack_start(button, True, True, 0)
            grid0.attach(image, 0, 1, 1, 1)
            grid0.attach_next_to(hbox0, image, Gtk.PositionType.BOTTOM, 1, 1)
            page = Gtk.Box()
            page.add(grid0)
            label = Gtk.Label("Image")
            self.notebook.append_page(page, label)
            grid0.show()
            image.show()
            button2.show()
            page.show()
            iq += 1
            global pint
            pint += 1
        
        self.label0.set_text("<b>{}</b> image(s)".format(iq))
        self.label0.set_use_markup(True)
        self.label1.set_text("<b>{}</b> in history".format(q))
        self.label1.set_use_markup(True)
        self.listbox.connect("row-activated", self.on_row_clicked)
        self.show_all()
        self.notebook.set_current_page(0)