def showProgress(self, modal=True): """ Open the progress dialog to show the current job progress. """ #Replace "self.edit_cntl.win" with "None" #---Huaicai 7/7/05: To fix bug 751, the "win" may be none. #Feel awkward for the design of our code. simProgressDialog = QProgressDialog() simProgressDialog.setModal(True) simProgressDialog.setObjectName("progressDialog") simProgressDialog.setWindowIcon(geticon('ui/border/MainWindow')) if self.Calculation == 'Energy': simProgressDialog.setWindowTitle( "Calculating Energy ...Please Wait") else: simProgressDialog.setWindowTitle("Optimizing ...Please Wait") progBar = QProgressBar(simProgressDialog) progBar.setMaximum(0) progBar.setMinimum(0) progBar.setValue(0) progBar.setTextVisible(False) simProgressDialog.setBar(progBar) simProgressDialog.setAutoReset(False) simProgressDialog.setAutoClose(False) return simProgressDialog
def showProgress(self, modal = True): """ Open the progress dialog to show the current job progress. """ #Replace "self.edit_cntl.win" with "None" #---Huaicai 7/7/05: To fix bug 751, the "win" may be none. #Feel awkward for the design of our code. simProgressDialog = QProgressDialog() simProgressDialog.setModal(True) simProgressDialog.setObjectName("progressDialog") simProgressDialog.setWindowIcon(geticon('ui/border/MainWindow')) if self.Calculation == 'Energy': simProgressDialog.setWindowTitle("Calculating Energy ...Please Wait") else: simProgressDialog.setWindowTitle("Optimizing ...Please Wait") progBar = QProgressBar(simProgressDialog) progBar.setMaximum(0) progBar.setMinimum(0) progBar.setValue(0) progBar.setTextVisible(False) simProgressDialog.setBar(progBar) simProgressDialog.setAutoReset(False) simProgressDialog.setAutoClose(False) return simProgressDialog
class ProgressBar(QDialog, Logger): def __init__(self, parent=None, max_items=100, window_title='Progress Bar', label='Label goes here', frameless=True, on_top=False): if on_top: _flags = Qt.WindowStaysOnTopHint if frameless: _flags |= Qt.FramelessWindowHint QDialog.__init__(self, parent=parent, flags=_flags) else: _flags = Qt.Dialog if frameless: _flags |= Qt.FramelessWindowHint QDialog.__init__(self, parent=parent, flags=_flags) self.application = Application self.setWindowTitle(window_title) self.l = QVBoxLayout(self) self.setLayout(self.l) self.label = QLabel(label) self.label.setAlignment(Qt.AlignHCenter) self.l.addWidget(self.label) self.progressBar = QProgressBar(self) self.progressBar.setRange(0, max_items) self.progressBar.setMinimum(0) self.progressBar.setMaximum(0) self.progressBar.setValue(0) self.l.addWidget(self.progressBar) self.close_requested = False def closeEvent(self, event): self._log_location() self.close_requested = True def increment(self): self.progressBar.setValue(self.progressBar.value() + 1) self.refresh() def refresh(self): self.application.processEvents() def set_label(self, value): self.label.setText(value) self.label.repaint() self.refresh() def set_maximum(self, value): self.progressBar.setMaximum(value) self.refresh() def set_value(self, value): self.progressBar.setValue(value) self.progressBar.repaint() self.refresh()
class DBRestore(QDialog): update_signal = pyqtSignal(object, object) def __init__(self, parent, library_path): QDialog.__init__(self, parent) self.l = QVBoxLayout() self.setLayout(self.l) self.l1 = QLabel('<b>'+_('Restoring database from backups, do not' ' interrupt, this will happen in three stages')+'...') self.setWindowTitle(_('Restoring database')) self.l.addWidget(self.l1) self.pb = QProgressBar(self) self.l.addWidget(self.pb) self.pb.setMaximum(0) self.pb.setMinimum(0) self.msg = QLabel('') self.l.addWidget(self.msg) self.msg.setWordWrap(True) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) self.resize(self.sizeHint() + QSize(100, 50)) self.error = None self.rejected = False self.library_path = library_path self.update_signal.connect(self.do_update, type=Qt.QueuedConnection) self.restorer = Restore(library_path, self) self.restorer.daemon = True # Give the metadata backup thread time to stop QTimer.singleShot(2000, self.start) def start(self): self.restorer.start() QTimer.singleShot(10, self.update) def reject(self): self.rejected = True self.restorer.progress_callback = lambda x, y: x QDialog.reject(self) def update(self): if self.restorer.is_alive(): QTimer.singleShot(10, self.update) else: self.restorer.progress_callback = lambda x, y: x self.accept() def __call__(self, msg, step): self.update_signal.emit(msg, step) def do_update(self, msg, step): if msg is None: self.pb.setMaximum(step) else: self.msg.setText(msg) self.pb.setValue(step)
class DBCheck(QDialog): # {{{ def __init__(self, parent, db): QDialog.__init__(self, parent) self.l = QVBoxLayout() self.setLayout(self.l) self.l1 = QLabel(_('Checking database integrity')+'...') self.setWindowTitle(_('Checking database integrity')) self.l.addWidget(self.l1) self.pb = QProgressBar(self) self.l.addWidget(self.pb) self.pb.setMaximum(0) self.pb.setMinimum(0) self.msg = QLabel('') self.l.addWidget(self.msg) self.msg.setWordWrap(True) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) self.resize(self.sizeHint() + QSize(100, 50)) self.error = None self.db = db self.closed_orig_conn = False def start(self): self.user_version = self.db.user_version self.rejected = False self.db.clean() self.db.close() self.closed_orig_conn = True t = DBThread(self.db.dbpath, False) t.connect() self.conn = t.conn self.dump = self.conn.iterdump() self.statements = [] self.count = 0 self.msg.setText(_('Dumping database to SQL')) # Give the backup thread time to stop QTimer.singleShot(2000, self.do_one_dump) self.exec_() def do_one_dump(self): if self.rejected: return try: try: self.statements.append(self.dump.next()) self.count += 1 except StopIteration: self.start_load() return QTimer.singleShot(0, self.do_one_dump) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() def start_load(self): try: self.conn.close() self.pb.setMaximum(self.count) self.pb.setValue(0) self.msg.setText(_('Loading database from SQL')) self.db.close() self.ndbpath = PersistentTemporaryFile('.db') self.ndbpath.close() self.ndbpath = self.ndbpath.name t = DBThread(self.ndbpath, False) t.connect() self.conn = t.conn self.conn.execute('create temporary table temp_sequence(id INTEGER PRIMARY KEY AUTOINCREMENT)') self.conn.commit() QTimer.singleShot(0, self.do_one_load) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() def do_one_load(self): if self.rejected: return if self.count > 0: try: try: self.conn.execute(self.statements.pop(0)) except OperationalError: if self.count > 1: # The last statement in the dump could be an extra # commit, so ignore it. raise self.pb.setValue(self.pb.value() + 1) self.count -= 1 QTimer.singleShot(0, self.do_one_load) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() else: self.replace_db() def replace_db(self): self.conn.commit() self.conn.execute('pragma user_version=%d'%int(self.user_version)) self.conn.commit() self.conn.close() shutil.copyfile(self.ndbpath, self.db.dbpath) self.db = None self.accept() def break_cycles(self): self.statements = self.unpickler = self.db = self.conn = None def reject(self): self.rejected = True QDialog.reject(self)
class ProgressBar(QDialog, Logger): def __init__( self, parent=None, max_items=100, window_title="Progress Bar", label="Label goes here", frameless=True, on_top=False, ): if on_top: _flags = Qt.WindowStaysOnTopHint if frameless: _flags |= Qt.FramelessWindowHint QDialog.__init__(self, parent=parent, flags=_flags) else: _flags = Qt.Dialog if frameless: _flags |= Qt.FramelessWindowHint QDialog.__init__(self, parent=parent, flags=_flags) self.application = Application self.setWindowTitle(window_title) self.l = QVBoxLayout(self) self.setLayout(self.l) self.label = QLabel(label) self.label.setAlignment(Qt.AlignHCenter) self.l.addWidget(self.label) self.progressBar = QProgressBar(self) self.progressBar.setRange(0, max_items) self.progressBar.setMinimum(0) self.progressBar.setMaximum(0) self.progressBar.setValue(0) self.l.addWidget(self.progressBar) self.close_requested = False def closeEvent(self, event): self._log_location() self.close_requested = True def increment(self): self.progressBar.setValue(self.progressBar.value() + 1) self.refresh() def refresh(self): self.application.processEvents() def set_label(self, value): self.label.setText(value) self.label.repaint() self.refresh() def set_maximum(self, value): self.progressBar.setMaximum(value) self.refresh() def set_value(self, value): self.progressBar.setValue(value) self.progressBar.repaint() self.refresh()
class DownloadDialog(QDialog): # {{{ def __init__(self, url, fname, parent): QDialog.__init__(self, parent) self.setWindowTitle(_('Download %s') % fname) self.l = QVBoxLayout(self) self.purl = urlparse(url) self.msg = QLabel( _('Downloading <b>%(fname)s</b> from %(url)s') % dict(fname=fname, url=self.purl.netloc)) self.msg.setWordWrap(True) self.l.addWidget(self.msg) self.pb = QProgressBar(self) self.pb.setMinimum(0) self.pb.setMaximum(0) self.l.addWidget(self.pb) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel, Qt.Horizontal, self) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) sz = self.sizeHint() self.resize(max(sz.width(), 400), sz.height()) fpath = PersistentTemporaryFile(os.path.splitext(fname)[1]) fpath.close() self.fpath = fpath.name self.worker = Worker(url, self.fpath, Queue()) self.rejected = False def reject(self): self.rejected = True QDialog.reject(self) def start_download(self): self.worker.start() QTimer.singleShot(50, self.update) self.exec_() if self.worker.err is not None: error_dialog( self.parent(), _('Download failed'), _('Failed to download from %(url)r with error: %(err)s') % dict(url=self.worker.url, err=self.worker.err), det_msg=self.worker.tb, show=True) def update(self): if self.rejected: return try: progress = self.worker.rq.get_nowait() except Empty: pass else: self.update_pb(progress) if not self.worker.is_alive(): return self.accept() QTimer.singleShot(50, self.update) def update_pb(self, progress): transferred, block_size, total = progress if total == -1: self.pb.setMaximum(0) self.pb.setMinimum(0) self.pb.setValue(0) else: so_far = transferred * block_size self.pb.setMaximum(max(total, so_far)) self.pb.setValue(so_far) @property def err(self): return self.worker.err
class StatusBar(QStatusBar): def __init__(self, win): QStatusBar.__init__(self, win) self._progressLabel = QLabel() self._progressLabel.setMinimumWidth(200) self._progressLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken) self.addPermanentWidget(self._progressLabel) self.progressBar = QProgressBar(win) self.progressBar.setMaximumWidth(250) qt4todo('StatusBar.progressBar.setCenterIndicator(True)') self.addPermanentWidget(self.progressBar) self.progressBar.hide() self.simAbortButton = QToolButton(win) self.simAbortButton.setIcon( geticon("ui/actions/Simulation/Stopsign.png")) self.simAbortButton.setMaximumWidth(32) self.addPermanentWidget(self.simAbortButton) self.connect(self.simAbortButton, SIGNAL("clicked()"), self.simAbort) self.simAbortButton.hide() self.dispbarLabel = QLabel(win) #self.dispbarLabel.setFrameStyle( QFrame.Panel | QFrame.Sunken ) self.dispbarLabel.setText("Global display style:") self.addPermanentWidget(self.dispbarLabel) # Global display styles combobox self.globalDisplayStylesComboBox = GlobalDisplayStylesComboBox(win) self.addPermanentWidget(self.globalDisplayStylesComboBox) # Selection lock button. It always displays the selection lock state # and it is available to click. self.selectionLockButton = QToolButton(win) self.selectionLockButton.setDefaultAction(win.selectLockAction) self.addPermanentWidget(self.selectionLockButton) self.abortableCommands = {} #bruce 081230 debug code: ## self.connect(self, SIGNAL('messageChanged ( const QString &)'), ## self.slotMessageChanged ) ## def slotMessageChanged(self, message): # bruce 081230 debug code ## print "messageChanged: %r" % str(message) def showMessage(self, text): #bruce 081230 """ [extends superclass method] """ ## QStatusBar.showMessage(self, " ") QStatusBar.showMessage(self, text) ## print "message was set to %r" % str(self.currentMessage()) return def _f_progress_msg(self, text): #bruce 081229 refactoring """ Friend method for use only by present implementation of env.history.progress_msg. Display text in our private label widget dedicated to progress messages. """ self._progressLabel.setText(text) return def makeCommandNameUnique(self, commandName): index = 1 trial = commandName while (self.abortableCommands.has_key(trial)): trial = "%s [%d]" % (commandName, index) index += 1 return trial def addAbortableCommand(self, commandName, abortHandler): uniqueCommandName = self.makeCommandNameUnique(commandName) self.abortableCommands[uniqueCommandName] = abortHandler return uniqueCommandName def removeAbortableCommand(self, commandName): del self.abortableCommands[commandName] def simAbort(self): """ Slot for Abort button. """ if debug_flags.atom_debug and self.sim_abort_button_pressed: #bruce 060106 print "atom_debug: self.sim_abort_button_pressed is already True before we even put up our dialog" # Added confirmation before aborting as part of fix to bug 915. Mark 050824. # Bug 915 had to do with a problem if the user accidently hit the space bar or espace key, # which would call this slot and abort the simulation. This should no longer be an issue here # since we aren't using a dialog. I still like having this confirmation anyway. # IMHO, it should be kept. Mark 060106. ret = QMessageBox.warning( self, "Confirm", "Please confirm you want to abort.\n", "Confirm", "Cancel", "", 1, # The "default" button, when user presses Enter or Return (1 = Cancel) 1) # Escape (1= Cancel) if ret == 0: # Confirmed for abortHandler in self.abortableCommands.values(): abortHandler.pressed() def show_indeterminate_progress(self): value = self.progressBar.value() self.progressBar.setValue(value) def possibly_hide_progressbar_and_stop_button(self): if (len(self.abortableCommands) <= 0): self.progressBar.reset() self.progressBar.hide() self.simAbortButton.hide() def show_progressbar_and_stop_button(self, progressReporter, cmdname="<unknown command>", showElapsedTime=False): """ Display the statusbar's progressbar and stop button, and update it based on calls to the progressReporter. When the progressReporter indicates completion, hide the progressbar and stop button and return 0. If the user first presses the Stop button on the statusbar, hide the progressbar and stop button and return 1. Parameters: progressReporter - See potential implementations below. cmdname - name of command (used in some messages and in abort button tooltip) showElapsedTime - if True, display duration (in seconds) below progress bar Return value: 0 if file reached desired size, 1 if user hit abort button. """ updateInterval = .1 # seconds startTime = time.time() elapsedTime = 0 displayedElapsedTime = 0 ###e the following is WRONG if there is more than one task at a time... [bruce 060106 comment] self.progressBar.reset() self.progressBar.setMaximum(progressReporter.getMaxProgress()) self.progressBar.setValue(0) self.progressBar.show() abortHandler = AbortHandler(self, cmdname) # Main loop while progressReporter.notDoneYet(): self.progressBar.setValue(progressReporter.getProgress()) env.call_qApp_processEvents() # Process queued events (e.g. clicking Abort button, # but could be anything -- no modal dialog involved anymore). if showElapsedTime: elapsedTime = int(time.time() - startTime) if (elapsedTime != displayedElapsedTime): displayedElapsedTime = elapsedTime env.history.progress_msg("Elapsed Time: " + hhmmss_str(displayedElapsedTime)) # note: it's intentional that this doesn't directly call # self._f_progress_msg. [bruce 081229 comment] if abortHandler.getPressCount() > 0: env.history.statusbar_msg("Aborted.") abortHandler.finish() return 1 time.sleep(updateInterval) # Take a rest # End of Main loop (this only runs if it ended without being aborted) self.progressBar.setValue(progressReporter.getMaxProgress()) time.sleep( updateInterval) # Give the progress bar a moment to show 100% env.history.statusbar_msg("Done.") abortHandler.finish() return 0
class DBCheck(QDialog): # {{{ def __init__(self, parent, db): QDialog.__init__(self, parent) self.l = QVBoxLayout() self.setLayout(self.l) self.l1 = QLabel(_('Checking database integrity') + '...') self.setWindowTitle(_('Checking database integrity')) self.l.addWidget(self.l1) self.pb = QProgressBar(self) self.l.addWidget(self.pb) self.pb.setMaximum(0) self.pb.setMinimum(0) self.msg = QLabel('') self.l.addWidget(self.msg) self.msg.setWordWrap(True) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) self.resize(self.sizeHint() + QSize(100, 50)) self.error = None self.db = db self.closed_orig_conn = False def start(self): self.user_version = self.db.user_version self.rejected = False self.db.clean() self.db.conn.close() self.closed_orig_conn = True t = DBThread(self.db.dbpath, False) t.connect() self.conn = t.conn self.dump = self.conn.iterdump() self.statements = [] self.count = 0 self.msg.setText(_('Dumping database to SQL')) # Give the backup thread time to stop QTimer.singleShot(2000, self.do_one_dump) self.exec_() def do_one_dump(self): if self.rejected: return try: try: self.statements.append(self.dump.next()) self.count += 1 except StopIteration: self.start_load() return QTimer.singleShot(0, self.do_one_dump) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() def start_load(self): try: self.conn.close() self.pb.setMaximum(self.count) self.pb.setValue(0) self.msg.setText(_('Loading database from SQL')) self.db.conn.close() self.ndbpath = PersistentTemporaryFile('.db') self.ndbpath.close() self.ndbpath = self.ndbpath.name t = DBThread(self.ndbpath, False) t.connect() self.conn = t.conn self.conn.execute( 'create temporary table temp_sequence(id INTEGER PRIMARY KEY AUTOINCREMENT)' ) self.conn.commit() QTimer.singleShot(0, self.do_one_load) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() def do_one_load(self): if self.rejected: return if self.count > 0: try: try: self.conn.execute(self.statements.pop(0)) except OperationalError: if self.count > 1: # The last statement in the dump could be an extra # commit, so ignore it. raise self.pb.setValue(self.pb.value() + 1) self.count -= 1 QTimer.singleShot(0, self.do_one_load) except Exception as e: import traceback self.error = (as_unicode(e), traceback.format_exc()) self.reject() else: self.replace_db() def replace_db(self): self.conn.commit() self.conn.execute('pragma user_version=%d' % int(self.user_version)) self.conn.commit() self.conn.close() shutil.copyfile(self.ndbpath, self.db.dbpath) self.db = None self.accept() def break_cycles(self): self.statements = self.unpickler = self.db = self.conn = None def reject(self): self.rejected = True QDialog.reject(self)
class StatusBar(QStatusBar): def __init__(self, win): QStatusBar.__init__(self, win) self.statusMsgLabel = QLabel() self.statusMsgLabel.setMinimumWidth(200) self.statusMsgLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken) self.addPermanentWidget(self.statusMsgLabel) self.progressBar = QProgressBar(win) self.progressBar.setMaximumWidth(250) qt4todo("StatusBar.progressBar.setCenterIndicator(True)") self.addPermanentWidget(self.progressBar) self.progressBar.hide() self.simAbortButton = QToolButton(win) self.simAbortButton.setIcon(geticon("ui/actions/Simulation/Stopsign.png")) self.simAbortButton.setMaximumWidth(32) self.addPermanentWidget(self.simAbortButton) self.connect(self.simAbortButton, SIGNAL("clicked()"), self.simAbort) self.simAbortButton.hide() self.dispbarLabel = QLabel(win) # self.dispbarLabel.setFrameStyle( QFrame.Panel | QFrame.Sunken ) self.dispbarLabel.setText("Global display style:") self.addPermanentWidget(self.dispbarLabel) # Global display styles combobox self.globalDisplayStylesComboBox = GlobalDisplayStylesComboBox(win) self.addPermanentWidget(self.globalDisplayStylesComboBox) # Selection lock button. It always displays the selection lock state # and it is available to click. self.selectionLockButton = QToolButton(win) self.selectionLockButton.setDefaultAction(win.selectLockAction) self.addPermanentWidget(self.selectionLockButton) # Only use of this appears to be commented out in MWsemantics as of 2007/12/14 self.modebarLabel = QLabel(win) self.addPermanentWidget(self.modebarLabel) self.abortableCommands = {} def makeCommandNameUnique(self, commandName): index = 1 trial = commandName while self.abortableCommands.has_key(trial): trial = "%s [%d]" % (commandName, index) index += 1 return trial def addAbortableCommand(self, commandName, abortHandler): uniqueCommandName = self.makeCommandNameUnique(commandName) self.abortableCommands[uniqueCommandName] = abortHandler return uniqueCommandName def removeAbortableCommand(self, commandName): del self.abortableCommands[commandName] def simAbort(self): """ Slot for Abort button. """ if debug_flags.atom_debug and self.sim_abort_button_pressed: # bruce 060106 print "atom_debug: self.sim_abort_button_pressed is already True before we even put up our dialog" # Added confirmation before aborting as part of fix to bug 915. Mark 050824. # Bug 915 had to do with a problem if the user accidently hit the space bar or espace key, # which would call this slot and abort the simulation. This should no longer be an issue here # since we aren't using a dialog. I still like having this confirmation anyway. # IMHO, it should be kept. Mark 060106. ret = QMessageBox.warning( self, "Confirm", "Please confirm you want to abort.\n", "Confirm", "Cancel", "", 1, # The "default" button, when user presses Enter or Return (1 = Cancel) 1, ) # Escape (1= Cancel) if ret == 0: # Confirmed for abortHandler in self.abortableCommands.values(): abortHandler.pressed() def show_indeterminate_progress(self): value = self.progressBar.value() self.progressBar.setValue(value) def possibly_hide_progressbar_and_stop_button(self): if len(self.abortableCommands) <= 0: self.progressBar.reset() self.progressBar.hide() self.simAbortButton.hide() def show_progressbar_and_stop_button(self, progressReporter, cmdname="<unknown command>", showElapsedTime=False): """ Display the statusbar's progressbar and stop button, and update it based on calls to the progressReporter. When the progressReporter indicates completion, hide the progressbar and stop button and return 0. If the user first presses the Stop button on the statusbar, hide the progressbar and stop button and return 1. Parameters: progressReporter - See potential implementations below. cmdname - name of command (used in some messages and in abort button tooltip) showElapsedTime - if True, display duration (in seconds) below progress bar Return value: 0 if file reached desired size, 1 if user hit abort button. """ updateInterval = 0.1 # seconds startTime = time.time() elapsedTime = 0 displayedElapsedTime = 0 ###e the following is WRONG if there is more than one task at a time... [bruce 060106 comment] self.progressBar.reset() self.progressBar.setMaximum(progressReporter.getMaxProgress()) self.progressBar.setValue(0) self.progressBar.show() abortHandler = AbortHandler(self, cmdname) # Main loop while progressReporter.notDoneYet(): self.progressBar.setValue(progressReporter.getProgress()) env.call_qApp_processEvents() # Process queued events (e.g. clicking Abort button, # but could be anything -- no modal dialog involved anymore). if showElapsedTime: elapsedTime = int(time.time() - startTime) if elapsedTime != displayedElapsedTime: displayedElapsedTime = elapsedTime env.history.progress_msg("Elapsed Time: " + hhmmss_str(displayedElapsedTime)) if abortHandler.getPressCount() > 0: env.history.statusbar_msg("Aborted.") abortHandler.finish() return 1 time.sleep(updateInterval) # Take a rest # End of Main loop (this only runs if it ended without being aborted) self.progressBar.setValue(progressReporter.getMaxProgress()) time.sleep(updateInterval) # Give the progress bar a moment to show 100% env.history.statusbar_msg("Done.") abortHandler.finish() return 0
class DownloadDialog(QDialog): # {{{ def __init__(self, url, fname, parent): QDialog.__init__(self, parent) self.setWindowTitle(_('Download %s')%fname) self.l = QVBoxLayout(self) self.purl = urlparse(url) self.msg = QLabel(_('Downloading <b>%(fname)s</b> from %(url)s')%dict( fname=fname, url=self.purl.netloc)) self.msg.setWordWrap(True) self.l.addWidget(self.msg) self.pb = QProgressBar(self) self.pb.setMinimum(0) self.pb.setMaximum(0) self.l.addWidget(self.pb) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel, Qt.Horizontal, self) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) sz = self.sizeHint() self.resize(max(sz.width(), 400), sz.height()) fpath = PersistentTemporaryFile(os.path.splitext(fname)[1]) fpath.close() self.fpath = fpath.name self.worker = Worker(url, self.fpath, Queue()) self.rejected = False def reject(self): self.rejected = True QDialog.reject(self) def start_download(self): self.worker.start() QTimer.singleShot(50, self.update) self.exec_() if self.worker.err is not None: error_dialog(self.parent(), _('Download failed'), _('Failed to download from %(url)r with error: %(err)s')%dict( url=self.worker.url, err=self.worker.err), det_msg=self.worker.tb, show=True) def update(self): if self.rejected: return try: progress = self.worker.rq.get_nowait() except Empty: pass else: self.update_pb(progress) if not self.worker.is_alive(): return self.accept() QTimer.singleShot(50, self.update) def update_pb(self, progress): transferred, block_size, total = progress if total == -1: self.pb.setMaximum(0) self.pb.setMinimum(0) self.pb.setValue(0) else: so_far = transferred * block_size self.pb.setMaximum(max(total, so_far)) self.pb.setValue(so_far) @property def err(self): return self.worker.err
class Pradio(QDialog): def __init__(self, parent=None): super(Pradio, self).__init__(parent) # logo................................... self.label = QLabel() self.pixmap = QPixmap('/usr/share/pradyo/plogo.png') self.label.setPixmap(self.pixmap) #/usr/share/pradyo/pradyo.py # progress barr..................................... self.bar =QProgressBar() self.bar.setMinimum(0) self.bar.setMaximum(100) self.bar.setValue(40) #label........................................... self.lcd = QLCDNumber(3) self.lcd.display('5') self.lcd.resize(50,50) # button.............................................. self.Btn1=QPushButton('Kiss FM') self.Btn2=QPushButton('Real FM') self.Btn3=QPushButton('Venus FM') self.Btn4=QPushButton('Kiss FM') self.Btn5=QPushButton('Nova FM') self.Btn6=QPushButton('Son FM') self.connect(self.Btn1, SIGNAL('clicked()'),partial(self.play,self.Btn1.text())) self.connect(self.Btn2, SIGNAL('clicked()'),partial(self.play,self.Btn2.text())) self.connect(self.Btn3, SIGNAL('clicked()'),partial(self.play,self.Btn3.text())) self.connect(self.Btn4, SIGNAL('clicked()'),partial(self.play,self.Btn4.text())) self.connect(self.Btn5, SIGNAL('clicked()'),partial(self.play,self.Btn5.text())) self.connect(self.Btn6, SIGNAL('clicked()'),partial(self.play,self.Btn6.text())) # ses buttonu........................................ self.dial = QDial() self.dial.setValue(30) self.connect(self.dial, SIGNAL("valueChanged(int)"),self.VolumeChange) self.dial.setNotchesVisible(True) # oynatma tuslarii...................................... self.PlayBtn = QtGui.QPushButton('', self) self.PlayBtn.setIcon(QtGui.QIcon('/usr/share/pradyo/a.png')) self.PlayBtn.setIconSize(QtCore.QSize(48,48)) # self.PlayBtn.clicked.connect(self.play) self.PlayBtn.setFlat(True) self.StopBtn = QtGui.QPushButton('', self) self.StopBtn.setIcon(QtGui.QIcon('/usr/share/pradyo/s.png')) self.StopBtn.setIconSize(QtCore.QSize(48,48)) self.StopBtn.setFlat(True) self.StopBtn.clicked.connect(self.stop_radio) # layout............................ grid = QGridLayout() grid.addWidget(self.PlayBtn,0,1) grid.addWidget(self.StopBtn,0,2) grid.addWidget(self.Btn1,1, 0, 3, 1) grid.addWidget(self.Btn2,1, 0, 7, 1) grid.addWidget(self.Btn3,1, 0, 11, 1) grid.addWidget(self.Btn4,1, 1, 3, 1) grid.addWidget(self.Btn5,1, 1, 7, 1) grid.addWidget(self.Btn6,1, 1, 11, 1) grid.addWidget(self.dial, 0, 4, 2, 1) grid.addWidget(self.label,0,0,1,1) self.setLayout(grid) self.setWindowTitle('Pradyo') self.setFixedSize(650, 300) def VolumeChange(self): VolumeChange=self.dial.value() print(VolumeChange) player.set_property('volume', VolumeChange/100.0) def play(self,value): deg =str(value) player.set_state(gst.STATE_NULL) # print(value) # music_stream_uri=music_station[value] # print(music_stream_uri) music =music_station[deg] print(str(music)) player.set_property('uri',music) player.set_state(gst.STATE_PLAYING) self.PlayBtn.setIcon(QtGui.QIcon('/usr/share/pradyo/a.png')) self.PlayBtn.setIconSize(QtCore.QSize(48,48)) def stop_radio(self): print ("Radio stops") player.set_state(gst.STATE_NULL) self.PlayBtn.setIcon(QtGui.QIcon('/usr/share/pradyo/d.png')) self.PlayBtn.setIconSize(QtCore.QSize(48,48)) def Close(self): self.close()