Example #1
0
			def __init__(self, parentwidget, label = "Sheet:"):
				global ListWidget
				ListWidget.__init__(self, parentwidget, label)

				try:
					import krosskspreadcore
					document = krosskspreadcore.get("KSpreadDocument")
					for sheetname in document.sheetNames():
						self.combo.insertItem(sheetname)
				except:
					import traceback
					trace = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
					print trace
Example #2
0
	def __init__(self, scriptpath, parent):
		self.scriptpath = scriptpath
		if not hasattr(__main__,"scripteditorfilename"):
			__main__.scripteditorfilename = self.getFileName("myscript.py")

		import krosskspreadcore
		self.doc = krosskspreadcore.get("KSpreadDocument")

		import os, qt
		qt.QDialog.__init__(self, parent, "MainDialog", 1, qt.Qt.WDestructiveClose)
		self.setCaption("Script Editor")
		
		layout = qt.QVBoxLayout(self)
		box = qt.QVBox(self)
		box.setMargin(4)
		box.setSpacing(10)
		layout.addWidget(box)

		menu = qt.QMenuBar(box)

		splitter = qt.QSplitter(box)
		splitter.setOrientation(qt.Qt.Vertical)

		self.scripttext = qt.QMultiLineEdit(splitter)
		self.scripttext.setWordWrap( qt.QTextEdit.NoWrap )
		self.scripttext.setTextFormat( qt.Qt.PlainText )
		qt.QObject.connect(self.scripttext, qt.SIGNAL("cursorPositionChanged(int,int)"),self.cursorPositionChanged)

		self.console = qt.QTextBrowser(splitter)
		splitter.setResizeMode(self.console, qt.QSplitter.KeepSize)

		statusbar = qt.QStatusBar(box)
		self.messagestatus = qt.QLabel(statusbar)
		statusbar.addWidget(self.messagestatus,1)
		self.cursorstatus = qt.QLabel(statusbar)
		statusbar.addWidget(self.cursorstatus)
		self.cursorPositionChanged()

		box.setMinimumSize( qt.QSize(680,540) )

		filemenu = qt.QPopupMenu(menu)
		menu.insertItem("&File", filemenu)
		
		newaction = qt.QAction("New", qt.QKeySequence("CTRL+N"), self)
		qt.QObject.connect(newaction, qt.SIGNAL("activated()"), self.newFile)
		newaction.addTo(filemenu)

		openaction = qt.QAction("Open...", qt.QKeySequence("CTRL+O"), self)
		qt.QObject.connect(openaction, qt.SIGNAL("activated()"), self.openFileAs)
		openaction.addTo(filemenu)

		saveaction = qt.QAction("Save", qt.QKeySequence("CTRL+S"), self)
		qt.QObject.connect(saveaction, qt.SIGNAL("activated()"), self.saveFile)
		saveaction.addTo(filemenu)

		saveasaction = qt.QAction("Save as...", qt.QKeySequence("CTRL+A"), self)
		qt.QObject.connect(saveasaction, qt.SIGNAL("activated()"), self.saveFileAs)
		saveasaction.addTo(filemenu)

		filemenu.insertSeparator()
		
		quitaction = qt.QAction("Quit", qt.QKeySequence("CTRL+Q"), self)
		qt.QObject.connect(quitaction, qt.SIGNAL("activated()"), self.close)
		quitaction.addTo(filemenu)

		editmenu = qt.QPopupMenu(menu)
		menu.insertItem("&Edit", editmenu)

		undoaction = qt.QAction("Undo", qt.QKeySequence("CTRL+Z"), self)
		qt.QObject.connect(undoaction, qt.SIGNAL("activated()"), self.scripttext.undo)
		undoaction.addTo(editmenu)

		redoaction = qt.QAction("Redo", qt.QKeySequence("CTRL+Shift+Z"), self)
		qt.QObject.connect(redoaction, qt.SIGNAL("activated()"), self.scripttext.redo)
		redoaction.addTo(editmenu)

		editmenu.insertSeparator()

		cutaction = qt.QAction("Cut", qt.QKeySequence("CTRL+X"), self)
		qt.QObject.connect(cutaction, qt.SIGNAL("activated()"), self.scripttext.cut)
		cutaction.addTo(editmenu)

		copyaction = qt.QAction("Copy", qt.QKeySequence("CTRL+C"), self)
		qt.QObject.connect(copyaction, qt.SIGNAL("activated()"), self.scripttext.copy)
		copyaction.addTo(editmenu)

		pasteaction = qt.QAction("Paste", qt.QKeySequence("CTRL+V"), self)
		qt.QObject.connect(pasteaction, qt.SIGNAL("activated()"), self.scripttext.paste)
		pasteaction.addTo(editmenu)

		clearaction = qt.QAction("Clear", qt.QKeySequence("CTRL+Shift+X"), self)
		qt.QObject.connect(clearaction, qt.SIGNAL("activated()"), self.scripttext.clear)
		clearaction.addTo(editmenu)

		editmenu.insertSeparator()

		selallaction = qt.QAction("Select All", 0, self)
		qt.QObject.connect(selallaction, qt.SIGNAL("activated()"), self.scripttext.selectAll)
		selallaction.addTo(editmenu)

		scriptmenu = qt.QPopupMenu(menu)
		menu.insertItem("&Script", scriptmenu)

		compileaction = qt.QAction("Compile", qt.QKeySequence("F9"), self)
		qt.QObject.connect(compileaction, qt.SIGNAL("activated()"), self.compileScript)
		compileaction.addTo(scriptmenu)

		executeaction = qt.QAction("Execute", qt.QKeySequence("F10"), self)
		qt.QObject.connect(executeaction, qt.SIGNAL("activated()"), self.executeScript)
		executeaction.addTo(scriptmenu)

		self.samplemenu = qt.QPopupMenu(menu)
		menu.insertItem("&Samples", self.samplemenu)
		itemid = 500
		global Samples
		for samplename in dir(Samples):
			if samplename.startswith("_"): continue
			itemid += 1
			menu = qt.QPopupMenu(self.samplemenu)
			qt.QObject.connect(menu, qt.SIGNAL("activated(int)"), self.sampleActivated)
			self.samplemenu.insertItem(samplename, menu, -1, self.samplemenu.count() - 1)
			attr = getattr(Samples,samplename)
			for a in dir(attr):
				if a.startswith("_"): continue
				itemid += 1
				child = getattr(attr,a)
				itemid = menu.insertItem(child.name, itemid)
				menu.setWhatsThis(itemid,"%s/%s" % (samplename,a))

		if os.path.exists(__main__.scripteditorfilename):
			self.openFile(__main__.scripteditorfilename)
Example #3
0
	def __init__(self, scriptpath, parent):
		self.scriptpath = scriptpath

		import krosskspreadcore
		self.doc = krosskspreadcore.get("KSpreadDocument")

		import qt
		qt.QDialog.__init__(self, parent, "Dialog", 1, qt.Qt.WDestructiveClose)
		self.setCaption("Export to HTML File")
		layout = qt.QVBoxLayout(self)
		box = qt.QVBox(self)
		box.setMargin(10)
		box.setSpacing(10)
		layout.addWidget(box)

		sheetbox = qt.QHBox(box)
		sheetbox.setSpacing(6)
		sheetlabel = qt.QLabel("Sheet:",sheetbox)
		self.sheetcombo = qt.QComboBox(sheetbox)
		currentsheetname = self.doc.currentSheet().name()
		for sheetname in self.doc.sheetNames():
			self.sheetcombo.insertItem(sheetname)
			if sheetname == currentsheetname:
				self.sheetcombo.setCurrentItem(self.sheetcombo.count() - 1)
		sheetlabel.setBuddy(self.sheetcombo)
		sheetbox.setStretchFactor(self.sheetcombo,1)

		self.styles = {
			"Paper" :
				"html { background-color:#efefef; }"
				"body { background-color:#fafafa; color:#303030; margin:1em; padding:1em; border:#606060 1px solid; }"
			,
			"Plain" :
				"html { background-color:#ffffff; color:#000; }"
				"body { margin:1em; }"
			,
			"Seawater" :
				"html { background-color:#0000aa; }"
				"body { background-color:#000066; color:#efefff; margin:1em; padding:1em; border:#00f 1px solid; }"
				"h1 { color:#0000ff; }"
				"th { color:#6666ff; }"
			,
		}

		stylebox = qt.QHBox(box)
		stylebox.setSpacing(6)
		stylelabel = qt.QLabel("Style:",stylebox)
		self.stylecombo = qt.QComboBox(stylebox)
		stylenames = self.styles.keys()
		stylenames.sort()
		for stylename in stylenames:
			self.stylecombo.insertItem(stylename)
		stylelabel.setBuddy(self.stylecombo)
		stylebox.setStretchFactor(self.stylecombo,1)

		filebox = qt.QHBox(box)
		filebox.setSpacing(6)
		filelabel = qt.QLabel("File:",filebox)
		self.fileedit = qt.QLineEdit(self.getDefaultFile(),filebox)
		btn = qt.QPushButton("...",filebox)
		qt.QObject.connect(btn, qt.SIGNAL("clicked()"),self.browseClicked)
		filelabel.setBuddy(self.fileedit)
		filebox.setStretchFactor(self.fileedit,1)

		btnbox = qt.QHBox(box)
		btnbox.setSpacing(6)
		okbtn = qt.QPushButton(btnbox)
		okbtn.setText("Export")
		okbtn.setDefault(True)
		qt.QObject.connect(okbtn,qt.SIGNAL("clicked()"),self.startExport)
		cancelbtn = qt.QPushButton(btnbox)
		cancelbtn.setText("Cancel")
		qt.QObject.connect(cancelbtn,qt.SIGNAL("clicked()"),self.close)

		box.setMinimumWidth(480)