def getImageThumb(self, data): if not isImage(data[9]): iconsPath = "/usr/share/icons/gnome/32x32/mimetypes/" defaultIcon = iconsPath + "empty.png" iconName = "gnome-mime-"+data[9].split('/')[0].lower()+"-"+data[9].split('/')[-1].lower()+".png" if os.path.exists(iconsPath+iconName): pixbuf = gtk.gdk.pixbuf_new_from_file(iconsPath+iconName) else: pixbuf = gtk.gdk.pixbuf_new_from_file(defaultIcon) image = gtk.Image() image.set_from_pixbuf(pixbuf) return image cachePath = getPyShareHomeDirectory() + 'cache/' if not os.path.exists(cachePath): os.makedirs(cachePath) #filename = cachePath + md5(data[6].join(data[5])).hexdigest() #if os.path.exists(filename): pixbuf = getThumbnailFromCache(data[2]) if pixbuf : image = gtk.Image() image.set_from_pixbuf(pixbuf) return image else: pixbuf = self.getImageFromHosting(data) filename=cachePath + md5(data[2]).hexdigest() image = gtk.Image() image.set_from_pixbuf(pixbuf) if(data[8]=="jpg" or data[8]=="gif"): pixbuf.save(filename, "jpeg") else: pixbuf.save(filename, data[8]) return image
def removeElement(self, widget, numberOfElement, fileid): """remove element from panel and database""" data = self.db.getFileById(fileid) if isImage(data[9]): removeFromCache(data[2]) self.db.deleteFile(fileid) element = self.elements[numberOfElement] separator = self.elements[numberOfElement+1] self.panel.remove(element) self.panel.remove(separator) element.destroy() separator.destroy() del self.elements[numberOfElement] del self.elements[numberOfElement+1]
def __fileUploadEnded(self, fileNumber, errorOccured, imageLinks=None,file=""): """if upload was successfull than attaches imageLinks to combobox with given fileNumber and shows it otherwise it sets proggressbar message to indicate upload failure imageLinks and file are ignored if errorOccured is True""" if not errorOccured: self.links[fileNumber] = imageLinks[0] # there is one thread per file so this should be thread safe db.addFile(getUploader(file).NAME, imageLinks[2][0], imageLinks[2][1], imageLinks[2][2], os.path.basename(file), os.path.getsize(file),file.split('.')[-1].lower(), getMimeTypes(file)) if isImage(getMimeTypes(file)): saveThumbnail(createThumbnail(file), file, imageLinks[2][0]) self.__uploadsCompletedLock.acquire() try: #rather not needed self.__uploadsCompleted += 1 if errorOccured: self.__uploadsErrors += 1 finally: self.__uploadsCompletedLock.release() try: gtk.gdk.threads_enter() if errorOccured: self.__pbars[fileNumber].set_text(_("upload failed")) else: self.__pbars[fileNumber].set_text(_("upload completed")) combobox = self.__comboBoxes[fileNumber] linkTypes = imageLinks[1] populateCombobox(combobox, linkTypes) combobox.show() self.__populateStatusIconMenuForFile(fileNumber, linkTypes) if self.__uploadsCompleted > 1: self.__createCopyAllLinks() self.setWindowSize() self.__statusIcon.set_tooltip(_("Uploaded ") + str(self.__uploadsCompleted) + _(" of ") + str(len(self.__comboBoxes)) + _(" files.")) if(self.__uploadsCompleted == len(self.__comboBoxes)): if (set.getBlinkIcon()): self.__statusIcon.set_blinking(True) if set.getShowNotifications(): try: import pynotify if pynotify.init("PyShare"): notification = None if self.__uploadsErrors == 0: notification = pynotify.Notification(_("All files have been uploaded"), _("select link from comboboxes or systray to copy it to clipboard"), "go-up") elif self.__uploadsErrors < self.__uploadsCompleted : notification = pynotify.Notification(_("Some files have not been uploaded"), _("select link from comboboxes or systray to copy it to clipboard. Try sending not-uploaded files again"), "go-up") else: notification = pynotify.Notification(_("Uploads failed"), _("Please try again. If error persist check if file is correct and that you have connection."), "go-up") notification.show() except ImportError: pass finally: gtk.gdk.threads_leave()
def __fileUploadEnded(self, fileNumber, errorOccured, imageLinks=None,file=""): """if upload was successfull than attaches imageLinks to combobox with given fileNumber and shows it otherwise it sets proggressbar message to indicate upload failure imageLinks and file are ignored if errorOccured is True""" if self.__cancelled[fileNumber]: self.__fileUploadCancelled(fileNumber) return # First, hide 'Cancel' button cancelbutton = self.__cancelUploadButton[fileNumber] cancelbutton.hide() if not errorOccured: self.links[fileNumber] = imageLinks[0] # there is one thread per file so this should be thread safe db.addFile(getUploader(file).NAME, imageLinks[2][0], imageLinks[2][1], imageLinks[2][2], os.path.basename(file), os.path.getsize(file),file.split('.')[-1].lower(), getMimeTypes(file)) if isImage(getMimeTypes(file)): saveThumbnail(createThumbnail(file), file, imageLinks[2][0]) self.__uploadsCompletedLock.acquire() try: #rather not needed self.__uploadsCompleted += 1 if errorOccured: self.__uploadsErrors += 1 finally: self.__uploadsCompletedLock.release() try: gtk.gdk.threads_enter() if errorOccured: self.__pbars[fileNumber].set_text(_("upload failed")) else: self.__pbars[fileNumber].set_text(_("upload completed")) # Upload has succeeded, we allow 'Copy Link' button to show copybutton = self.__cplinkButton[fileNumber] copybutton.show() combobox = self.__comboBoxes[fileNumber] linkTypes = imageLinks[1] populateCombobox(combobox, linkTypes) combobox.show() self.__populateStatusIconMenuForFile(fileNumber, linkTypes) if self.__uploadsCompleted > 1: self.__createCopyAllLinks() self.setWindowSize() self.__statusIcon.set_tooltip(_("Uploaded ") + str(self.__uploadsCompleted) + _(" of ") + str(len(self.__comboBoxes)) + _(" files.")) if(self.__uploadsCompleted == len(self.__comboBoxes)): if (set.getBlinkIcon()): self.__statusIcon.set_blinking(True) if set.getShowNotifications(): try: import pynotify if pynotify.init("PyShare"): notification = None if self.__uploadsErrors == 0: notification = pynotify.Notification(_("File(s) uploaded successfully"), _("Click the Copy Link button to copy the file url(s) to your clipboard."), "go-up") elif self.__uploadsErrors < self.__uploadsCompleted : notification = pynotify.Notification(_("Some upload(s) failed"), _("For successfully upload(s), click the Copy Link button to copy the file url(s) to your clipboard. Please try failed upload(s) again."), "go-up") else: notification = pynotify.Notification(_("Upload(s) Failed"), _("Please verify your internet connection and that the file(s) have appropriate permissions then try again."), "go-up") notification.show() except ImportError: pass finally: gtk.gdk.threads_leave()
def addElement(self, data): """add element to history panel with thumb, links and information about image""" hbox = gtk.HBox(False, 0) self.panel.pack_start(hbox, False, False, 0) hbox.show() image = self.getImageThumb(data) image.set_padding(10,10) image.set_tooltip_text(data[6]) hbox.pack_start(image, False, False, 0) image.show() vboxSmall = gtk.VBox(True, 0) hbox.pack_start(vboxSmall, False, False, 0) vboxSmall.show() table = gtk.Table(4, 3, False) vboxSmall.pack_start(table, True, True, 0) table.set_size_request(400, -1) table.set_border_width(10) table.show() labelname = gtk.Label() labelname.set_markup("<b>"+_("Original filename:")+"</b>") labelname.set_alignment(xalign=0, yalign=0.5) labelname.show() table.attach(labelname, 0, 1, 0, 1) name=gtk.Label(data[6]) name.set_alignment(xalign=0, yalign=0.5) name.show() table.attach(name, 1, 2, 0, 1) labeldate = gtk.Label() labeldate.set_markup("<b>"+_("Upload date:")+"</b>") labeldate.set_alignment(xalign=0, yalign=0.5) labeldate.show() table.attach(labeldate, 0, 1, 1, 2) date=gtk.Label(convert_date(data[5])) date.set_alignment(xalign=0, yalign=0.5) date.show() table.attach(date, 1, 2, 1, 2) labelsize = gtk.Label() labelsize.set_markup("<b>"+_("Filesize:")+"</b>") labelsize.set_alignment(xalign=0, yalign=0.5) labelsize.show() table.attach(labelsize, 0, 1, 2, 3) size=gtk.Label(convert_bytes(data[7])) size.set_alignment(xalign=0, yalign=0.5) size.show() table.attach(size, 1, 2, 2, 3) labellink=gtk.Label() labellink.set_markup("<b>"+_("Links:")+"</b>") labellink.set_alignment(xalign=0, yalign=0.5) labellink.show() table.attach(labellink, 0, 1, 3, 4) if isImage(data[9]): links, typesOfLinks, basicLinks = createLinks(data[2], data[6], data[4], data[3]) else: links, typesOfLinks, basicLinks = createLinks(data[2], data[6], None, data[3]) self.links.append(links) comboBox = createCombobox(typesOfLinks) comboBox.connect("changed", self.copyLink, self.fileNumber) comboBox.show() self.fileNumber += 1 table.attach(comboBox, 1, 2, 3, 4) toolButton = gtk.ToolButton(gtk.STOCK_REMOVE) toolButton.set_tooltip_text(_("Remove")) toolButton.connect("clicked", self.removeElement, self.totalNumberOfElements, data[0]) table.attach(toolButton, 2,3, 0,3) separator = gtk.HSeparator() self.panel.pack_start(separator, False, False, 4) separator.show() self.elements[self.totalNumberOfElements] = hbox self.totalNumberOfElements += 1 self.elements[self.totalNumberOfElements] = separator self.totalNumberOfElements += 1