def __init__(self, parent=None): super(Main, self).__init__(parent) # This is because Python does not automatically # call the parent's constructor. self.setupUi(self) self.displayArea.setAcceptDrops(True) #notify that the program has started. n = pynotify.Notification ("SimpleImageDownloader Running!", "Drag an image from a web page to the drop here button " "the link will be displayed. Hit the Browse button to extract the image url. " "Select Download to download the image, Multiple Images can be extracted and downloaded at once.", "notification-message-im") n.show () #show the notification # Pass this "self" for building widgets and # keeping a reference. self.connectActions() self.img_dl = ImageDownloader(self) self.progressBar.setValue(0) #signals to update the ui from other threads QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update(QString)"),self.update) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_progressbar_value()"),self.update_progressbar_value) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_status(QString)"),self.update_status) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_extract_url(QString)"),self.update_extract_url)
class Main(QtGui.QMainWindow, main_window.Ui_MainWindow): """ The second parent must be 'Ui_<obj. name of main widget class>'. If confusing, simply open up ImageViewer.py and get the class name used. I'd named mine as mainWindow, hence Ui_mainWindow. """ def __init__(self, parent=None): super(Main, self).__init__(parent) # This is because Python does not automatically # call the parent's constructor. self.setupUi(self) self.displayArea.setAcceptDrops(True) #notify that the program has started. n = pynotify.Notification ("SimpleImageDownloader Running!", "Drag an image from a web page to the drop here button " "the link will be displayed. Hit the Browse button to extract the image url. " "Select Download to download the image, Multiple Images can be extracted and downloaded at once.", "notification-message-im") n.show () #show the notification # Pass this "self" for building widgets and # keeping a reference. self.connectActions() self.img_dl = ImageDownloader(self) self.progressBar.setValue(0) #signals to update the ui from other threads QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update(QString)"),self.update) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_progressbar_value()"),self.update_progressbar_value) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_status(QString)"),self.update_status) QtCore.QObject.connect(self.img_dl,QtCore.SIGNAL("update_extract_url(QString)"),self.update_extract_url) def update_extract_url(self, url): self.displayArea.append(str(url)) def update_progressbar_value(self): self.progressBar.setValue(self.progressBar.value() + 1) def update(self, s): self.displayArea.append(str(s)) def update_status(self, s): self.label.setText(str(s)) def download(self, url): global downloader_created #check if there is already a downloader created if("img.skins.be" in url): #is an image url queue.put_nowait(url) else: #is a webpage url and needs to be read queue.put_nowait(url) if(not downloader_created): self.downloader = Downloader(self.img_dl) self.downloader.start() downloader_created = True def extract_url(self, url): global reader_created reader_queue.put_nowait(url) if(not reader_created): self.reader = Reader(self.img_dl) self.reader.start() reader_created = True def extract_url_list(self, list): global reader_created self.displayArea.clear() for url in list: if(not "img.skins.be" in url): reader_queue.put_nowait(url) else: self.displayArea.append(url) if(not reader_created): self.reader = Reader(self.img_dl) self.reader.start() reader_created = True #connect signals to buttons def connectActions(self): self.download_pushButton.clicked.connect(self.download_callback) #note the use of clicked not clicked() self.browse_pushButton.clicked.connect(self.browse_callback) #note the use of clicked not clicked() def download_callback(self): text = str(self.displayArea.toPlainText()).strip().split('\n') self.progressBar.setMinimum(0) self.progressBar.setMaximum(len(text)) for t in text: self.download(t) def browse_callback(self): display_area_text = str(self.displayArea.toPlainText()).strip().split('\n') forum_page_text = str(self.forumPageInput.text()) if(len(forum_page_text) > 1): self.img_dl.browse_forum_page(forum_page_text) # run in separate thread elif(len(display_area_text) > 0): self.extract_url_list(display_area_text) def main(self): self.show()