Пример #1
0
    def addFiles(self, urls, firstAdding=False):
        """adds progressbar, buttons, thumbnail and status menu entry for each file to GUI.
        calls set windows size
        if there is more than one file in the windows also shows copy all link combobox
        starts uploding given files"""
        files = self.urlsToPaths(urls)
        addedFiles = []
        vbox = self.vboxFiles
        numberOfFilesAddedEarierl = len(self.__comboBoxes)
        totalNumberOfFiles = numberOfFilesAddedEarierl
        for file in files:
            hbox = gtk.HBox(False, 0)
            vbox.pack_start(hbox, False, False, 0)
            hbox.show()

	    from stat import *
	    st = os.stat(file)
	    if (st[ST_SIZE] > 5000000):
		from subprocess import Popen
		proc=Popen("zenity --question --text='File may be to large to transfer. Continue?'", shell=True )
		proc.communicate()
		if proc.returncode:
		    break

            #thumbnail
            image = gtk.Image()
            image.set_from_pixbuf(createThumbnail(file))
            hbox.pack_start(image, False, False, 8)
            image.show()

            vboxSmall = gtk.VBox(False, 5)
            hbox.pack_start(vboxSmall, False, False, 0)
            vboxSmall.show()
            
            #filename
            label = gtk.Label(file.split('/')[-1])
	    label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
            label.set_alignment(0, 0.5)
            vboxSmall.pack_start(label, False, False, 0)
            label.show()
            
            #progress bar
            pbar = gtk.ProgressBar()
            self.__pbars.append(pbar)
            vboxSmall.pack_start(pbar, False, False, 0)
            pbar.show()

            #comboBox = createCombobox(uploader.getReturnedLinkTypes())
            comboBox = createCombobox()
            self.links.append([])
            comboBox.connect("changed", self.copyLink, totalNumberOfFiles)
            comboBox.connect("notify::popup-shown", self.__windowClicked)
            #comboBox.show() # "show" comboboxes to make windows size calculation precise(comboboxes will be hidden again before window will be desplayed)
            self.__comboBoxes.append(comboBox)

	    #Copy Link button - not displayed until upload finished
            copyButton = gtk.Button(label = "Copy Link")
            copyButton.connect("clicked", self.copyLink, totalNumberOfFiles, 0)
	    self.__cplinkButton.append(copyButton)
            vboxSmall.pack_start(copyButton, False, False, 0)
            
	    # Cancel upload button
	    cancelButton = gtk.Button(label = "Cancel")
            cancelButton.connect("clicked", self.cancelUpload, totalNumberOfFiles)
	    self.__cancelUploadButton.append(cancelButton)
	    self.__cancelled.append(0)
	    vboxSmall.pack_start(cancelButton, False, False, 0)
	    cancelButton.show()
	    
	    #cancel label to appear after upload cancelled
	    label = gtk.Label("Cancelled")
	    label.set_size_request(150, 50)
	    label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white")) 
	    eb = gtk.EventBox()
	    eb.add(label)
	    eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("grey"))
	    self.__cancelledLabel.append(eb)
	    vboxSmall.pack_start(eb, False, False, 0)
	    label.show()

            separator = gtk.HSeparator()
            vbox.pack_start(separator, False, False, 4)
            separator.show()

            uploader = getUploader(file)
            addedFiles.append(file)
            uploadFileWrapper(uploader,self.fileUploadFailed,
                file,self.fileUploaded,self.progress,totalNumberOfFiles, self.__semaphore)
            totalNumberOfFiles += 1
            
        if firstAdding:
            self.__addFooter()
            self.__createStatusIconMenu(addedFiles)
        else:
            self.insertFilesToStatusIconMenu(addedFiles, numberOfFilesAddedEarierl)
            
#        if totalNumberOfFiles > 1:
#            self.__createCopyAllLinks()

        self.setWindowSize()

        while numberOfFilesAddedEarierl < totalNumberOfFiles: # hide comboboxes, they will be displayed when links are ready
            self.__comboBoxes[numberOfFilesAddedEarierl].hide()
            numberOfFilesAddedEarierl += 1
        self.__statusIcon.set_blinking(False)
Пример #2
0
    def addFiles(self, urls, firstAdding=False):
        """adds progressbar, buttons, thumbnail and status menu entry for each file to GUI.
        calls set windows size
        if there is more than one file in the windows also shows copy all link combobox
        starts uploding given files"""
        files = self.urlsToPaths(urls)
        addedFiles = []
        vbox = self.vboxFiles
        numberOfFilesAddedEarierl = len(self.__comboBoxes)
        totalNumberOfFiles = numberOfFilesAddedEarierl
        for file in files:
            hbox = gtk.HBox(False, 0)
            vbox.pack_start(hbox, False, False, 0)
            hbox.show()

            vboxSmall = gtk.VBox(False, 0)
            hbox.pack_start(vboxSmall, False, False, 0)
            vboxSmall.show()

            label = gtk.Label(file.split('/')[-1])
            vboxSmall.pack_start(label, False, False, 0)
            label.show()

            pbar = gtk.ProgressBar()
            self.__pbars.append(pbar)
            vboxSmall.pack_start(pbar, False, False, 0)
            pbar.show()

            #comboBox = createCombobox(uploader.getReturnedLinkTypes())
            comboBox = createCombobox()
            self.links.append([])
            comboBox.connect("changed", self.copyLink, totalNumberOfFiles)
            comboBox.connect("notify::popup-shown", self.__windowClicked)
            comboBox.show() # "show" comboboxes to make windows size calculation precise(comboboxes will be hidden again before window will be desplayed)
            self.__comboBoxes.append(comboBox)

            vboxSmall.pack_start(comboBox, False, False, 0)

            image = gtk.Image()
            image.set_from_pixbuf(createThumbnail(file))
            hbox.pack_start(image, False, False, 8)
            image.show()

            separator = gtk.HSeparator()
            vbox.pack_start(separator, False, False, 4)
            separator.show()

            uploader = getUploader(file)
            addedFiles.append(file)
            uploadFileWrapper(uploader,self.fileUploadFailed,
                file,self.fileUploaded,self.progress,totalNumberOfFiles, self.__semaphore)
            totalNumberOfFiles += 1
            
        if firstAdding:
            self.__addFooter()
            self.__createStatusIconMenu(addedFiles)
        else:
            self.insertFilesToStatusIconMenu(addedFiles, numberOfFilesAddedEarierl)
            
#        if totalNumberOfFiles > 1:
#            self.__createCopyAllLinks()

        self.setWindowSize()

        while numberOfFilesAddedEarierl < totalNumberOfFiles: # hide comboboxes, they will be displayed when links are ready
            self.__comboBoxes[numberOfFilesAddedEarierl].hide()
            numberOfFilesAddedEarierl += 1
        self.__statusIcon.set_blinking(False)