class PMessageBox(PAbstractBox): # STYLE SHEET STYLE = """color:white;font-size:16pt;""" OUT_POS = MIDCENTER IN_POS = MIDCENTER STOP_POS = MIDCENTER def __init__(self, parent): PAbstractBox.__init__(self, parent) self.ui = Ui_MessageBox() self.ui.setupUi(self) self.busy = QProgressIndicator(self, "white") self.busy.setMinimumSize(QSize(32, 32)) self.busy.hide() self.ui.mainLayout.insertWidget(1, self.busy) self._animation = 2 self._duration = 1 self.last_msg = None self.setStyleSheet(PMessageBox.STYLE) self.enableOverlay() self.setOverlayOpacity(150) self.hide() def showMessage(self, message, icon=None, busy=False): self.ui.label.setText(message) if busy: self.busy.busy() self.ui.icon.hide() else: if icon: if type(icon) == str: icon = KIcon(icon).pixmap(32, 32) self.ui.icon.setPixmap(QPixmap(icon)) self.ui.icon.show() else: self.ui.icon.hide() self.busy.hide() self.last_msg = self.animate(start=PMessageBox.IN_POS, stop=PMessageBox.STOP_POS) qApp.processEvents() # ??? def hideMessage(self, force=False): if self.isVisible() or force: self.animate(start=PMessageBox.STOP_POS, stop=PMessageBox.OUT_POS, direction=OUT, dont_animate=True)
class PMessageBox(PAbstractBox): # STYLE SHEET STYLE = """color:white;font-size:16pt;""" OUT_POS = MIDCENTER IN_POS = MIDCENTER STOP_POS = MIDCENTER def __init__(self, parent): PAbstractBox.__init__(self, parent) self.ui = Ui_MessageBox() self.ui.setupUi(self) self.busy = QProgressIndicator(self, "white") self.busy.setMinimumSize(QtCore.QSize(32, 32)) self.busy.hide() self.ui.mainLayout.insertWidget(1, self.busy) self._animation = 2 self._duration = 1 self.last_msg = None self.setStyleSheet(PMessageBox.STYLE) self.enableOverlay() self.setOverlayOpacity(150) self.hide() def showMessage(self, message, icon = None, busy = False): self.ui.label.setText(message) if busy: self.busy.busy() self.ui.icon.hide() else: if icon: if type(icon) == str: icon = QIcon(icon).pixmap(32,32) self.ui.icon.setPixmap(QtGui.QPixmap(icon)) self.ui.icon.show() else: self.ui.icon.hide() self.busy.hide() self.last_msg = self.animate(start = PMessageBox.IN_POS, stop = PMessageBox.STOP_POS) QtWidgets.qApp.processEvents() def hideMessage(self, force = False): if self.isVisible() or force: self.animate(start = PMessageBox.STOP_POS, stop = PMessageBox.OUT_POS, direction = OUT, dont_animate = True)
class ServiceItemWidget(QtGui.QWidget): def __init__(self, package, parent, item): QtGui.QWidget.__init__(self, None) self.ui = Ui_ServiceItemWidget() self.ui.setupUi(self) self.busy = QProgressIndicator(self) self.busy.setMinimumSize(QtCore.QSize(32, 32)) self.ui.mainLayout.insertWidget(0, self.busy) self.ui.spacer.hide() self.busy.hide() self.ui.labelName.setText(package) self.toggleButtons() self.ui.buttonStart.setIcon(KIcon("media-playback-start")) self.ui.buttonStop.setIcon(KIcon("media-playback-stop")) self.ui.buttonReload.setIcon(KIcon("view-refresh")) self.ui.buttonInfo.setIcon(KIcon("dialog-information")) self.toggled = False self.root = parent self.iface = parent.iface self.item = item self.package = package self.info = ServiceItemInfo(self) self.type = None self.desc = None self.connect(self.ui.buttonStart, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonStop, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonReload, SIGNAL("clicked()"), self.setService) self.connect(self.ui.checkStart, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonInfo, SIGNAL("clicked()"), self.info.showDescription) def updateService(self, data, firstRun): self.type, self.desc, serviceState = data self.setState(serviceState, firstRun) self.ui.labelDesc.setText(self.desc) def setState(self, state, firstRun=False): if not firstRun: # There is a raise condition, FIXME in System.Service time.sleep(1) state = self.iface.info(self.package)[2] if state in ('on', 'started', 'conditional_started'): self.running = True icon = 'flag-green' else: self.running = False icon = 'flag-black' self.ui.buttonStop.setEnabled(self.running) self.ui.buttonReload.setEnabled(self.running) self.ui.labelStatus.setPixmap(KIcon(icon).pixmap(32, 32)) self.showStatus() self.runningAtStart = False if state in ('on', 'stopped'): self.runningAtStart = True elif state in ('off', 'started', 'conditional_started'): self.runningAtStart = False self.ui.checkStart.setChecked(self.runningAtStart) self._last_state = self.ui.checkStart.isChecked() # print self.package, state def setService(self): try: self.showBusy() self._last_state = not self.ui.checkStart.isChecked() if self.sender() == self.ui.buttonStart: self.iface.start(self.package) elif self.sender() == self.ui.buttonStop: self.iface.stop(self.package) elif self.sender() == self.ui.buttonReload: self.iface.restart(self.package) elif self.sender() == self.ui.checkStart: self.iface.setEnable(self.package, self.ui.checkStart.isChecked()) except Exception, msg: self.showStatus() self.root.showFail(msg)
class ServiceItemWidget(QtGui.QWidget): def __init__(self, package, parent, item): QtGui.QWidget.__init__(self, None) self.ui = Ui_ServiceItemWidget() self.ui.setupUi(self) self.busy = QProgressIndicator(self) self.busy.setMinimumSize(QtCore.QSize(32, 32)) self.ui.mainLayout.insertWidget(0, self.busy) self.ui.spacer.hide() self.busy.hide() self.ui.labelName.setText(package) self.toggleButtons() self.ui.buttonStart.setIcon(KIcon("media-playback-start")) self.ui.buttonStop.setIcon(KIcon("media-playback-stop")) self.ui.buttonReload.setIcon(KIcon("view-refresh")) self.ui.buttonInfo.setIcon(KIcon("dialog-information")) self.toggled = False self.root = parent self.iface = parent.iface self.item = item self.package = package self.info = ServiceItemInfo(self) self.type = None self.desc = None self.connect(self.ui.buttonStart, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonStop, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonReload, SIGNAL("clicked()"), self.setService) self.connect(self.ui.checkStart, SIGNAL("clicked()"), self.setService) self.connect(self.ui.buttonInfo, SIGNAL("clicked()"), self.info.showDescription) def updateService(self, data, firstRun): self.type, self.desc, serviceState = data self.setState(serviceState, firstRun) self.ui.labelDesc.setText(self.desc) def setState(self, state, firstRun=False): if not firstRun: # There is a raise condition, FIXME in System.Service time.sleep(1) state = self.iface.info(self.package)[2] if state in ('on', 'started', 'conditional_started'): self.running = True icon = 'flag-green' else: self.running = False icon = 'flag-black' self.ui.buttonStop.setEnabled(self.running) self.ui.buttonReload.setEnabled(self.running) self.ui.labelStatus.setPixmap(KIcon(icon).pixmap(32, 32)) self.showStatus() self.runningAtStart = False if state in ('on', 'stopped'): self.runningAtStart = True elif state in ('off', 'started', 'conditional_started'): self.runningAtStart = False self.ui.checkStart.setChecked(self.runningAtStart) self._last_state = self.ui.checkStart.isChecked() # print self.package, state def setService(self): try: self.showBusy() self._last_state = not self.ui.checkStart.isChecked() if self.sender() == self.ui.buttonStart: self.iface.start(self.package) elif self.sender() == self.ui.buttonStop: self.iface.stop(self.package) elif self.sender() == self.ui.buttonReload: self.iface.restart(self.package) elif self.sender() == self.ui.checkStart: self.iface.setEnable(self.package, self.ui.checkStart.isChecked()) except Exception, msg: self.showStatus() self.root.showFail(msg)
class ProgressDialog(PAbstractBox, Ui_ProgressDialog): def __init__(self, state, parent=None): PAbstractBox.__init__(self, parent) self.iface = backend.pm.Iface() self.state = state self.setupUi(self) self.busy = QProgressIndicator(self, "white") self.busy.setMinimumSize(QSize(48, 48)) self.mainLayout.addWidget(self.busy) # PDS Settings self._animation = 2 self._duration = 1 self.last_msg = None self.enableOverlay() self.setOverlayOpacity(150) self._disable_parent_in_shown = True self.registerFunction(FINISHED, self.busy.startAnimation) self.registerFunction(OUT, self.busy.stopAnimation) self.cancelButton.clicked.connect(self.cancel) self.cancelButton.setIcon(QIcon.fromTheme("list-remove")) self.parent = parent self.widget.setStyleSheet("QTextEdit { \ background:rgba(0,0,0,0); \ color:white;}") self._last_action = '' self._shown = False def _show(self): self.animate(start=MIDCENTER, stop=MIDCENTER) self._shown = True print("start") def _hide(self): if self._shown: self.animate(direction=OUT, start=MIDCENTER, stop=MIDCENTER) self.parent.setWindowTitle( _translate("Package Manager", "Package Manager")) self._shown = False def updateProgress(self, progress): self.busy.stopAnimation() self.busy.hide() self.widget.show() if not self.isVisible(): if not self.parent.cw._started: self.disableCancel() self._show() self.progressBar.setValue(progress) self.percentage.setText( _translate("Package Manager", "<p align='right'>{0} %</p>").format(progress)) self.parent.setWindowTitle( _translate("Package Manager", "Operation - {0}%").format(progress)) def updateOperation(self, operation, arg): if operation in [ _translate("Package Manager", "configuring"), _translate("Package Manager", "extracting") ]: self.disableCancel() if operation == "updatingrepo": operationInfo = _translate( "Package Manager", "Downloading package list of {0}").format(arg) else: operationInfo = _translate("Package Manager", '{0} {1}').format(operation, arg) self.operationInfo.setText(operationInfo) def updateStatus(self, packageNo, totalPackages, operation): text = _translate("Package Manager", "[{0} / {1}]").format(packageNo, totalPackages) self.actionLabel.setText("%s %s" % (text, self._last_action)) def updateRemainingTime(self, time): self.timeRemaining.setText("<p align='right'>%s</p>" % time) def updateCompletedInfo(self, completed, total, rate): text = _translate("Package Manager", "{0} / {1}, {2}").format(completed, total, rate) self.completedInfo.setText(text) def updateActionLabel(self, action): self.actionLabel.setText("<i>%s</i>" % self.state.getActionCurrent(action)) self._last_action = self.actionLabel.toPlainText() def enableCancel(self): self.cancelButton.setEnabled(True) def disableCancel(self): self.cancelButton.setEnabled(False) def reset(self): self.widget.hide() self.busy.show() self.actionLabel.setText( _translate("Package Manager", "Preparing PiSi...")) self.progressBar.setValue(0) self.operationInfo.setText("") self.completedInfo.setText("") self.timeRemaining.setText("<p align='right'>--:--:--</p>") self.timeRemaining.show() def cancel(self): self.widget.hide() self.busy.show() self.actionLabel.setText( _translate("Package Manager", "<b>Cancelling operation...</b>")) self.disableCancel() QTimer.singleShot(100, self.iface.cancel) def repoOperationView(self): self.timeRemaining.setText("") self.timeRemaining.hide()
class ProgressDialog(PAbstractBox, Ui_ProgressDialog): def __init__(self, state, parent=None): PAbstractBox.__init__(self, parent) self.iface = backend.pm.Iface() self.state = state self.setupUi(self) self.busy = QProgressIndicator(self, "white") self.busy.setMinimumSize(QSize(48, 48)) self.mainLayout.addWidget(self.busy) # PDS Settings self._animation = 2 self._duration = 1 self.last_msg = None self.enableOverlay() self.setOverlayOpacity(150) self._disable_parent_in_shown = True self.registerFunction(FINISHED, self.busy.startAnimation) self.registerFunction(OUT, self.busy.stopAnimation) self.connect(self.cancelButton, SIGNAL("clicked()"), self.cancel) self.cancelButton.setIcon(KIcon("cancel")) self.parent = parent self.setStyleSheet("QLabel, QTextEdit, QTextBrowser{background:rgba(0,0,0,0);color:white;}") self._last_action = '' self._shown = False def _show(self): self.animate(start = MIDCENTER, stop = MIDCENTER) self._shown = True def _hide(self): if self._shown: self.animate(direction = OUT, start = MIDCENTER, stop = MIDCENTER) self.parent.setWindowTitle(i18n("Package Manager")) self._shown = False def updateProgress(self, progress): self.busy.stopAnimation() self.busy.hide() self.widget.show() if not self.isVisible(): if not self.parent.cw._started: self.disableCancel() self._show() self.progressBar.setValue(progress) self.percentage.setText(i18n("<p align='right'>%1 %</p>", progress)) self.parent.setWindowTitle(i18n("Operation - %1%", progress)) def updateOperation(self, operation, arg): if operation in [i18n("configuring"), i18n("extracting")]: self.disableCancel() if operation == "updatingrepo": operationInfo = i18n("Downloading package list of %1", arg) else: operationInfo = i18n('%1 %2', operation, arg) self.operationInfo.setText(operationInfo) def updateStatus(self, packageNo, totalPackages, operation): text = i18n("[%1 / %2]", packageNo, totalPackages) self.actionLabel.setText("%s %s" % (text, self._last_action)) def updateRemainingTime(self, time): self.timeRemaining.setText("<p align='right'>%s</p>" % time) def updateCompletedInfo(self, completed, total, rate): text = i18n("%1 / %2, %3", completed, total, rate) self.completedInfo.setText(text) def updateActionLabel(self, action): self.actionLabel.setText("<i>%s</i>" % self.state.getActionCurrent(action)) self._last_action = self.actionLabel.toPlainText() def enableCancel(self): self.cancelButton.setEnabled(True) def disableCancel(self): self.cancelButton.setEnabled(False) def reset(self): self.widget.hide() self.busy.show() self.actionLabel.setText(i18n("Preparing PiSi...")) self.progressBar.setValue(0) self.operationInfo.setText("") self.completedInfo.setText("") self.timeRemaining.setText("<p align='right'>--:--:--</p>") self.timeRemaining.show() def cancel(self): self.widget.hide() self.busy.show() self.actionLabel.setText(i18n("<b>Cancelling operation...</b>")) self.disableCancel() QTimer.singleShot(100, self.iface.cancel) def repoOperationView(self): self.timeRemaining.setText("") self.timeRemaining.hide()
class ConnectionItem(QtWidgets.QWidget, Ui_ConnectionItem): def __init__(self, parent, connection): QtWidgets.QWidget.__init__(self, parent) self.setupUi(self) self.available = True self.parent = parent self.connection = connection bus = parent.bus.get_object(NM_BUS_NAME, str(connection.proxy.object_path)) interface = dbus.Interface(bus, NM_SETTINGS_CONNECTION) interface.connect_to_signal("Removed", parent.fillConnections) interface.connect_to_signal("Updated", self.updateState) self.busy = QProgressIndicator(self) self.busy.setMinimumSize(QSize(32, 32)) self.mainLayout.insertWidget(0, self.busy) self.busy.hide() self.connect(parent, SIGNAL("stateChanged()"), self.updateState) self.button.clicked.connect(lambda: self.parent.setState(self)) self.updateState() self.toggleButtons() def updateState(self, *args): if self.available is not True: return active = self.parent.isActive(self.connection) if active: state = self.parent.getState(self.connection) if state == ActiveConnectionState.ACTIVATED.value: self.setIcon(get_icon(self.connection.settings.conn_type, True)) elif state == ActiveConnectionState.ACTIVATING.value: self.showBusy() else: self.setIcon(get_icon(self.connection.settings.conn_type, False)) self.name.setText(unicode(self.connection.settings.id)) self.details.setText(unicode(self.connection.settings.conn_type)) self.button.setText("Disconnect" if active else "Connect") def showBusy(self): self.busy.busy() self.icon.hide() def setIcon(self, icon): self.busy.hide() self.icon.setPixmap(icon) self.icon.show() def resizeEvent(self, event): if self.parent.msgbox: self.parent.msgbox._resizeCallBacks(event) def enterEvent(self, event): if not self.button.isVisible(): self.toggleButtons(True) def leaveEvent(self, event): if self.button.isVisible(): self.toggleButtons() def toggleButtons(self, toggle=False): self.button.setVisible(toggle)
class ProgressDialog(PAbstractBox, Ui_ProgressDialog): def __init__(self, state, parent=None): PAbstractBox.__init__(self, parent) self.iface = backend.pm.Iface() self.state = state self.setupUi(self) self.busy = QProgressIndicator(self, "white") self.busy.setMinimumSize(QSize(48, 48)) self.mainLayout.addWidget(self.busy) # PDS Settings self._animation = 2 self._duration = 500 self.last_msg = None self.enableOverlay() self._disable_parent_in_shown = True self.registerFunction(FINISHED, self.busy.startAnimation) self.registerFunction(OUT, self.busy.stopAnimation) self.connect(self.cancelButton, SIGNAL("clicked()"), self.cancel) self.parent = parent self.setStyleSheet( "QLabel, QTextEdit, QTextBrowser{background:rgba(0,0,0,0);color:white;}" ) self._last_action = '' self._shown = False def _show(self): self.animate(start=MIDCENTER, stop=MIDCENTER) self._shown = True def _hide(self): if self._shown: self.animate(direction=OUT, start=MIDCENTER, stop=MIDCENTER) self.parent.setWindowTitle(i18n("Package Manager")) self._shown = False def updateProgress(self, progress): self.busy.stopAnimation() self.busy.hide() self.widget.show() if not self.isVisible(): if not self.parent.cw._started: self.disableCancel() self._show() self.progressBar.setValue(progress) self.percentage.setText(i18n("<p align='right'>%1 %</p>", progress)) self.parent.setWindowTitle(i18n("Operation - %1%", progress)) def updateOperation(self, operation, arg): if operation in [i18n("configuring"), i18n("extracting")]: self.disableCancel() if operation == "updatingrepo": operationInfo = i18n("Downloading package list of %1", arg) else: operationInfo = i18n('%1 %2', operation, arg) self.operationInfo.setText(operationInfo) def updateStatus(self, packageNo, totalPackages, operation): text = i18n("[%1 / %2]", packageNo, totalPackages) self.actionLabel.setText("%s %s" % (text, self._last_action)) def updateRemainingTime(self, time): self.timeRemaining.setText("<p align='right'>%s</p>" % time) def updateCompletedInfo(self, completed, total, rate): text = i18n("%1 / %2, %3", completed, total, rate) self.completedInfo.setText(text) def updateActionLabel(self, action): self.actionLabel.setText("<i>%s</i>" % self.state.getActionCurrent(action)) self._last_action = self.actionLabel.toPlainText() def enableCancel(self): self.cancelButton.setEnabled(True) def disableCancel(self): self.cancelButton.setEnabled(False) def reset(self): self.widget.hide() self.busy.show() self.actionLabel.setText(i18n("Preparing PiSi...")) self.progressBar.setValue(0) self.operationInfo.setText("") self.completedInfo.setText("") self.timeRemaining.setText("<p align='right'>--:--:--</p>") self.timeRemaining.show() def cancel(self): self.widget.hide() self.busy.show() self.actionLabel.setText(i18n("<b>Cancelling operation...</b>")) self.disableCancel() QTimer.singleShot(100, self.iface.cancel) def repoOperationView(self): self.timeRemaining.setText("") self.timeRemaining.hide()
class ConnectionItem(QtGui.QWidget, Ui_ConnectionItem): def __init__(self, parent, connection): QtGui.QWidget.__init__(self, parent) self.setupUi(self) self.available = True self.parent = parent self.connection = connection bus = parent.bus.get_object(NM_BUS_NAME, str(connection.proxy.object_path)) interface = dbus.Interface(bus, NM_SETTINGS_CONNECTION) interface.connect_to_signal("Removed", parent.fillConnections) interface.connect_to_signal("Updated", self.updateState) self.busy = QProgressIndicator(self) self.busy.setMinimumSize(QSize(32, 32)) self.mainLayout.insertWidget(0, self.busy) self.busy.hide() self.connect(parent, SIGNAL("stateChanged()"), self.updateState) self.button.clicked.connect(lambda: self.parent.setState(self)) self.updateState() self.toggleButtons() def updateState(self, *args): if self.available is not True: return active = self.parent.isActive(self.connection) if active: state = self.parent.getState(self.connection) if state == ActiveConnectionState.ACTIVATED.value: self.setIcon(get_icon(self.connection.settings.conn_type, True)) elif state == ActiveConnectionState.ACTIVATING.value: self.showBusy() else: self.setIcon(get_icon(self.connection.settings.conn_type, False)) self.name.setText(unicode(self.connection.settings.id)) self.details.setText(unicode(self.connection.settings.conn_type)) self.button.setText("Disconnect" if active else "Connect") def showBusy(self): self.busy.busy() self.icon.hide() def setIcon(self, icon): self.busy.hide() self.icon.setPixmap(icon) self.icon.show() def resizeEvent(self, event): if self.parent.msgbox: self.parent.msgbox._resizeCallBacks(event) def enterEvent(self, event): if not self.button.isVisible(): self.toggleButtons(True) def leaveEvent(self, event): if self.button.isVisible(): self.toggleButtons() def toggleButtons(self, toggle=False): self.button.setVisible(toggle)