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()
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 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 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 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()