def done(self, result): self.saveDialogSize(config("dialogsize")) self.saveCompletions() self.settings.saveConfig() if result: # indent the text again using the user (document) settings: text = self.builder().ly() text = self.mainwin.currentDocument().indent(text) self.mainwin.view().insertText(text) KPageDialog.done(self, result)
def showConfigurationInterface(self): dialog = KPageDialog() dialog.setFaceType(KPageDialog.Plain) dialog.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel)) self.createConfigurationInterface(dialog) dialog.resize(400,300) dialog.exec_()
def showConfigurationInterface(self): self.dialog = KPageDialog() self.dialog.setModal(True) self.dialog.setFaceType(KPageDialog.List) self.dialog.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel)) self.createConfigurationInterface(self.dialog) self.dialog.move(self.popupPosition(self.dialog.sizeHint())) self.dialog.exec_()
def __init__(self, mainwin): KPageDialog.__init__(self, mainwin) self.mainwin = mainwin self.setFaceType(KPageDialog.Tabbed) self.setButtons(KPageDialog.ButtonCode( KPageDialog.Try | KPageDialog.Help | KPageDialog.Ok | KPageDialog.Cancel | KPageDialog.Default)) self.setButtonIcon(KPageDialog.Try, KIcon("run-lilypond")) self.enableButton(KPageDialog.Try, False) self.setCaption(i18n("Score Setup Wizard")) self.setHelp("scorewiz") self.completableWidgets = {} self.titles = Titles(self) self.parts = Parts(self) self.settings = Settings(self) self.loadCompletions() self.restoreDialogSize(config("dialogsize")) self.defaultClicked.connect(self.default) self.tryClicked.connect(self.previewScore)
def __init__(self, mainwin): KPageDialog.__init__(self, mainwin) self.setAttribute(Qt.WA_DeleteOnClose) self.mainwin = mainwin self.setFaceType(KPageDialog.Tree) self.setButtons( KPageDialog.ButtonCode( KPageDialog.Reset | KPageDialog.Default | KPageDialog.Apply | KPageDialog.Ok | KPageDialog.Cancel | KPageDialog.Help ) ) self.setCaption(i18n("Configure")) self.setHelp("settings-dialog") self.setDefaultButton(KPageDialog.Ok) self.applyClicked.connect(self.saveSettings) self.defaultClicked.connect(self.slotDefaultClicked) self.resetClicked.connect(self.loadSettings) self.currentPageChanged.connect(self.slotCurrentPageChanged) self.pages = [ GeneralPreferences(self), LilyPondPreferences(self), Commands(self), RumorSettings(self), EditorComponent(self), ] self.loadSettings() # make icons in tree somewhat larger tree = self.findChild(QTreeView) if tree: tree.setIconSize(QSize(22, 22)) # restore our dialog size self.restoreDialogSize(config("settings dialog")) self.finished.connect(lambda: self.saveDialogSize(config("settings dialog")))
class plasmaGreatAdvice(plasmascript.Applet): def __init__(self, parent=None): plasmascript.Applet.__init__(self, parent) self.kdehome = "/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-motivator/contents/" self.Settings = QSettings("kde-plasma-motivator", "kde-plasma-motivator") self.initVar() if os.path.exists(self.kdehome + "icons/advice.png"): self.iconPath = self.kdehome + "icons/advice.png" else: self.iconPath = os.getcwd() + "/kde-plasma-motivator/contents/icons/advice.png" def initVar(self): self.timeout = self.Settings.value("TimeOut", 300).toInt()[0] self.autoclose = self.Settings.value("AutoClose", 3).toInt()[0] self.popup = self.Settings.value("PopUp", 1).toInt()[0] self.iconText = self.Settings.value("IconText", 1).toInt()[0] self.popupColor = self.Settings.value("PopUpColor", "red").toString() self.iconTextColor = self.Settings.value("IconTextColor", "blue").toString() def initLayout(self): if "layout" in dir(self): count = self.layout.count() for i in xrange(count): item = self.layout.itemAt(count - 1 - i) self.layout.removeAt(count - 1 - i) item = None self.adviceIcon = Plasma.IconWidget() self.adviceIcon.setIcon(self.iconPath) if bool(self.popup): self.adviceIcon.clicked.connect(self.show_n_hide) if self.applet.formFactor() == Plasma.Horizontal: self.adviceIcon.setOrientation(Qt.Horizontal) self.layout.setOrientation(Qt.Horizontal) self.layout.addItem(self.adviceIcon) else: self.adviceIcon.setOrientation(Qt.Vertical) self.layout.setOrientation(Qt.Vertical) if bool(self.popup): self.layout.addItem(self.adviceIcon) if bool(self.iconText): self.adviceLabel = Plasma.Label() self.adviceLabel.setScaledContents(True) self.adviceLabel.setAlignment(Qt.AlignCenter) self.layout.addItem(self.adviceLabel) self.adviceIcon.setTextBackgroundColor(QColor(self.iconTextColor)) self.layout.setAlignment(self.adviceIcon, Qt.AlignLeft) self.setLayout(self.layout) def init(self): self.layout = QGraphicsLinearLayout(self.applet) self.layout.setSpacing(0) self.initLayout() self.setHasConfigurationInterface(True) Plasma.ToolTipManager.self().setContent( self.applet, Plasma.ToolTipContent("Great Advice\nMotivator", QString(""), QIcon(self.iconPath)) ) self.onceTimer = QTimer() self.onceTimer.timeout.connect(self.showAdvice) self.onceTimer.setSingleShot(True) self.onceTimer.start() self.Timer = QTimer() self.Timer.timeout.connect(self.showAdvice) self.Timer.start(self.timeout * 1000) def getNewText(self): fileName = randomString(24) Data = QStringList() if os.path.exists(self.kdehome + "code/getText.sh"): Data.append(self.kdehome + "code/getText.sh") else: Data.append(os.getcwd() + "/kde-plasma-motivator/contents/code/getText.sh") Data.append(fileName) getAdsviceThread = QProcess() start, pid = getAdsviceThread.startDetached("/bin/sh", Data, os.getcwd()) return fileName, start, pid def preparedData(self): if "Control" in dir(self): self.Control.close() fileName, start, pid = self.getNewText() if start: i = 0 while pid_exists(pid, 0): time.sleep(0.1) i += 1 """ inhibits connect """ if i > 100: pid_exists(pid, 9) if os.path.exists("/dev/shm/" + fileName): with open("/dev/shm/" + fileName, "rb") as f: data = f.read() os.remove("/dev/shm/" + fileName) """ text is absent, may be no connect """ if data == "": data = "Проверь коннект, ёпта! (Авт.)" """ brocken text, may be low connect """ if data.startswith("<span class="): data = "Смени блять провайдера! (Авт.)" else: data = "WARNING: Getting Advice Error" else: data = "WARNING: Bad command for getting Advice" return data def showAdvice(self): data = self.preparedData() # print data text = QString().fromUtf8(data) if bool(self.popup): self.adviceIcon.setIcon(self.iconPath) self.Control = ControlWidget(text, self.autoclose, self, self.popupColor) self.Control.show() elif not bool(self.popup) and not bool(self.iconText): self.adviceIcon.setIcon(self.iconPath) else: self.adviceIcon.setIcon("") if self.applet.formFactor() == Plasma.Horizontal: if bool(self.iconText): self.adviceIcon.setText(text) else: self.adviceIcon.setText("") else: if bool(self.iconText): text__ = str(data).replace(",", ", ") text_ = text__.replace(" ", " ") text = QString().fromUtf8(text_.replace(" ", "\n")) self.adviceLabel.setText(text) else: pass def show_n_hide(self): if "Control" not in dir(self): return None if self.Control.isVisible(): self.Control.hide() else: self.Control.move(self.popupPosition(self.Control.size())) self.Control.show() def createConfigurationInterface(self, parent): self.appletSettings = AppletSettings(self, parent) parent.addPage(self.appletSettings, "Settings") self.connect(parent, SIGNAL("okClicked()"), self.configAccepted) self.connect(parent, SIGNAL("cancelClicked()"), self.configDenied) def showConfigurationInterface(self): self.dialog = KPageDialog() self.dialog.setModal(True) self.dialog.setFaceType(KPageDialog.List) self.dialog.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel)) self.createConfigurationInterface(self.dialog) self.dialog.move(self.popupPosition(self.dialog.sizeHint())) self.dialog.exec_() def configAccepted(self): self.Timer.stop() self.appletSettings.refreshSettings(self) self.initVar() self.initLayout() self.Timer.start(self.timeout * 1000) self.dialog.done(0) def configDenied(self): self.dialog.done(0) def __del__(self): self.Timer.stop() if "Control" in dir(self): self.Control.close()
class plasmaAlarmClock(plasmascript.Applet): alarm = pyqtSignal(list, list, list) nextAlarm = pyqtSignal(str) def __init__(self, parent = None): plasmascript.Applet.__init__(self, parent) self.name = 'kde-plasma-alarm-clock' self.Settings = QSettings(self.name, self.name) mark = 'plasma/plasmoids/' + self.name self.plasmaPath = '' for d in KSD().resourceDirs('data') : _path = os.path.join(str(d), mark) if os.path.isfile(os.path.join(_path, 'contents/icons/alarm.png')) : self.plasmaPath = _path if self.plasmaPath == '' : self.plasmaPath = os.path.join(os.getcwd(), self.name) self.appletWD = os.path.join(self.plasmaPath, 'contents') self.alarmIconPath = self.appletWD + '/icons/alarm.png' self.alarm1IconPath = self.appletWD + '/icons/alarm1.png' self.alarm2IconPath = self.appletWD + '/icons/alarm2.png' self.alarm_disabledIconPath = self.appletWD + '/icons/alarm_disabled.png' #print self.alarmIconPath, ':', self.appletWD self.paused = True def initVar(self): if self.Settings.value('Alarm Clock Enable', 'True') == 'True' : self.alarmed = True else: self.alarmed = False self.alarmTimesList = getAlarmTimesList(self.Settings) #print self.alarmTimesList def initLayout(self): if hasattr(self.layout,'count') : while self.layout.count() > 0 : idx = self.layout.count()-1 self.layout.itemAt(idx).setVisible(False) self.layout.removeAt(idx) self.layout.setOrientation(Qt.Vertical) if self.config().readEntry('Icon Show', 'True') == 'True' : self.layout.addItem(self.alarmIcon) self.layout.setAlignment(self.alarmIcon, Qt.AlignCenter) self.alarmIcon.setVisible(True) if self.config().readEntry('Time Show', 'True') == 'True' : self.layout.addItem(self.timeLCD) self.layout.setAlignment(self.timeLCD, Qt.AlignCenter) self.timeLCD.setVisible(True) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.setLayout(self.layout) self.fontColour = 'QWidget {background: rgba(0,0,0,16); color: %s;}' % (self.config().readEntry("fontColour")) self.unblinkColour = 'QWidget {background: rgba(0,0,0,0); color: %s;}' % (self.config().readEntry("unblinkColour")) #print [self.fontColour, self.unblinkColour] def init(self): self.initVar() self.layout = QGraphicsLinearLayout(self.applet) self.alarmIcon = Plasma.IconWidget() self.alarmIcon.setIcon(QIcon().fromTheme('alarm-clock', QIcon(':/'+self.alarmIconPath))) self.alarmIcon.mouseReleaseEvent = self.mouseReleaseEvent self.LCD = QLCDNumber() self.LCD.setSegmentStyle(QLCDNumber.Flat) self.LCD.setStyleSheet('QWidget {background: rgba(0,0,0,0);}') self.LCD.setSmallDecimalPoint(True) self.timeLCD = QGraphicsProxyWidget() self.timeLCD.setWidget(self.LCD) self.timeLCD.mouseReleaseEvent = self.mouseReleaseEvent self.initLayout() self.setHasConfigurationInterface(True) self.setNewToolTip() self.alarm.connect(self.showAlarm) self.nextAlarm.connect(self.setNewToolTip) self.checkAlarmList = CheckAlarmList(self) self.checkAlarmList.started.connect(self.start) self.checkAlarmList.start() def start(self): self.checkAlarmList.started.disconnect(self.start) self.timer = QTimer() self.timer.timeout.connect(self.blink) if self.alarmed : self.changeActivity() else : self.setNewToolTip('Stopped') self.connect(self.applet, SIGNAL('destroyed()'), self.eventClose) def mousePressEvent(self, ev): if ev.type() == QEvent.GraphicsSceneMousePress : ev.accept() def mouseReleaseEvent(self, ev): if ev.type() == QEvent.GraphicsSceneMouseRelease : self.changeActivity() def changeActivity(self): if not self.paused : self.timer.stop() self.alarmIcon.setIcon(self.alarm_disabledIconPath) self.setNewToolTip('Stopped') self.paused = True else : self.alarmIcon.setIcon(self.alarm1IconPath) self.timer.start(1000) self.paused = False self.checkAlarmList.check_alarm() def blink(self): try : if self.alarmIcon.isVisible() : self.alarmIcon.setIcon(self.alarm2IconPath) self.LCD.setStyleSheet(self.fontColour) if self.LCD.isVisible() : self.LCD.display(self.currTime.replace(':', ' ')) QTimer().singleShot(250, self.unBlink) except Exception, err : print err, 'in blink()' finally : pass def unBlink(self): try : if self.alarmIcon.isVisible() : self.alarmIcon.setIcon(self.alarm1IconPath) self.LCD.setStyleSheet(self.unblinkColour) self.LCD.display(self.currTime) except Exception, err : print err, 'in unBlink()' finally : pass def showAlarm(self, msgs, sounds, cmds): #print msgs, sounds, cmds, 'alarmed' playSounds = [] runCmds = [] for sound in sounds : if not os.path.isfile(sound.toLocal8Bit().data()) : sound = QString('/usr/share/sounds/pop.wav') #print (sound) playSounds.append(QProcess()) playSounds[len(playSounds)-1].startDetached('/usr/bin/play', QStringList() << sound) for cmd in cmds : if cmd.isEmpty() : continue runCmds.append(QProcess()) runCmds[len(runCmds)-1].startDetached('/usr/bin/sh', QStringList() << '-c' << cmd) for msg in msgs : if msg.isEmpty() : continue notify = KNotification.event(\ KNotification.Notification, \ 'Alarm Clock', \ msg, \ QPixmap(self.alarmIconPath)) def setNewToolTip(self, msg = ''): Plasma.ToolTipManager.self().setContent( \ self.applet, \ Plasma.ToolTipContent( \ 'Alarm Clock', \ QString(msg), \ QIcon(self.alarmIconPath) ) ) def createConfigurationInterface(self, parent): self.appletSettings = AppletSettings(self, parent) parent.addPage(self.appletSettings, "Settings") self.colorSelect = ColorWidget(self, parent) parent.addPage(self.colorSelect, "Color") self.connect(parent, SIGNAL("okClicked()"), self.configAccepted) self.connect(parent, SIGNAL("cancelClicked()"), self.configDenied) def showConfigurationInterface(self): self.dialog = KPageDialog() self.dialog.setModal(True) self.dialog.setFaceType(KPageDialog.List) self.dialog.setButtons( KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel) ) self.createConfigurationInterface(self.dialog) self.dialog.move(self.popupPosition(self.dialog.sizeHint())) self.dialog.exec_() def configAccepted(self): self.appletSettings.refreshSettings(self) self.colorSelect.refreshSettings() self.initVar() self.dialog.done(0) self.initLayout() self.checkAlarmList.check_alarm() def configDenied(self): self.dialog.done(0) def eventClose(self): self.timer.stop() self.timer.timeout.disconnect(self.blink) if hasattr(self, 'checkAlarmList') : self.checkAlarmList.stop() self.checkAlarmList.quit() del self.checkAlarmList self.checkAlarmList = None self.alarm.disconnect(self.showAlarm) self.nextAlarm.disconnect(self.setNewToolTip) print 'AlarmClock is closed' def __del__(self): self.eventClose()
class plasmaCpuFreqUtility(plasmascript.Applet): def __init__(self, parent = None): plasmascript.Applet.__init__(self, parent) self.kdehome = unicode(KGlobal.dirs().localkdedir()) if os.path.exists('/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png') : self.iconPath = '/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png' elif os.path.exists(self.kdehome + '/share/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png') : self.iconPath = self.kdehome + '/share/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png' #print 'installing', self.iconPath else : self.iconPath = os.getcwd() + '/plasmaCpuFreqUtility/contents/icons/performance.png' self.Settings = QSettings('kde-plasma-cpufrequtility', 'kde-plasma-cpufrequtility') def init(self): self.setImmutability(Plasma.Mutable) self.setHasConfigurationInterface(True) self.layout = QGraphicsLinearLayout(self.applet) self.layout.setSpacing(0) self.icon = Plasma.IconWidget() self.icon.setIcon(self.iconPath) self.icon.setMinimumIconSize(QSizeF(24.0, 24.0)) self.icon.clicked.connect(self.mouseDoubleClickEvent) self.layout.addItem(self.icon) self.setLayout(self.layout) self.colorSelect = ColorWidget(self) enabled = self.Settings.value('Remember', 0).toInt()[0] if bool(enabled) : self.ProcData = self.getLastProcParemeters() self.Control = ControlWidget({}, self, os.path.dirname(self.iconPath)) self.Control.changeRegime(self.ProcData) else : self.ProcData = define_proc_data() self.Control = ControlWidget(self.ProcData, self, os.path.dirname(self.iconPath)) self.setTooltip(self.Control.getNewProcParemeters()) def mouseDoubleClickEvent(self, ev = True): if type(ev) is not bool : ev.ignore() if self.Control.isVisible() : self.Control.hide() else: self.Control.move(self.popupPosition(self.Control.size())) self.Control.show() def parametersReset(self): self.Control.close() self.ProcData = define_proc_data() self.Control = ControlWidget(self.ProcData, self, os.path.dirname(self.iconPath)) self.setTooltip(self.Control.getNewProcParemeters()) #self.mouseDoubleClickEvent() def setTooltip(self, newParameters): htmlStr = '<b>' for i in xrange(COUNT_PROC) : if i == 0 or newParameters[i]['enable'] == 1 : enable = '<font color=' + self.colorSelect.enableOnColor + '> on </font>' elif newParameters[i]['enable'] == 0 : enable = '<font color=' + self.colorSelect.enableOffColor + '> off </font>' htmlStr += '<pre><font color=' + self.colorSelect.cpuColor + '>CPU' + str(i) + '</font>' + enable htmlStr += ' <font color=' + self.colorSelect.governorColor + '>' + newParameters[i]['regime'] + '</font>' htmlStr += ' <font color=' + self.colorSelect.minFreqColor + '>' + newParameters[i]['minfrq'][:-3] + '</font>' htmlStr += ' <font color=' + self.colorSelect.maxFreqColor + '>' + newParameters[i]['maxfrq'][:-3] + '</font><br></pre>' htmlStr += '</b>' Plasma.ToolTipManager.self().setContent( self.applet, Plasma.ToolTipContent( \ 'CPU FreqUtility', \ QString(htmlStr), self.icon.icon() ) ) def getLastProcParemeters(self): lastParameters = {} i = 0 for paramProc in self.Settings.value('Parameters', '').toString().split(";;", QString.SkipEmptyParts) : lastParameters[i] = {} parameters = paramProc.split(" ", QString.SkipEmptyParts) lastParameters[i]['enable'] = int(parameters[0]) lastParameters[i]['regime'] = str(parameters[1]) lastParameters[i]['minfrq'] = str(parameters[2]) lastParameters[i]['maxfrq'] = str(parameters[3]) i += 1 return lastParameters def createConfigurationInterface(self, parent): self.colorSelect = ColorWidget(self, parent) parent.addPage(self.colorSelect, "Color") self.connect(parent, SIGNAL("okClicked()"), self.configAccepted) self.connect(parent, SIGNAL("cancelClicked()"), self.configDenied) def showConfigurationInterface(self): self.dialog = KPageDialog() self.dialog.setModal(True) self.dialog.setFaceType(KPageDialog.List) self.dialog.setButtons( KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel) ) self.createConfigurationInterface(self.dialog) self.dialog.move(self.popupPosition(self.dialog.sizeHint())) self.dialog.exec_() def configAccepted(self): self.colorSelect.refreshInterfaceSettings() self.dialog.done(0) self.parametersReset() def configDenied(self): self.dialog.done(0)
def done(self, result): if result: self.saveSettings() KPageDialog.done(self, result)
def showConfigurationInterface(self): dialog = KPageDialog() dialog.setWindowTitle("Star Trek Fortune Settings") dialog.setFaceType(KPageDialog.List) dialog.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel)) # Appearance Settings defaultConfig = {"textColor":self._textColor,"shadowColor":self._shadowColor, "font":self._font,"hideBackground":self._showBackground, "hideSVG":self._showSVG, "updateInterval":self._updateInterval} self._configDialog = STFConfig(self, defaultConfig) appearancePage = dialog.addPage(self._configDialog,i18n("Appearance")) appearancePage.setIcon(KIcon("preferences-desktop-color")) self.connect(dialog, SIGNAL("okClicked()"), self.configAccepted) self.connect(dialog, SIGNAL("cancelClicked()"), self.configDenied) dialog.resize(540,330) dialog.exec_()