All pastes #900486 Raw Edit

Anonymous

public python v1 · immutable
·published 2008-02-11 22:54 UTC
rendered paste body
# This is Technology Preview (BETA) version of scripting# support in Kexi. The scripting API may change in details# in the next Kexi version.# For more information and documentation see# http://www.kexi-project.org/scripting/## Show the Total for the entire Year.class DataProvider:	def __init__(self):		import kexiapp		keximainwindow = kexiapp.get("KexiAppMainWindow")		try:			self.connection = keximainwindow.getConnection()		except:			raise "No connection established. Please open the project to be documented first."	def printConnection(self):		condata = self.connection.data()		infos = []		for item in ("caption", "description", "driverName", "hostName", "port", "userName", "fileName", "dbPath", "localSocketFileName", "serverInfoString"):			result = getattr(condata, item)()			if result != None and result != "" and (item != "port" or result != 0):				infos.append( (item, result) )		return infos	def printDriver(self):		driver = self.connection.driver()		result = [ ("Version", "%s.%s" % (driver.versionMajor(),driver.versionMinor())) ]		conlist = driver.connectionsList()		if len(conlist) > 0:			result.append( ("Connections",str(conlist)) )		return result	def printDatabases(self):		result = [ ("Current database", self.connection.currentDatabase()) ]		dbnames = self.connection.databaseNames()		if len(dbnames) > 0:			result.append( ("Databases",str(dbnames)) )		return result	def printTables(self):		result = []		for t in self.connection.tableNames():			tableschema = self.connection.tableSchema(t)			ti = []			for i in ("name", "caption", "description"):				v = getattr(tableschema,i)()				if v != None and v != "":					ti.append( (i,v) )			tf = []			for field in tableschema.fieldlist().fields():				tfi = []				for n in ("caption","description","type","subType","typeGroup","length","defaultValue"):					v = getattr(field,n)()					if v != None and v != "":						tfi.append( (n,v) )				props = []				for n in ("PrimaryKey","ForeignKey","AutoInc","UniqueKey","NotNull", "NotEmpty","Indexed","Unsigned"):					v = getattr(field,"is%s" % n)()					if v != None and v != "" and v != False and v != 0:						props.append( "%s " % n )				if len(props) > 0:					tfi.append( ("properties",props) )				tf.append( (field.name(), tfi) )			ti.append( ("fields", tf) )			if len(ti) > 0:				result.append( (t, ti) )		return result	def printQueries(self):		result = []		for q in self.connection.queryNames():			queryschema = self.connection.querySchema(q)			qi = []			for i in ("name", "caption", "description", "statement"):				v = getattr(queryschema,i)()				if v != None and v != "":					qi.append( (i,v) )			if len(qi) > 0:				result.append( (q, qi) )		return resultclass GuiApp:	def __init__(self, dataprovider):		self.dataprovider = dataprovider		try:			import gui		except:			raise "Import of the Kross GUI module failed."			self.dialog = gui.Dialog("Income for the Year...");		inputFrame = self.dialog.addFrame(self.dialog)		self.dialog.addLabel(inputFrame, "Year?")		#need to figure out how to add a text box		self.dialog.addLabel(inputFrame, "Input box to go here.")		btnFrame = self.dialog.addFrame(self.dialog)		self.dialog.addButton(btnFrame, "Calculate", self.doCalculate)		self.dialog.addButton(btnFrame, "Cancel", self.doCancel)			self.dialog.show()	def doCancel(self):		self.dialog.close()		self.dialog = None	def doCalculate(self):		#need to figure out how to query and add up the values for the message box below		msgBox = self.dialog.showMessageBox("info", "Income Total:", "%s" % "$3000")		msgBox.show()		self.doCancel()GuiApp( DataProvider() )