# -*- coding: iso-8859-1 -*- # Copyright stuff from PyQt4.QtCore import * from PyQt4.QtGui import * from PyKDE4.plasma import Plasma from PyKDE4 import plasmascript from PyKDE4.kdeui import * import sys, os from string import split, strip format=[["pdf","kpdf"],["htm","html","konqueror"],["jpg","jpeg","png","gif","gwenview"],["txt","dat","py","sh","c","h","kwrite"]] class KuloApplet(plasmascript.Applet): def __init__(self,parent,args=None): plasmascript.Applet.__init__(self,parent) def init(self): self.setHasConfigurationInterface(True) self.setAspectRatioMode(Plasma.KeepAspectRatio) self.configurations = self.config() self.layout = QGraphicsGridLayout(self.applet) self.prepareConfigDialog() self.stringlist = QStringList() self.model = QStringListModel(self.applet) self.model.setStringList(self.stringlist) self.treeview = MyTreeView() self.treeview.setModel(self.model) self.layout.addItem(self.treeview,0,0,1,4) self.treeview.nativeWidget().header().hide() self.treeview.nativeWidget().setAlternatingRowColors(True) #font = QFont("Courier New", 18) #self.treeview.nativeWidget().setFont(font) #palette = QPalette() #palette.setColor(QPalette.Inactive,QPalette.WindowText,QColor(Qt.red)) #self.treeview.nativeWidget().setStyleSheet("color: #00ff00") #self.treeview.nativeWidget().repaint() self.configurations.readEntry("prova",QStringList()) font = self.configurations.readEntry("TextFont").split(",")[0:4] print font, type(font) self.treeview.nativeWidget().setFont(QFont(font[0],int(font[1]))) self.treeview.nativeWidget().setStyleSheet("color: "+ self.configurations.readEntry("TextColor")+";"+"alternate-background-color: ") self.label1=Plasma.Label(self.applet) self.label1.setText("Search:") self.layout.addItem(self.label1,1,0) self.label2=Plasma.Label(self.applet) self.label2.setText("Case Sensitive") self.layout.addItem(self.label2,1,3) self.lineEdit = MyLineEdit() self.layout.addItem(self.lineEdit, 1,1) self.checkBox = Plasma.CheckBox(self.applet) #self.checkBox.setText("") self.layout.addItem(self.checkBox,1,2) self.lineEdit.nativeWidget().maximumSize=30 self.pushButton = Plasma.PushButton(self.applet) self.pushButton.setText("Clear") self.layout.addItem(self.pushButton,2, 0,1,4) self.setLayout(self.layout) self.resize(550,250) QObject.connect(self.pushButton, SIGNAL("clicked()"), self.resetList) QObject.connect(self.lineEdit, SIGNAL("returnPressed()"), self.addItem) QObject.connect(self.lineEdit, SIGNAL("keyUPPressed"), self.prevHistoryItem) QObject.connect(self.lineEdit, SIGNAL("keyDownPressed"), self.nextHistoryItem) QObject.connect(self.treeview, SIGNAL("DblClick"), self.openFile) QObject.connect(self.treeview, SIGNAL("Click"), self.openDirectory) QObject.connect(self.applet,SIGNAL("appletDestroyed()"),self.saveHistory) QMetaObject.connectSlotsByName(self.applet) #print os.path.realpath(".") #flog=open("/root/log.txt",'w') #flog.write(str(os.path.realpath("."))) #flog.close() f=open("/root/.kde/share/apps/plasma/plasmoids/Kulo/contents/code/history.txt",'r') #f=open("Kulo/contents/code/history.txt",'r') self.history=f.readlines() f.close() self.historyCurrentItem=0 print self.history #def retranslateUi(self, Form): #Form.setWindowTitle(QApplication.translate("Form", "PyQTLocate", None, QApplication.UnicodeUTF8)) #self.pushButton.setText(QApplication.translate("Form", "Clear", None, QApplication.UnicodeUTF8)) def resetList(self): self.stringlist.clear() self.model.setStringList(self.stringlist) def saveHistory(self): print "merda" f=open("/root/.kde/share/apps/plasma/plasmoids/Kulo/contents/code/history.txt",'w') #f=open("Kulo/contents/code/history.txt",'w') f.writelines(self.history) f.close() def prevHistoryItem(self): print self.historyCurrentItem if self.historyCurrentItem < len(self.history): self.historyCurrentItem=self.historyCurrentItem+1 print self.historyCurrentItem self.lineEdit.setText(str(self.history[-self.historyCurrentItem])) def nextHistoryItem(self): print self.historyCurrentItem if self.historyCurrentItem > 1: self.historyCurrentItem=self.historyCurrentItem-1 print self.historyCurrentItem self.lineEdit.setText(str(self.history[-self.historyCurrentItem])) def addItem(self): self.stringlist.clear() lineText=self.lineEdit.text() print lineText if str(lineText).strip() is not "" and str(lineText).strip()+"\n" not in self.history: self.history.append(lineText+"\n") self.historyCurrentItem=1 self.saveHistory() self.historyCurrentItem=self.historyCurrentItem-1 #global results, listres, numpage, numitems, itemsview, imageTooltip h=0 listres=0 if self.checkBox.isChecked() == 1: cmd="/usr/bin/locate " + str(lineText) else: cmd="/usr/bin/locate -i " + str(lineText) loc=os.popen(cmd) results=[] #imageTooltip=[] results=loc.readlines() numitems=len(results) #numpage=len(results)/itemsview for item in results: self.stringlist.append(item[:-1]) self.model.setStringList(self.stringlist) self.lineEdit.nativeWidget().clear() def openDirectory(self,index): print "into", index item = self.model.data(index,0).toString() print item cmd="dolphin '" + str(os.path.split(str(item))[0]) + "'" return os.popen(cmd) def openFile(self,index): print "into", index item = self.model.data(index,0).toString() print item return os.popen("xdg-open '" + str(item) + "'") #if os.path.isdir(item) == True: #print "is dir true" #return os.popen("dolphin '" + str(item) + "'") #else: #print item, format #extension=str(os.path.splitext(str(item))[1][1:]) #for k in format: #if extension in k: #return os.popen(k[-1] + " '" + str(item) + "'") #return os.popen("dolphin '" + str(os.path.split(str(item))[0]) + "'") def showConfigurationInterface(self): self.dialog.show() def prepareConfigDialog(self): #self.tfont = QFont() #self.tcolor = QColor() self.bcolor = QColor() self.dialog = KDialog() self.layBox = QGridLayout(self.dialog.mainWidget()) self.labelD = QLabel ("Font", self.dialog) self.layBox.addWidget(self.labelD,0,0) self.FontButton = QPushButton(self.dialog) self.layBox.addWidget(self.FontButton,0,1) #self.FontButton.setText("current font") self.tfont=QFont(self.configurations.readEntry("TextFont")) self.FontButton.setText(self.tfont.toString().split(",")[0]+" "+self.tfont.toString().split(",")[1]) self.labelC = QLabel ("Text Color", self.dialog) self.layBox.addWidget(self.labelC,1,0) self.ColorButton = KColorButton(self.dialog) self.layBox.addWidget(self.ColorButton,1,1) self.tcolor = QColor(self.configurations.readEntry("TextColor",QColor(Qt.black).name())) #self.tcolor=self.dialog.palette().color(QPalette.Active,QPalette.WindowText) self.ColorButton.setColor(self.tcolor) self.labelB = QLabel ("Alternate Back Color", self.dialog) self.layBox.addWidget(self.labelB,2,0) self.BColorButton = KColorButton(self.dialog) self.layBox.addWidget(self.BColorButton,2,1) self.dialog.setButtons(KDialog.ButtonCodes(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel | KDialog.Apply))) #self.dialog.showButton(KDialog.Apply, True) QObject.connect(self.FontButton, SIGNAL("clicked()"), self.showFontDialog) self.connect(self.dialog, SIGNAL("applyClicked()"), self, SLOT("configAccepted()")) self.connect(self.dialog, SIGNAL("okClicked()"), self, SLOT("configAccepted()")) return True @pyqtSignature("configAccepted()") def configAccepted(self): self.tcolor=self.ColorButton.color() self.bcolor=self.BColorButton.color() self.configurations.writeEntry("TextColor", self.tcolor.name()) self.treeview.nativeWidget().setFont(self.tfont) self.treeview.nativeWidget().setStyleSheet("color: "+ self.tcolor.name()+";"+"alternate-background-color: ") def showFontDialog(self): KFontDialog().getFont(self.tfont) self.FontButton.setText(self.tfont.toString().split(",")[0]+" "+self.tfont.toString().split(",")[1]) self.configurations.writeEntry("TextFont",QVariant(self.tfont)) class MyLineEdit(Plasma.LineEdit): def __init__(self, *args): Plasma.LineEdit.__init__(self, *args) def event(self, event): if (event.type()==QEvent.KeyPress) and (event.key()==Qt.Key_Up): self.emit(SIGNAL("keyUPPressed")) return True if (event.type()==QEvent.KeyPress) and (event.key()==Qt.Key_Down): self.emit(SIGNAL("keyDownPressed")) return True return Plasma.LineEdit.event(self, event) class MyTreeView(Plasma.TreeView): def __init__(self, *args): Plasma.TreeView.__init__(self, *args) def mouseDoubleClickEvent(self,event): if event.button() == 1: mousePoint=event.pos().toPoint() index = self.nativeWidget().indexAt(mousePoint) self.emit(SIGNAL("DblClick"),index) #return True def mouseReleaseEvent(self,event): if event.button() == 4: mousePoint=event.pos().toPoint() index = self.nativeWidget().indexAt(mousePoint) self.emit(SIGNAL("Click"),index) #return True def CreateApplet(parent): return KuloApplet(parent)