Beispiel #1
0
    def open_image(self, filename=None):
        # Present a dialog for the user to choose an image here
        if not filename:
            fil = gtk.FileFilter()
            fil.set_name("Images")
            fil.add_pixbuf_formats()
            dialog = gtk.FileChooserDialog (_("Choose image to insert"), None, gtk.FILE_CHOOSER_ACTION_OPEN, \
                                     (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
            dialog.add_filter(fil)
            res = dialog.run()
            dialog.hide()
            if res != gtk.RESPONSE_OK:
                return False
            else:
                fname = dialog.get_filename()
        else:
            fname = filename

        try:
            self.orig_pic = gtk.gdk.pixbuf_new_from_file(fname)
        except:
            try:
                # lets see if file was imported and is already extracted
                fname = os.path.join(utils.get_images_dir(),
                                     +os.path.basename(filename))
                self.orig_pic = gtk.gdk.pixbuf_new_from_file(fname)
            except:
                return False

        self.filename = fname

        if not filename:
            self.width = self.orig_pic.get_width()
            self.height = self.orig_pic.get_height()
            margin = utils.margin_required(utils.STYLE_NORMAL)

            self.lr = (self.pic_location[0] + self.width + margin[2],
                       self.pic_location[1] + self.height + margin[3])
            self.pic = self.orig_pic
        self.text = fname[fname.rfind('/') + 1:fname.rfind('.')]
        return True
Beispiel #2
0
def load_icon(icon, width=48, height=48):
    pixbuf = None
    if icon != None and icon != "":
        try:
            icon_file = os.path.join(utils.get_images_dir(), icon)
            if os.path.exists(icon_file):
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_file, width,
                                                              height)
            elif icon.startswith("/"):
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon, width,
                                                              height)
            else:
                pixbuf = icon_theme.load_icon(os.path.splitext(icon)[0], width,
                                              gtk.ICON_LOOKUP_USE_BUILTIN)
        except Exception, msg1:
            try:
                pixbuf = icon_theme.load_icon(icon, width,
                                              gtk.ICON_LOOKUP_USE_BUILTIN)
            except Exception, msg2:
                print 'Error:load_icon:Icon Load Error:%s (or %s)' % (msg1,
                                                                      msg2)
    def open_image (self, filename = None):
        # Present a dialog for the user to choose an image here
        if not filename:
            fil = gtk.FileFilter ()
            fil.set_name("Images")
            fil.add_pixbuf_formats ()
            dialog = gtk.FileChooserDialog (_("Choose image to insert"), None, gtk.FILE_CHOOSER_ACTION_OPEN, \
                                     (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
            dialog.add_filter (fil)
            res = dialog.run ()
            dialog.hide ()
            if res != gtk.RESPONSE_OK:
                return False
            else:
                fname = dialog.get_filename()
        else:
            fname = filename

        try:
            self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname)
        except:
            try:
                # lets see if file was imported and is already extracted
                fname = os.path.join (utils.get_images_dir (), + os.path.basename(filename))
                self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname)
            except:
                return False

        self.filename = fname

        if not filename:
            self.width = self.orig_pic.get_width ()
            self.height = self.orig_pic.get_height ()
            margin = utils.margin_required (utils.STYLE_NORMAL)

            self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3])
            self.pic = self.orig_pic
        self.text = fname[fname.rfind('/')+1:fname.rfind('.')]
        return True