def testUI2(): #print Parley.dataDirs() #print Parley.pluginDirs() #return forms = Kross.module("forms") mydialog = forms.createDialog("MyDialog") mydialog.setButtons("Ok|Cancel") mydialog.setFaceType("Plain") #Auto Plain List Tree Tabbed print dir(mydialog) #for attr in dir(mydialog): #print attr, getattr(mydialog,attr) mywidget = forms.createWidgetFromUIFile( mydialog, Parley.pluginDirs()[0] + "./mywidget.ui") mydialog.setMainWidget(mywidget) mywidget["QTextEdit"].setText("some string") #print dir(mywidget["QPushButton"]) mywidget["QPushButton"].text = "Push me" #mywidget.textEdit.setText("soooome string") Parley.connect(mywidget["QPushButton"], "pressed()", click) #print mywidget print dir(mywidget) if mydialog.exec_loop(): if mydialog.result() == "Ok": print mywidget["QTextEdit"].text
def __init__(self, scriptaction): """ Some initial work like the import of the Kross and KSpread functionality and test functions are added to demonstrate the usage. """ import os, sys try: import Kross except: raise "Failed to import the Kross module." self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.embeddedInKSpread = False try: import KSpread self.kspread = KSpread self.embeddedInKSpread = True except ImportError: try: import Kross self.kspread = Kross.module("kspread") except ImportError: raise "Failed to import the Sheets Kross module. Please run this script with \"kross thisscriptfile.py\"" self.addTestFunctions()
def initWidget(widget): # the Kross forms module does provide methods to create # widgets for us. You are for example able to load a UI # file, create layouts or just any other supported widget. forms = Kross.module("forms") frame = forms.createWidget("QWidget") forms.createLayout(frame, "QHBoxLayout") # here we load the KHTML KPart that is our full powered # webbrowser widget. khtml_part = forms.loadPart(frame, "libkhtmlpart") khtml_part.javaScriptEnabled = True khtml_part.javaEnabled = False khtml_part.pluginsEnabled = False # now we add the frame to our widget and will earn a # proxywidget for it. proxywidget = karamba.createCanvasWidget(widget, frame) # the following lines demonstrate, how to control the # webbrowser using the JavaScript language. The KHTML # KPart does provide different signals we are able to # connect our own functions too. Just see here the # kdelibs/khtml/khtmlpart.h file. def selectionChanged(): print khtml_part.executeScript("window.scrollBy(0,50);") khtml_part.connect("selectionChanged()", selectionChanged) # and finally we like to load an url and display something. khtml_part.openUrl("http://www.kde.org")
def __init__(self, action, config): self.config = config forms = Kross.module("forms") self.dialog = forms.createDialog("ReportLab.org") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") # Auto Plain List Tree Tabbed self.dialog.minimumWidth = 580 self.dialog.minimumHeight = 400 # if not self.config.writeFileName: savepage = self.dialog.addPage("Save", "Export to PDF Document", "document-save") savewidget = forms.createFileWidget(savepage, "kfiledialog:///wordsreportlab") savewidget.setFilter("*.pdf|PDF Documents\n*|All Files") savewidget.setMode("Saving") # page = self.dialog.addPage("Template","Template","book") # pagewidget = forms.createWidgetFromUIFile(page, os.path.join(action.currentPath(), "kwreportlabpage.ui")) if self.dialog.exec_loop(): if not self.config.writeFileName: self.config.writeFileName = savewidget.selectedFile() if not self.config.writeFileName: raise "No file selected." writer = MyWriter(config) writer.write()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.proj = Plan.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(T.i18n("Resources Import")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed #TODO add options page ( import Calendars? Select calendars, Select resources... ) openpage = self.dialog.addPage(T.i18n("Open"),T.i18n("Plan Resources"),"document-open") self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kplatresourcesimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter("*.plan|%(1)s\n*|%(2)s" % { '1' : T.i18n("Plan"), '2' : T.i18n("All Files") } ) if self.dialog.exec_loop(): try: Plan.beginCommand( T.i18nc( "(qtundo_format )", "Import resources" ) ) self.doImport( self.proj ) Plan.endCommand() except: Plan.revertCommand() # play safe in case parts where loaded self.forms.showMessageBox("Error", T.i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
def start(action, myconfig, myorca): while True: try: myorca.speak(T.i18n("Calligra Spreadsheet")) break except IOError: forms = Kross.module("forms") dialog = forms.createDialog(T.i18n("Orca Screen Reader")) dialog.minimumWidth = 400 dialog.minimumHeight = 40 dialog.setButtons("Ok|Cancel") page = dialog.addPage("", "") label = forms.createWidget(page, "QLabel") label.text = T.i18n("Failed to connect with the Orca HTTP-Server.") widget = forms.createWidget(page, "QWidget") layout = forms.createLayout(widget, "QHBoxLayout") forms.createWidget(widget, "QLabel").text = T.i18n("Url:") urlEdit = forms.createWidget(widget, "QLineEdit") urlEdit.text = myconfig.url if not dialog.exec_loop(): return myconfig.url = urlEdit.text mykspread = MyKSpread(action, myorca) setattr(__main__, "_KSpreadOrca", mykspread) MyDialog(self, mykspread)
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("E-Mail Script Settings")) dialog.setButtons("Ok|Cancel") page = page = dialog.addPage(t.i18n("E-Mail Settings"),t.i18n("E-Mail Settings"),"mail-send") widget = forms.createWidgetFromUIFile(page,KTScriptingPlugin.scriptDir("email_notifications") + "emailconfig.ui") widget["username"].text = self.mail_user widget["password"].text = self.mail_pwd widget["server"].text = self.mail_server widget["port"].value = self.mail_port widget["to"].text = self.mail_dest widget["cc"].text = self.mail_cc widget["bcc"].text = self.mail_bcc widget["add_cc"].checked = self.mail_add_cc widget["add_bcc"].checked = self.mail_add_bcc widget["cc"].enabled = self.mail_add_cc widget["bcc"].enabled = self.mail_add_bcc widget["tls"].checked = self.mail_use_tls if dialog.exec_loop(): # update settings self.mail_user = widget["username"].text self.mail_pwd = widget["password"].text self.mail_server = widget["server"].text self.mail_port = widget["port"].value self.mail_dest = widget["to"].text self.mail_cc = widget["cc"].text self.mail_bcc = widget["bcc"].text self.mail_add_cc = widget["add_cc"].checked self.mail_add_bcc = widget["add_bcc"].checked self.mail_use_tls = widget["tls"].checked self.save()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.proj = KPlato.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(i18n("Busy Information Export")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed datapage = self.dialog.addPage(i18n("Schedules"),i18n("Export Selected Schedule"),"document-export") self.scheduleview = KPlato.createScheduleListView(datapage) savepage = self.dialog.addPage(i18n("Save"),i18n("Export Busy Info File"),"document-save") self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kplatobusyinfoexportsave") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } ) if self.dialog.exec_loop(): try: self.doExport( self.proj ) except Exception, inst: self.forms.showMessageBox("Sorry", i18n("Error"), "%s" % inst) except:
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Insert Shape") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed self.shapes = Words.shapeKeys() page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI(page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.shapes ] ) ) ) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.doInsert()
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Insert Shape") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed self.shapes = Words.shapeKeys() page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI( page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % (0, ''.join([ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.shapes ]))) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.doInsert()
def __init__(self): self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("KHTML Part") self.dialog.minimumWidth = 720 self.dialog.minimumHeight = 480 #dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed page = self.dialog.addPage("", "") #self.part = self.forms.loadPart(page, "libkhtmlpart", "file:///home/kde4/kspreaddocument2.html") #self.part = self.forms.loadPart(page, "libkhtmlpart", "http://127.0.0.1:8282/") self.part = self.forms.loadPart(page, "libkhtmlpart", "http://techbase.kde.org/Development/Tutorials/KWord_Scripting") if not self.part: raise "Failed to load the KHTML KPart" self.part.javaScriptEnabled = False self.part.javaEnabled = False self.part.pluginsEnabled = False #part.openUrl("/home/kde4/kspreaddocument2.html") self.part.connect("popupMenu(const QString&, const QPoint&)", self.popupMenu) self.part.connect("selectionChanged()", self.selectionChanged) self.part.connect("formSubmitNotification(const char*,const QString&,const QByteArray&,const QString&,const QString&, const QString&)", self.formSubmitNotification) #print self.part #print dir(self.part) self.dialog.exec_loop()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.proj = Plan.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(T.i18n("Task Import")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage(T.i18n("Open"), T.i18n("Tables Tasks"), "document-open") self.openwidget = self.forms.createFileWidget( openpage, "kfiledialog:///tablestaskimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter("*.ods|%(1)s\n*|%(2)s" % { '1': T.i18n("Tables"), '2': T.i18n("All Files") }) if self.dialog.exec_loop(): try: Plan.beginCommand(T.i18nc("(qtundoformat)", "Import tasks")) self.doImport(self.proj) Plan.endCommand() except: Plan.revertCommand() # in case partly loaded self.forms.showMessageBox( "Error", T.i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
def showDialog(self): """ Shows the import-dialog and let the user define the imagefile which should be imported. """ import Kross, os forms = Kross.module("forms") dialog = forms.createDialog("Python Imaging Library Import") try: dialog.setFaceType("List") dialog.setButtons("Ok|Cancel") filepage = dialog.addPage("File","Import Image From File","document-open") filewidget = forms.createFileWidget(filepage, "kfiledialog:///kritapilimport") filewidget.setMode("Opening") filewidget.setFilter(self.getFilters()) optionspage = dialog.addPage("Options","Import Options","configure") currentpath = self.scriptaction.currentPath() uifile = os.path.join(currentpath, "pilimport.ui") optionswidget = forms.createWidgetFromUIFile(optionspage, uifile) if dialog.exec_loop(): self.filename = filewidget.selectedFile() self.colorspace = self.getOption(optionswidget, "Colorspace", ["RGB","CMYK"]) self.destination = self.getOption(optionswidget, "Destination", ["NewLayer","ActiveLayer"]) self.size = self.getOption(optionswidget, "Size", ["Resize","Scale","Ignore"]) if not os.path.isfile(self.filename): raise "No valid file to import from choosen." self.doImport() finally: dialog.delayedDestruct()
def __init__(self, action, config): import Kross, KWord self.action = action self.config = config forms = Kross.module("forms") self.dialog = forms.createDialog("Import Doxygen XML File") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage("Open", "Import Doxygen XML File", "document-open") openwidget = forms.createFileWidget( openpage, "kfiledialog:///kwordsampleimportfile") openwidget.setMode("Opening") #openwidget.minimumWidth = 540 #openwidget.minimumHeight = 400 openwidget.setFilter("*.xml|XML Files\n*|All Files") configpage = self.dialog.addPage("Options", "Import Options", "preferences-other") configwidget = forms.createWidgetFromUIFile( configpage, os.path.join(action.currentPath(), "importdoxyxmloptions.ui")) stylepage = self.dialog.addPage("Styles", "Cascading Style Sheet", "preferences-web-browser-stylesheets") stylewidget = forms.createWidgetFromUIFile( stylepage, os.path.join(action.currentPath(), "importdoxyxmlstyle.ui")) styleedit = stylewidget["textEdit"] if self.dialog.exec_loop(): fileName = openwidget.selectedFile() if not fileName: raise "No file selected" self.config.FileName = fileName self.config.TableOfContent = configwidget["TocCheckBox"].checked self.config.IndexPage = configwidget["IndexPageCheckBox"].checked self.config.OtherPages = configwidget["OtherPagesCheckBox"].checked self.config.EnablePages = configwidget["PagesCheckBox"].checked self.config.PageDescription = configwidget[ "PageDescriptionCheckBox"].checked self.config.EnableClasses = configwidget["ClassesCheckBox"].checked self.config.ClassDescription = configwidget[ "ClassDescriptionCheckBox"].checked self.config.MemberDescription = configwidget[ "MemberDescriptionCheckBox"].checked self.config.EnableSlots = configwidget["SlotsCheckBox"].checked self.config.EnableSignals = configwidget["SignalsCheckBox"].checked self.config.EnableProperties = configwidget[ "PropertiesCheckBox"].checked self.config.EnableFunctions = configwidget[ "FunctionsCheckBox"].checked self.config.EnableVariables = configwidget[ "VariablesCheckBox"].checked self.importFile(styleedit.plainText)
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(T.i18n("CSV Export")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed savepage = self.dialog.addPage(T.i18nc("Options page name", "Save"),T.i18n("Export to CSV File"),"document-save") self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kspreadcsvexportsave") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.csv *.txt|%(1)s\n*|%(2)s" % { '1' : T.i18n("Comma-Separated-Value Files"), '2' : T.i18n("All Files") } ) datapage = self.dialog.addPage(T.i18nc("Options page name", "Export"),T.i18n("Export Sheets and ranges"),"document-export") self.sheetslistview = KSpread.createSheetsListView(datapage) self.sheetslistview.setSelectionType("MultiSelect") self.sheetslistview.setEditorType("Range") optionspage = self.dialog.addPage(T.i18n("Options"),T.i18n("Comma Separated Value Options"),"configure") self.optionswidget = self.forms.createWidgetFromUIFile(optionspage, os.path.join(self.currentpath, "csvoptions.ui")) if self.dialog.exec_loop(): try: self.doExport() except: self.forms.showMessageBox("Error", T.i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Trackers Lists Updater Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Trackers Lists Updater"), t.i18n("Trackers Lists Updater"), "kt-bandwidth-scheduler") widget = forms.createWidgetFromUIFile( page, KTScriptingPlugin.scriptDir("trackers_lists_updater") + "trackers_lists_updater.ui") widget["autoRetry"].checked = self.autoRetry widget["hours"].value = self.hours widget["minutes"].value = self.minutes widget["seconds"].value = self.seconds widget["hours"].enabled = self.autoRetry widget["minutes"].enabled = self.autoRetry widget["seconds"].enabled = self.autoRetry widget["updateBack"].checked = self.updateBack if dialog.exec_loop(): self.autoRetry = widget["autoRetry"].checked self.hours = widget["hours"].value self.minutes = widget["minutes"].value self.seconds = widget["seconds"].value self.updateBack = widget["updateBack"].checked self.save() self.updateTrackers()
def __init__(self, scriptaction): writerClazzes = [] global Writer for f in dir(Writer): if not f.startswith('_'): writerClazzes.append(getattr(Writer, f)) forms = Kross.module("forms") self.dialog = forms.createDialog("Export File") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed try: savepage = self.dialog.addPage("Save", "Export File", "document-save") savewidget = forms.createFileWidget( savepage, "kfiledialog:///wordssampleexportfile") savewidget.setMode("Saving") #savewidget.minimumWidth = 540 #savewidget.minimumHeight = 400 filters = [] for f in writerClazzes: filters.append("%s|%s" % (f.filtermask, f.filtername)) if len(writerClazzes) > 1: filters.insert( 0, "%s|All Supported Files" % " ".join([f.filtermask for f in writerClazzes])) filters.append("*|All Files") savewidget.setFilter("\n".join(filters)) if self.dialog.exec_loop(): file = savewidget.selectedFile() if not file: raise "No file selected" #print savewidget.currentMimeFilter().lower() def getWriterClazz(): for f in writerClazzes: for m in f.filtermask.split(' '): try: if file.lower().endswith( m[m.rindex('.'):].lower().strip()): return f except ValueError: pass return None writerClazz = getWriterClazz() if not writerClazz: raise "No writer for file \"%s\"" % file writerClazz(file) except: tb = "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) forms.showMessageBox("Error", "Error", tb)
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() #self.undostack = KSpread.undoStack() #self.undostack.connect("indexChanged(int)",self.indexChanged) #file = os.path(self.getLogDir(),"KSpread.log") self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Logger") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed savepage = self.dialog.addPage("Save","Save to Log File","document-save") self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kspreadlogger") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.txt *.log|Log File\n*|All Files") if self.dialog.exec_loop(): filename = self.savewidget.selectedFile() if os.path.isfile(filename): if self.forms.showMessageBox("WarningContinueCancel", "Overwrite file?", "The file \"%s\" does already exist. Overwrite the file?" % filename) != "Continue": raise "Aborted." sheetname = KSpread.currentSheet().sheetName() cellrange = "A1:F50" #FIXME try: self.file = open(filename, "w") self.startLogging(sheetname, cellrange) except IOError, (errno, strerror): raise "Failed to write Log File \"%s\":\n%s" % (filename,strerror)
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(T.i18n("CSV Import")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") # Auto Plain List Tree Tabbed openpage = self.dialog.addPage(T.i18n("Open"), T.i18n("Import from CSV File"), "document-open") self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kspreadcsvimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter( "*.csv *.txt|%(1)s\n*|%(2)s" % {"1": T.i18n("Comma-Separated-Value Files"), "2": T.i18n("All Files")} ) datapage = self.dialog.addPage(T.i18n("Import"), T.i18n("Import to sheet beginning at cell"), "document-import") self.sheetslistview = KSpread.createSheetsListView(datapage) self.sheetslistview.setEditorType("Cell") optionspage = self.dialog.addPage(T.i18n("Options"), T.i18n("Comma Separated Value Options"), "configure") self.optionswidget = self.forms.createWidgetFromUIFile( optionspage, os.path.join(self.currentpath, "csvoptions.ui") ) if self.dialog.exec_loop(): try: self.doImport() except: self.forms.showMessageBox( "Error", T.i18n("Error"), "%s" % "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])), )
def __init__(self, action, config): self.action = action self.config = config forms = Kross.module("forms") dialog = forms.createDialog(T.i18n("Import vCard")) #dialog.minimumWidth = 400 #dialog.minimumHeight = 300 dialog.setButtons("Ok|Cancel") dialog.setFaceType("List") #Auto Plain List Tree Tabbed filepage = dialog.addPage(T.i18n("Open"), T.i18n("vCard File"), "document-open") #deffile = "/home/kde4/vcardtest/addressbook.vcf" #"kfiledialog:///kspreadvcardimport" deffile = "kfiledialog:///kspreadvcardimport" self.openwidget = forms.createFileWidget(filepage, deffile) self.openwidget.setMode("Opening") self.openwidget.setFilter("*.vcf|%(1)s\n*|%(2)s" % { '1' : T.i18n("vCard Files"), '2' : T.i18n("All Files") } ) datapage = dialog.addPage(T.i18n("Import"),T.i18n("Import to sheet beginning at cell"),"document-import") self.sheetslistview = KSpread.createSheetsListView(datapage) self.sheetslistview.setEditorType("Cell") if not dialog.exec_loop(): return vcardfilename = self.openwidget.selectedFile() if not os.path.isfile(vcardfilename): raise Exception, T.i18n("File '%1' not found.", [vcardfilename]) currentSheet = self.sheetslistview.sheet() if not currentSheet: raise Exception, T.i18n("No current sheet.") self.importVCardFile(vcardfilename, currentSheet)
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("E-Mail Script Settings")) dialog.setButtons("Ok|Cancel") page = page = dialog.addPage(t.i18n("E-Mail Settings"), t.i18n("E-Mail Settings"), "mail-send") widget = forms.createWidgetFromUIFile( page, KTScriptingPlugin.scriptDir("email_notifications") + "emailconfig.ui") widget["username"].text = self.mail_user widget["password"].text = self.mail_pwd widget["server"].text = self.mail_server widget["port"].value = self.mail_port widget["to"].text = self.mail_dest widget["cc"].text = self.mail_cc widget["bcc"].text = self.mail_bcc widget["add_cc"].checked = self.mail_add_cc widget["add_bcc"].checked = self.mail_add_bcc widget["cc"].enabled = self.mail_add_cc widget["bcc"].enabled = self.mail_add_bcc widget["tls"].checked = self.mail_use_tls if dialog.exec_loop(): # update settings self.mail_user = widget["username"].text self.mail_pwd = widget["password"].text self.mail_server = widget["server"].text self.mail_port = widget["port"].value self.mail_dest = widget["to"].text self.mail_cc = widget["cc"].text self.mail_bcc = widget["bcc"].text self.mail_add_cc = widget["add_cc"].checked self.mail_add_bcc = widget["add_bcc"].checked self.mail_use_tls = widget["tls"].checked self.save()
def __init__(self, action, config): self.config = config forms = Kross.module("forms") self.dialog = forms.createDialog("ReportLab.org") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed self.dialog.minimumWidth = 580 self.dialog.minimumHeight = 400 #if not self.config.writeFileName: savepage = self.dialog.addPage("Save","Export to PDF Document","document-save") savewidget = forms.createFileWidget(savepage, "kfiledialog:///kwordreportlab") savewidget.setFilter("*.pdf|PDF Documents\n*|All Files") savewidget.setMode("Saving") #page = self.dialog.addPage("Template","Template","book") #pagewidget = forms.createWidgetFromUIFile(page, os.path.join(action.currentPath(), "kwreportlabpage.ui")) if self.dialog.exec_loop(): if not self.config.writeFileName: self.config.writeFileName = savewidget.selectedFile() if not self.config.writeFileName: raise "No file selected." writer = MyWriter(config) writer.write()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") try: self.start() except Exception, inst: self.forms.showMessageBox("Sorry", T.i18n("Error"), "%s" % inst)
def __init__(self): self.embeddedInKSpread = False try: import KSpread self.kspread = KSpread self.embeddedInKSpread = True except ImportError: try: self.kspread = Kross.module("kspread") except ImportError: raise Exception, "Failed to import the Kross module. Please run this script with \"kross thisscriptfile.py\"" application = self.kspread.application() self.document = self.kspread.document() global Config self.filename = '' for f in Config.ReaderFiles: if os.path.isfile(f): self.filename = f break if self.embeddedInKSpread: if self.document.url(): self.setFile(self.document.url()) elif self.filename and self.filename != '': self.setFile(self.filename) self.openFile() elif self.document.url(): self.setFile(self.document.url()) self.info = { 'Title': self.document.documentInfoTitle() or Config.Info['Title'], 'Subject': self.document.documentInfoSubject() or Config.Info['Subject'], 'Author': self.document.documentInfoAuthorName() or Config.Info['Author'], 'EMail': self.document.documentInfoEmail() or Config.Info['EMail'], 'Keywords': self.document.documentInfoKeywords() or Config.Info['Keywords'], 'Filename': self.document.url() or Config.Info['Filename'], 'Date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), } print "Application: %s" % application print "Document: %s" % self.document #print dir(self.kspread) #print dir(application) #print dir(document) print "Filename: %s" % self.filename print "Embedded in KSpread: %s" % self.embeddedInKSpread print "Sheetnames: %s" % self.kspread.sheetNames()
def doImport( self, project ): filename = self.openwidget.selectedFile() if not os.path.isfile(filename): raise Exception, T.i18n("No file selected") Tables = Kross.module("kspread") if not Tables: raise Exception, T.i18n("Could not start Calligra Sheets") if not Tables.openUrl(filename): self.forms.showMessageBox("Sorry", T.i18n("Error"), T.i18n("Could not open document: %1", [filename])) return def findParentTask(parent, wbs): if wbs == project.data(parent, 'WBSCode'): return parent for i in range(parent.childCount()): task = findParentTask(parent.childAt(i), wbs) if task is not None: return task return None def parentTask(wbs): codes = wbs.split('.') if len(codes) > 1: codes.pop() pwbs = '.'.join(codes) for i in range(project.taskCount()): parent = findParentTask(project.taskAt(i), pwbs) if parent is not None: return parent return project def createTask(properties, data): if len(data) == 0: return task = project.createTask(parentTask(data[0])) if task is None: raise Exception, T.i18n("Failed to create task") for i in range(1, len(properties)): project.setData(task, properties[i], data[i]) # Get data into list that can be sorted after wbs code reader = Tables.reader() props = [] def changedRow(row): if row == 1: props.append(reader.currentValues()) else: data = reader.currentValues() # skip lines without wbs code if data[0] is not None: createTask(props[0], data) reader.setSheet("Sheet1") reader.connect("changedRow(int)", changedRow) reader.start()
def __init__(self): readerClazzes = [] global Reader for f in dir(Reader): if not f.startswith('_'): readerClazzes.append( getattr(Reader,f) ) import Kross forms = Kross.module("forms") try: mainwidget = forms.createWidget("QWidget") self.widget = forms.createFileWidget(mainwidget, "kfiledialog:///kwordscriptingvariablereadfile") self.widget.setMode("Opening") self.widget.minimumWidth = 540 self.widget.minimumHeight = 400 filters = [] for f in readerClazzes: filters.append("%s|%s" % (f.filtermask,f.filtername)) if len(readerClazzes) > 1: filters.insert(0, "%s|All Supported Files" % " ".join([f.filtermask for f in readerClazzes])) filters.append("*|All Files") self.widget.setFilter("\n".join(filters)) print "1 ################################################################" #def callbackFileSelected(args): #print "==================> callbackFileSelected %s" % args #if not self.widget.connect("fileSelected(QString)", callbackFileSelected): #raise "Failed to connect with filewidget \"fileSelected(QString)\" signal" def callbackFileHighlighted(*args): print "callbackFileHighlighted %s" % args file = args[0] print "Selected file: %s" % file global __main__ __main__._variableReadFile_ = file if not self.widget.connect("fileHighlighted(QString)", callbackFileHighlighted): raise "Failed to connect with filewidget \"fileHighlighted(QString)\" signal" #def callbackSelectionChanged(args): #print "==================> callbackSelectionChanged %s" % args #if not self.widget.connect("selectionChanged()", callbackSelectionChanged): #raise "Failed to connect with filewidget \"selectionChanged()\" signal" #def callbackFilterChanged(args): #print "==================> callbackFilterChanged %s" % args #if not self.widget.connect("filterChanged(QString)", callbackFilterChanged): #raise "Failed to connect with filewidget \"filterChanged(QString)\" signal" print "2 ################################################################" except: import traceback tb = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) forms.showMessageBox("Error","Error",tb) raise tb
def __init__(self, exporter): self.exporter = exporter self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("HTML Export") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed if not self.exporter.reader.hasFile(): openpage = self.dialog.addPage( "Open", "Read from OpenDocument Spreadsheet File", "document-open") self.openwidget = self.forms.createFileWidget( openpage, "kfiledialog:///kcellshtmlexportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter( "*.ods|OpenDocument Spreadsheet Files\n*|All Files") if not self.exporter.writer.hasFile(): savepage = self.dialog.addPage("Save", "Save to HTML File", "document-save") self.savewidget = self.forms.createFileWidget( savepage, "kfiledialog:///kcellshtmlexportsave") self.savewidget.setMode("Saving") self.savewidget.setFilter( "*.html *.htm *.xhtml|HTML Documents\n*|All Files") infospage = self.dialog.addPage("Infos", "HTML Document Informations", "document-properties") self.infoswidget = self.forms.createWidgetFromUIFile( infospage, os.path.join(self.exporter.currentpath, "htmlexportinfos.ui")) for i in self.exporter.reader.infos.keys(): w = self.infoswidget[i] w.setText(self.exporter.reader.infos[i]) layoutpage = self.dialog.addPage("Styles", "KCStyle of the HTML Document", "fill-color") layoutwidget = self.forms.createWidgetFromUI( layoutpage, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % (self.exporter.writer.styles._currentRow, self.exporter.writer.styles._uiItems)) print dir(layoutwidget) self.layoutlist = layoutwidget["List"]
def __init__(self, scriptaction): readerClazzes = [] global Reader for f in dir(Reader): if not f.startswith('_'): readerClazzes.append( getattr(Reader,f) ) forms = Kross.module("forms") self.dialog = forms.createDialog("Import File") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed try: openpage = self.dialog.addPage("Open","Import File","document-open") openwidget = forms.createFileWidget(openpage, "kfiledialog:///wordssampleimportfile") openwidget.setMode("Opening") #openwidget.minimumWidth = 540 #openwidget.minimumHeight = 400 filters = [] for f in readerClazzes: filters.append("%s|%s" % (f.filtermask,f.filtername)) if len(readerClazzes) > 1: filters.insert(0, "%s|All Supported Files" % " ".join([f.filtermask for f in readerClazzes])) filters.append("*|All Files") openwidget.setFilter("\n".join(filters)) if self.dialog.exec_loop(): file = openwidget.selectedFile() if not file: raise "No file selected" #print openwidget.currentMimeFilter().lower() def getReaderClazz(): for f in readerClazzes: for m in f.filtermask.split(' '): try: if file.lower().endswith( m[m.rindex('.'):].lower().strip() ): return f except ValueError: pass return None readerClazz = getReaderClazz() if not readerClazz: raise "No reader for file \"%s\"" % file readerClazz(file) except: #list = traceback.format_tb(sys.exc_info()[2], None) #s = traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]) tb = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) forms.showMessageBox("Error","Error","%s" % tb)
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Auto Remove Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Auto Remove"),t.i18n("Auto Remove"),"kt-remove") widget = forms.createWidgetFromUIFile(page,KTScriptingPlugin.scriptDir("auto_remove") + "auto_remove.ui") widget["finish_seeding"].checked = self.remove_on_finish_seeding widget["finish_downloading"].checked = self.remove_on_finish_downloading if dialog.exec_loop(): self.remove_on_finish_seeding = widget["finish_seeding"].checked self.remove_on_finish_downloading = widget["finish_downloading"].checked self.save()
def merge(): if Lokalize.projectOverview(): files=Lokalize.projectOverview().selectedItems() elif Editor.isValid(): files=[Editor.currentFile()] forms = Kross.module("forms") if not files: return if files[0].endswith('.po'): mergeOne=mergeOneGettext if os.system('which msgmerge')!=0: forms.showMessageBox("Error", i18n("Gettext not found"), i18n("Install gettext package for this feature to work")) else: if not tt_present: print 'error' #forms = Kross.module("forms") #forms.showMessageBox("Error", i18n("Translate-tolkit not found"), i18n("Install translate-toolkit package for this feature to work")) mergeOne=mergeOneOdf okCount=0 progress=0 if len(files)>1: progress=forms.showProgressDialog(i18n("Updating from templates..."), "") progress.setRange(0,len(files)) #progress.setMaximum(len(files)) counter=0 for po in files: if progress: progress.addText(po) progress.setValue(counter) counter+=1 ok=mergeOne(po) okCount+=ok if ok: editor=Lokalize.editorForFile(po) if editor: editor.reloadFile() if progress: progress.deleteLater() if mergeOne==mergeOneGettext: if len(files)==1: pot=potForPo(files[0]) if okCount: potModifSeconds=os.path.getmtime(pot) potModifDelta=datetime.timedelta(seconds=time.time()-potModifSeconds) potModifStr=time.strftime('%X %x %Z', time.localtime(potModifSeconds)) forms.showMessageBox("Information", i18n("Merge has been completed"), i18n("Merge has been completed.\nTemplate modification time: %1 (%2 days ago).",[str(potModifStr),potModifDelta.days])) else: if not os.path.exists(pot): forms.showMessageBox("Error", i18n("Merge failed."), i18n("Could not find template file for the merge:\n%1",[pot]))
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Auto Execute Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Auto Execute"), t.i18n("Auto Execute"), "system-run") widget = forms.createWidgetFromUIFile( page, KTScriptingPlugin.scriptDir("auto_execute") + "auto_execute.ui") widget["command_line"].setText(self.command) if dialog.exec_loop(): self.command = widget["command_line"].text self.save()
def __init__(self): self.embeddedInKSpread = False try: import KSpread self.kspread = KSpread self.embeddedInKSpread = True except ImportError: try: self.kspread = Kross.module("kspread") except ImportError: raise "Failed to import the Kross module. Please run this script with \"kross thisscriptfile.py\"" application = self.kspread.application() self.document = self.kspread.document() global Config self.filename = '' for f in Config.ReaderFiles: if os.path.isfile(f): self.filename = f break if self.embeddedInKSpread: if self.document.url(): self.setFile(self.document.url()) elif self.filename and self.filename != '': self.setFile(self.filename) self.openFile() elif self.document.url(): self.setFile(self.document.url()) self.infos = { 'Title' : self.document.documentInfoTitle() or Config.Infos['Title'], 'Subject' : self.document.documentInfoSubject() or Config.Infos['Subject'], 'Author' : self.document.documentInfoAuthorName() or Config.Infos['Author'], 'EMail' : self.document.documentInfoEmail() or Config.Infos['EMail'], 'Keywords' : self.document.documentInfoKeywords() or Config.Infos['Keywords'], 'Filename' : self.document.url() or Config.Infos['Filename'], 'Date' : datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), } print "Application: %s" % application print "Document: %s" % self.document #print dir(self.kspread) #print dir(application) #print dir(document) print "Filename: %s" % self.filename print "Embedded in KSpread: %s" % self.embeddedInKSpread print "Sheetnames: %s" % self.kspread.sheetNames()
def srcFileOpenRequested(filename, line): try: Editor.setSrcFileOpenRequestAccepted(True) except: print 'your lokalize needs update ;)' if not editor.isValid() or editor.currentFile()=='': return import Kross forms = Kross.module("forms") print filename (path, pofilename)=os.path.split(Editor.currentFile()) (package, ext)=os.path.splitext(pofilename) (upperPath, module)=os.path.split(path) if module.startswith('extragear-'): module=module.replace('extragear-','../extragear/') elif module.startswith('playground-'): module=module.replace('playground-','../playground/') elif module=='kdebase': trySubmodules=['workspace','apps','runtime'] for s in trySubmodules: if os.path.exists(ourPath+'/../../../KDE/kdebase/'+s+'/'+package): module=module+'/'+s print module break if package.startswith('desktop_'): while 1: try: package=package[package.index('_')+1:] except: break KdeTrunkPath=os.path.normpath(ourPath+'/../../../') mapSrcSuggest = mapSrc.get(package, '---') srcFilePath = subprocess.check_output(["/bin/bash", "-c", "/bin/find " + os.getenv("HOME")+"/dev/src/calligra/ | grep " + filename + "$"]).split('\n')[0] #srcFilePath = os.getenv("HOME")+"/dev/src/calligra/kexi/" + filename if len(srcFilePath): #os.system('kdialog --msgbox "'+srcFilePath + '%d' % line + '"') subprocess.call(['/usr/bin/kate', '-u', srcFilePath, '--line', '%d' % line]) print 'kate -u '+srcFilePath+(' --line %d &' % line) else: print "couldn't find. searched in:", print tryList answer=forms.showMessageBox("QuestionYesNo", "Could not find source file", "Searched in:\n"+'\n'.join(tryList)+""" Also searched using 'locate' command. Would you like to initiate websearch (using lxr.kde.org)? """) if answer=='Yes': os.system("kfmclient openURL 'http://lxr.kde.org/search?filestring=%s&string='" % filename)
def testUI(): forms = Kross.module("forms") dialog = forms.createDialog("My Dialog") dialog.setButtons("Ok|Cancel") print dir(dialog) page = dialog.addPage("Picture Selector","Select an image","document-open") #l = forms.createLayout(dialog,"QVBoxLayout") #label = forms.createWidget(page,"QLabel") #label.text = "Hello World Label" btn = forms.createWidget(page,"QPushButton") btn.text = "Next Picture" gview = forms.createWidget(page,"QGraphicsView") print dir(gview) if dialog.exec_loop(): forms.showMessageBox("Information", "Okay...", "The Ok-button was pressed")
def __init__(self, action, mykspread): self.action = action self.mykspread = mykspread self.config = mykspread.config forms = Kross.module("forms") self.dialog = forms.createDialog(T.i18n("Orca Screen Reader")) self.dialog.setButtons("None") self.dialog.setFaceType("Tabbed") #Auto Plain List Tree Tabbed #self.dialog.minimumWidth = 300 self.dialog.minimumHeight = 40 page = self.dialog.addPage(T.i18n("Action"), "") self.cellNameBtn = forms.createWidget(page, "QPushButton") self.cellNameBtn.text = T.i18n("Cell Name") #self.cellNameBtn.shortcut = "Ctrl+S" self.cellNameBtn.connect("clicked()", self.cellNameBtnClicked) self.cellValueBtn = forms.createWidget(page, "QPushButton") self.cellValueBtn.text = T.i18n("Cell Value") self.cellValueBtn.connect("clicked()", self.cellValueBtnClicked) self.sheetNameBtn = forms.createWidget(page, "QPushButton") self.sheetNameBtn.text = T.i18n("Sheet Name") self.sheetNameBtn.connect("clicked()", self.sheetNameBtnClicked) page = self.dialog.addPage("Option", "") self.cellNameCheckbox = forms.createWidget(page, "QCheckBox") self.cellNameCheckbox.text = T.i18n("Cell Name if selection changed") self.cellNameCheckbox.checked = self.config.cellNameOnSelectionChanged self.cellNameCheckbox.connect("stateChanged(int)", self.optionChanged) self.cellValueCheckbox = forms.createWidget(page, "QCheckBox") self.cellValueCheckbox.text = T.i18n("Cell Value if selection changed") self.cellValueCheckbox.checked = self.config.cellValueOnSelectionChanged self.cellValueCheckbox.connect("stateChanged(int)", self.optionChanged) self.sheetNameChanged = forms.createWidget(page, "QCheckBox") self.sheetNameChanged.text = T.i18n("Sheet Name if sheet changed") self.sheetNameChanged.checked = self.config.sheetNameOnSheetChanged self.sheetNameChanged.connect("stateChanged(int)", self.optionChanged) mykspread.__del__ = self.dialog.delayedDestruct self.dialog.show()
def testUI(): forms = Kross.module("forms") dialog = forms.createDialog("My Dialog") dialog.setButtons("Ok|Cancel") print dir(dialog) page = dialog.addPage("Picture Selector", "Select an image", "document-open") #l = forms.createLayout(dialog,"QVBoxLayout") #label = forms.createWidget(page,"QLabel") #label.text = "Hello World Label" btn = forms.createWidget(page, "QPushButton") btn.text = "Next Picture" gview = forms.createWidget(page, "QGraphicsView") print dir(gview) if dialog.exec_loop(): forms.showMessageBox("Information", "Okay...", "The Ok-button was pressed")
def __init__(self, action, mykspread): self.action = action self.mykspread = mykspread self.config = mykspread.config forms = Kross.module("forms") self.dialog = forms.createDialog(T.i18n("Orca Screen Reader")) self.dialog.setButtons("None") self.dialog.setFaceType("Tabbed") # Auto Plain List Tree Tabbed # self.dialog.minimumWidth = 300 self.dialog.minimumHeight = 40 page = self.dialog.addPage(T.i18n("Action"), "") self.cellNameBtn = forms.createWidget(page, "QPushButton") self.cellNameBtn.text = T.i18n("Cell Name") # self.cellNameBtn.shortcut = "Ctrl+S" self.cellNameBtn.connect("clicked()", self.cellNameBtnClicked) self.cellValueBtn = forms.createWidget(page, "QPushButton") self.cellValueBtn.text = T.i18n("Cell Value") self.cellValueBtn.connect("clicked()", self.cellValueBtnClicked) self.sheetNameBtn = forms.createWidget(page, "QPushButton") self.sheetNameBtn.text = T.i18n("Sheet Name") self.sheetNameBtn.connect("clicked()", self.sheetNameBtnClicked) page = self.dialog.addPage("Option", "") self.cellNameCheckbox = forms.createWidget(page, "QCheckBox") self.cellNameCheckbox.text = T.i18n("Cell Name if selection changed") self.cellNameCheckbox.checked = self.config.cellNameOnSelectionChanged self.cellNameCheckbox.connect("stateChanged(int)", self.optionChanged) self.cellValueCheckbox = forms.createWidget(page, "QCheckBox") self.cellValueCheckbox.text = T.i18n("Cell Value if selection changed") self.cellValueCheckbox.checked = self.config.cellValueOnSelectionChanged self.cellValueCheckbox.connect("stateChanged(int)", self.optionChanged) self.sheetNameChanged = forms.createWidget(page, "QCheckBox") self.sheetNameChanged.text = T.i18n("Sheet Name if sheet changed") self.sheetNameChanged.checked = self.config.sheetNameOnSheetChanged self.sheetNameChanged.connect("stateChanged(int)", self.optionChanged) mykspread.__del__ = self.dialog.delayedDestruct self.dialog.show()
def start(self): writer = KSpread.writer() filename = self.showImportDialog(writer) if not filename: return # no exception, user prob pressed cancel Plan = Kross.module("Plan") if Plan is None: raise Exception, T.i18n("Failed to start Plan. Is Plan installed?") Plan.openUrl(filename) proj = Plan.project() data = self.showDataSelectionDialog(writer, Plan) if len(data) == 0: raise Exception, T.i18n("No data to import") objectType = data[0] schedule = data[1] props = data[2] if len(props) == 0: raise Exception, T.i18n("No properties to import") record = [] if data[3] == True: for prop in props: record.append(proj.headerData(objectType, prop)) if not writer.setValues(record): if self.forms.showMessageBox( "WarningContinueCancel", T.i18n("Warning"), T.i18n( "Failed to set all properties of '%1' to cell '%2'", [", ".join(record), writer.cell()])) == "Cancel": return writer.next() if objectType == 0: # Nodes self.importValues(writer, proj, proj, props, schedule) if objectType == 1: # Resources for i in range(proj.resourceGroupCount()): self.importValues(writer, proj, proj.resourceGroupAt(i), props, schedule) if objectType == 2: # Accounts for i in range(proj.accountCount()): self.importValues(writer, proj, proj.accountAt(i), props, schedule)
def __init__(self, action, config): import Kross, KWord self.action = action self.config = config forms = Kross.module("forms") self.dialog = forms.createDialog("Import Doxygen XML File") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage("Open","Import Doxygen XML File","document-open") openwidget = forms.createFileWidget(openpage, "kfiledialog:///kwordsampleimportfile") openwidget.setMode("Opening") #openwidget.minimumWidth = 540 #openwidget.minimumHeight = 400 openwidget.setFilter("*.xml|XML Files\n*|All Files") configpage = self.dialog.addPage("Options","Import Options","preferences-other") configwidget = forms.createWidgetFromUIFile(configpage, os.path.join(action.currentPath(),"importdoxyxmloptions.ui")) stylepage = self.dialog.addPage("Styles","Cascading Style Sheet","preferences-web-browser-stylesheets") stylewidget = forms.createWidgetFromUIFile(stylepage, os.path.join(action.currentPath(),"importdoxyxmlstyle.ui")) styleedit = stylewidget["textEdit"] if self.dialog.exec_loop(): fileName = openwidget.selectedFile() if not fileName: raise "No file selected" self.config.FileName = fileName self.config.TableOfContent = configwidget["TocCheckBox"].checked self.config.IndexPage = configwidget["IndexPageCheckBox"].checked self.config.OtherPages = configwidget["OtherPagesCheckBox"].checked self.config.EnablePages = configwidget["PagesCheckBox"].checked self.config.PageDescription = configwidget["PageDescriptionCheckBox"].checked self.config.EnableClasses = configwidget["ClassesCheckBox"].checked self.config.ClassDescription = configwidget["ClassDescriptionCheckBox"].checked self.config.MemberDescription = configwidget["MemberDescriptionCheckBox"].checked self.config.EnableSlots = configwidget["SlotsCheckBox"].checked self.config.EnableSignals = configwidget["SignalsCheckBox"].checked self.config.EnableProperties = configwidget["PropertiesCheckBox"].checked self.config.EnableFunctions = configwidget["FunctionsCheckBox"].checked self.config.EnableVariables = configwidget["VariablesCheckBox"].checked self.importFile(styleedit.plainText)
def __init__(self, exporter): self.exporter = exporter self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("HTML Export") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed if not self.exporter.reader.hasFile(): openpage = self.dialog.addPage("Open","Read from OpenDocument Spreadsheet File","document-open") self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kspreadhtmlexportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter("*.ods|OpenDocument Spreadsheet Files\n*|All Files") if not self.exporter.writer.hasFile(): savepage = self.dialog.addPage("Save","Save to HTML File","document-save") self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kspreadhtmlexportsave") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.html *.htm *.xhtml|HTML Documents\n*|All Files") infospage = self.dialog.addPage("Infos","HTML Document Informations","document-properties") self.infoswidget = self.forms.createWidgetFromUIFile(infospage, os.path.join(self.exporter.currentpath, "htmlexportinfos.ui")) for i in self.exporter.reader.infos.keys(): w = self.infoswidget[i] w.setText( self.exporter.reader.infos[i] ) layoutpage = self.dialog.addPage("Styles","Style of the HTML Document","fill-color") layoutwidget = self.forms.createWidgetFromUI(layoutpage, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( self.exporter.writer.styles._currentRow , self.exporter.writer.styles._uiItems ) ) print dir(layoutwidget) self.layoutlist = layoutwidget["List"]
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Execute Action") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed self.objects = [ ('application', KWord.application()), ('shell', KWord.shell()), ('mainwindow', KWord.mainWindow()), ('document', KWord.document()), ] self.actions = [] for obj in self.objects: for s in dir(obj[1]): if s.startswith('slot'): self.actions.append("%s.%s" % (obj[0], s)) page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI( page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % (0, ''.join([ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.actions ]))) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.execAction()
def createConnection(self, projectfile): kexidb = Kross.module("kexidb") if not kexidb: raise "Failed to load the KexiDB Scripting module. This script needs Kexi to run." connectiondata = kexidb.createConnectionDataByFile(projectfile) if not connectiondata: raise "Invalid Kexi Project File: %s" % projectfile connectiondata.setFileName(projectfile) connectiondata.setDatabaseName(projectfile) driver = kexidb.driver(connectiondata.driverName()) if not driver: raise "No KexiDB driver for: %s" % connectiondata.driverName() connection = driver.createConnection(connectiondata) if not connection.connect(): raise "Failed to connect: %s" % connection.lastError() if not connection.useDatabase(connectiondata.databaseName()): raise "Failed to open database: %s" % connection.lastError() return connection
def showDialog(self): """ Shows the export-dialog and let the user define the imagefile to which the Krita image should be exported. """ import Kross forms = Kross.module("forms") dialog = forms.createDialog("Python Imaging Library Export") try: dialog.setButtons("Ok|Cancel") page = dialog.addPage("File","Export Image to File","document-save") widget = forms.createFileWidget(page, "kfiledialog:///kritapilexport") widget.setMode("Saving") widget.setFilter(self.getFilters()) if dialog.exec_loop(): self.filename = widget.selectedFile() self.doExport() finally: dialog.delayedDestruct()
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Execute Action") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed self.objects = [ ('application', Words.application()), ('shell', Words.shell()), ('mainwindow', Words.mainWindow()), ('document', Words.document()), ] self.actions = [] for obj in self.objects: for s in dir(obj[1]): if s.startswith('slot'): self.actions.append( "%s.%s" % (obj[0],s) ) page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI(page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.actions ] ) ) ) self.widgetlist = widget["List"] if self.dialog.exec_loop(): self.execAction()
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() #self.undostack = KSpread.undoStack() #self.undostack.connect("indexChanged(int)",self.indexChanged) #file = os.path(self.getLogDir(),"KSpread.log") self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(T.i18n("Logger")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed savepage = self.dialog.addPage(T.i18nc("Options page name", "Save"), T.i18n("Save to Log File"), "document-save") self.savewidget = self.forms.createFileWidget( savepage, "kfiledialog:///kspreadlogger") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.txt *.log|%(1)s\n*|%(2)s" % { '1': T.i18n("Log File"), '2': T.i18n("All Files") }) if self.dialog.exec_loop(): filename = self.savewidget.selectedFile() if os.path.isfile(filename): if self.forms.showMessageBox( "WarningContinueCancel", T.i18n("Overwrite file?"), T.i18n( "The file \"%1\" does already exist. Overwrite the file?", [filename])) != "Continue": raise Exception, T.i18n("Aborted.") sheetname = KSpread.currentSheet().sheetName() cellrange = "A1:F50" #FIXME try: self.file = open(filename, "w") self.startLogging(sheetname, cellrange) except IOError, (errno, strerror): raise Exception, T.i18n("Failed to write Log File \"%1\":\n%2", [filename], [strerror])
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Auto Resume Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Auto Resume"),t.i18n("Auto Resume"),"kt-bandwidth-scheduler") widget = forms.createWidgetFromUIFile(page,KTScriptingPlugin.scriptDir("auto_resume") + "auto_resume.ui") widget["auto_resume"].checked = self.auto_resume widget["hours"].value = self.hours widget["minutes"].value = self.minutes widget["seconds"].value = self.seconds widget["hours"].enabled = self.auto_resume widget["minutes"].enabled = self.auto_resume widget["seconds"].enabled = self.auto_resume if dialog.exec_loop(): self.auto_resume = widget["auto_resume"].checked self.hours = widget["hours"].value self.minutes = widget["minutes"].value self.seconds = widget["seconds"].value self.save() if self.auto_resume and KTorrent.paused(): self.startTimer()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.proj = KPlato.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(i18n("Busy Information Import")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage(i18n("Open"),i18n("Import Busy Info File"),"document-open") self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kplatobusyinfoimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } ) if self.dialog.exec_loop(): try: self.doImport( self.proj ) except: self.forms.showMessageBox("Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
def __init__(self, action, config): self.action = action self.config = config forms = Kross.module("forms") dialog = forms.createDialog(T.i18n("Import vCard")) #dialog.minimumWidth = 400 #dialog.minimumHeight = 300 dialog.setButtons("Ok|Cancel") dialog.setFaceType("List") #Auto Plain List Tree Tabbed filepage = dialog.addPage(T.i18n("Open"), T.i18n("vCard File"), "document-open") #deffile = "/home/kde4/vcardtest/addressbook.vcf" #"kfiledialog:///kspreadvcardimport" deffile = "kfiledialog:///kspreadvcardimport" self.openwidget = forms.createFileWidget(filepage, deffile) self.openwidget.setMode("Opening") self.openwidget.setFilter("*.vcf|%(1)s\n*|%(2)s" % { '1': T.i18n("vCard Files"), '2': T.i18n("All Files") }) datapage = dialog.addPage(T.i18n("Import"), T.i18n("Import to sheet beginning at cell"), "document-import") self.sheetslistview = KSpread.createSheetsListView(datapage) self.sheetslistview.setEditorType("Cell") if not dialog.exec_loop(): return vcardfilename = self.openwidget.selectedFile() if not os.path.isfile(vcardfilename): raise Exception, T.i18n("File '%1' not found.", [vcardfilename]) currentSheet = self.sheetslistview.sheet() if not currentSheet: raise Exception, T.i18n("No current sheet.") self.importVCardFile(vcardfilename, currentSheet)
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("CSV Import") self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage("Open", "Import from CSV File", "document-open") self.openwidget = self.forms.createFileWidget( openpage, "kfiledialog:///kcellscsvimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter( "*.csv *.txt|Comma-Separated-KCValue Files\n*|All Files") datapage = self.dialog.addPage("Import", "Import to sheet beginning at cell", "document-import") self.sheetslistview = KCells.createSheetsListView(datapage) self.sheetslistview.setEditorType("KCCell") optionspage = self.dialog.addPage("Options", "Comma Separated KCValue Options", "configure") self.optionswidget = self.forms.createWidgetFromUIFile( optionspage, os.path.join(self.currentpath, "csvoptions.ui")) if self.dialog.exec_loop(): try: self.doImport() except: self.forms.showMessageBox( "Error", "Error", "%s" % "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
def __init__(self, scriptaction): self.scriptaction = scriptaction #self.currentpath = self.scriptaction.currentPath() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog("Tool Actions") self.dialog.minimumWidth = 500 self.dialog.minimumHeight = 360 self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed self.actions = [] tool = KWord.tool() for n in tool.actionNames(): self.actions.append( "%s" % n ) page = self.dialog.addPage("", "") widget = self.forms.createWidgetFromUI(page, '<ui version="4.0" >' ' <class>Form</class>' ' <widget class="QWidget" name="Form" >' ' <layout class="QHBoxLayout" >' ' <item>' ' <widget class="QListWidget" name="List">' ' <property name="currentRow"><number>%i</number></property>' ' %s' ' </widget>' ' </item>' ' </layout>' ' </widget>' '</ui>' % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.actions ] ) ) ) self.widgetlist = widget["List"] if self.dialog.exec_loop(): if len(self.actions) > 0: self.execAction()
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.proj = Plan.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog( T.i18n("Busy Information Import")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed openpage = self.dialog.addPage(T.i18n("Open"), T.i18n("Import Busy Info File"), "document-open") self.openwidget = self.forms.createFileWidget( openpage, "kfiledialog:///kplatobusyinfoimportopen") self.openwidget.setMode("Opening") self.openwidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1': T.i18n("Resource Busy Information"), '2': T.i18n("All Files") }) if self.dialog.exec_loop(): try: Plan.beginCommand( T.i18nc("(qtundo_format)", "Import resource busy information")) self.doImport(self.proj) Plan.endCommand() except: Plan.revertCommand() self.forms.showMessageBox( "Error", T.i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
def __init__(self, scriptaction): self.scriptaction = scriptaction self.currentpath = self.scriptaction.currentPath() self.proj = Plan.project() self.forms = Kross.module("forms") self.dialog = self.forms.createDialog(i18n("Busy Information Export")) self.dialog.setButtons("Ok|Cancel") self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed datapage = self.dialog.addPage(i18n("Schedules"), i18n("Export Selected Schedule"), "document-export") self.scheduleview = Plan.createScheduleListView(datapage) savepage = self.dialog.addPage(i18n("Save"), i18n("Export Busy Info File"), "document-save") self.savewidget = self.forms.createFileWidget( savepage, "kfiledialog:///kplatobusyinfoexportsave") self.savewidget.setMode("Saving") self.savewidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1': i18n("Resource Busy Information"), '2': i18n("All Files") }) if self.dialog.exec_loop(): try: self.doExport(self.proj) except: self.forms.showMessageBox( "Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))