class KTorrentView(plasmascript.Applet): def __init__(self,parent,args=None): plasmascript.Applet.__init__(self,parent) def init(self): self.setHasConfigurationInterface(False) self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.settings = self.config() self.theme = Plasma.Svg(self) self.theme.setImagePath("widgets/background") self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsGridLayout(self.applet) self.layout.setColumnSpacing(0,5.0) self.setLayout(self.layout) self.resize(500,200)
class TaskCoachApplet(plasmascript.Applet): def __init__(self,parent,args=None): plasmascript.Applet.__init__(self,parent) def init(self): self.setHasConfigurationInterface(False) self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.settings = self.config() self.theme = Plasma.Svg(self) self.theme.setImagePath("widgets/background") self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsGridLayout(self.applet) self.layout.setColumnSpacing(0,5.0) # using the predefined KGuiItem objects save us a lot of work self.btnOpen = Plasma.PushButton(self.applet) self.btnOpen.nativeWidget().setGuiItem(KStandardGuiItem.Open) self.btnReset = Plasma.PushButton(self.applet) self.btnReset.nativeWidget().setGuiItem(KStandardGuiItem.Reset) self.btnSave = Plasma.PushButton(self.applet) self.btnSave.nativeWidget().setGuiItem(KStandardGuiItem.Save) self.btnSaveAs = Plasma.PushButton(self.applet) self.btnSaveAs.nativeWidget().setGuiItem(KStandardGuiItem.SaveAs) self.layout.addItem(self.btnOpen,0,0) self.layout.addItem(self.btnReset,0,1) self.layout.addItem(self.btnSave,2,1) self.layout.addItem(self.btnSaveAs,2,0) self.model = None self.filePath = None self.treeView = Plasma.TreeView(self.applet) self.treeView.setVisible(False) header = self.treeView.nativeWidget().header() header.setDefaultAlignment(Qt.AlignCenter) fontColor = self.theme.theme().color(Plasma.Theme.TextColor) header.setStyleSheet(""" QHeaderView { color: %s; font: bold italic; }; """ % fontColor.name() ) self.treeView.setStyleSheet(""" QTreeView { background-color: transparent; color: %s;}; """ % fontColor.name() ) self.treeView.setModel(self.model) self.layout.addItem(self.treeView,1,0,1,2) self.setLayout(self.layout) self.resize(350,500) self.btnOpen.clicked.connect(self.openFile) self.btnReset.clicked.connect(self.resetFile) self.btnSave.clicked.connect(self.saveFile) self.btnSaveAs.clicked.connect(self.saveFileAs) # FIXME: doesn't work QObject.connect(self.treeView.nativeWidget(), SIGNAL("dataChanged(QModelIndex,QModelIndex)"), self.onDataChanged) self.treeView.nativeWidget().setItemDelegate( ProgressDelegate( self.treeView.nativeWidget())) self.treeView.nativeWidget().header().setResizeMode( QHeaderView.Interactive) self.treeView.nativeWidget().setEditTriggers(QTreeView.AllEditTriggers) def _open(self,filePath): if not filePath.isEmpty(): self.model = TaskListModel(str(filePath)) self.treeView.setModel(self.model) self.treeView.nativeWidget().expandAll() self.treeView.nativeWidget().header().resizeSection(0, self.treeView.nativeWidget().width() * 0.8) self.treeView.nativeWidget().header().resizeSection(1, self.treeView.nativeWidget().width() * 0.1) self.filePath = filePath self.treeView.setVisible(True) @pyqtSlot() def openFile(self,*args): fPath = QFileDialog.getOpenFileName(None, "Select TaskCoach file", expanduser("~"), "TaskCoach files (*.tsk);;All Files(*.*)") self._open(fPath) @pyqtSlot() def resetFile(self,*args): if self.filePath is not None: self.model = TaskListModel(str(self.filePath)) self.treeView.setModel(self.model) self.treeView.nativeWidget().expandAll() @pyqtSlot() def saveFileAs(self,*args): savePath = QFileDialog.getSaveFileName ( None, "Save As", self.filePath, "TaskCoach files (*.tsk);;All Files(*.*)") if savePath.isEmpty(): return # user cancelled action tmpPath = QString(self.filePath) self.filePath = savePath done = self.saveFile() # if anything went wrong, go back to original if not done: self.filePath = tmpPath @pyqtSlot() def saveFile(self,*args): try: f = codecs.open(str(self.filePath),"w","utf-8") f.write(self.model.domDocument.toString()) f.close() return True except Exception, e: QMessageBox.critical(None, "Failure while saving", e.msg) return False except Error, e: QMessageBox.critical(None, "Failure while saving", e.msg) return False
class GSBApplet(plasmascript.Applet): def __init__(self,parent,args=None): plasmascript.Applet.__init__(self,parent) def init(self): self.setHasConfigurationInterface(True) self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.settings = self.config() self.theme = Plasma.Svg(self) self.theme.setImagePath("widgets/background") self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsGridLayout(self.applet) self.layout.setColumnSpacing(0,5.0) self.lblTitle = Plasma.Label(self.applet) self.lblTitle.nativeWidget().setText( ki18n("Stuff to get back").toString()) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setStyleSheet("""QLabel { text-align:center; font-style: italic; font-weight: bold;}""") self.layout.addItem(self.lblTitle,0,0,1,3) self.btnAdd = Plasma.PushButton(self.applet) self.btnAdd.nativeWidget().setGuiItem(KStandardGuiItem.Add) self.layout.addItem(self.btnAdd,1,0) self.btnRemove = Plasma.PushButton(self.applet) self.btnRemove.nativeWidget().setGuiItem(KStandardGuiItem.Remove) self.layout.addItem(self.btnRemove,1,2) self.db = GSBDbModel() self.view = Plasma.TreeView(self.applet) self.view.setModel(self.db) self.view.nativeWidget().setColumnHidden(self.db.IDCOL,True) self.view.nativeWidget().setRootIsDecorated(False) self.view.nativeWidget().setExpandsOnDoubleClick(False) self.view.nativeWidget().setItemsExpandable(False) self.view.setStyleSheet(""" QTreeView { background-color: transparent; } QTreeView::item { padding-top:10px; padding-bottom: 10px; } """) self.view.nativeWidget().header().resizeSections( QHeaderView.ResizeToContents) self.view.nativeWidget().setItemDelegate( LoanDelegate( self.applet, self.view.nativeWidget())) self.layout.addItem(self.view,2,0,1,3) self.setLayout(self.layout) self.btnAdd.clicked.connect(self.add_loan) self.btnRemove.clicked.connect(self.remove_loan) def createConfigurationInterface(self, parent): self.configDlg = ConfigDlg(parent, self.applet) page = parent.addPage(self.configDlg, ki18n("GetStuffBack Options").toString()) page.setIcon(KIcon("user-desktop")) parent.okClicked.connect(self.configAccepted) def showConfigurationInterface(self): dialog = KPageDialog() dialog.setFaceType(KPageDialog.List) dialog.setButtons( KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel) ) self.createConfigurationInterface(dialog) dialog.exec_() @pyqtSlot() def configAccepted(self): grace_period = self.configDlg.spinGrace.value() colour = self.configDlg.btnColour.color() options = self.settings.group("general") options.writeEntry("grace",grace_period) options.writeEntry("overdue_colour",colour.name()) @pyqtSlot() def add_loan(self,*args): addDlg = AddDlg(self) result = addDlg.exec_() if result == False: return False ln = Loan() ln.item_description = unicode(addDlg.lineItemDescription.toPlainText()) ln.person = unicode(addDlg.linePerson.text()) ln.date = addDlg.dteDate.dateTime().toPyDateTime() ln.expected_date = addDlg.dteExpectedDate.dateTime().toPyDateTime() ln.item_type = unicode(addDlg.comboItemType.currentText()) self.db.add_loan(ln) self.db.dataChanged.emit(QModelIndex(),QModelIndex()) self.db.reset() @pyqtSlot() def remove_loan(self,*args): deleteList = self.view.nativeWidget().selectionModel().selectedIndexes() rows = set() for index in deleteList: row = index.row() if row not in rows: rows.add(row) self.db.removeRow(row)