On Saturday 22 November 2008 07:55:31 pm Bob Sysero llc Dev wrote:
> Dear Dabo-Users,
>
>  I was able to get the Create a OpenOffice SpreadSheet Example to work
> and I would like to demo it to in my Form that I created with the
> ClassDesigner.  The module is in ui directory called DaboSpreadSheet.py.
> What I like to do is call the module in my Form by pressing a Button
> using the OnHit event.

Normally, you would create a method to accept the event (the click event) and 
do something in the method.  From ClassDesigner (CD) right click on the 
button you want to use.  Choose to 'Edit Code' and CD will create method 
named "onHit".   In that method you could add the code to create the 
spreadsheet.  Don't forget the "import ooolib".  Actually, you can added the 
import in the method - but it might be better to add it using "Manage 
Imports" (upper right button of the CD Editor). 

I can tell you are experiencing a learning curve with Dabo.  So I thought I 
would provide a little code that does what you were describing.  The code is 
different than using what you would see from CD.  But maybe seeing the code 
will better explain what you are doing in CD.  There are many ways to skin a 
cat in Dabo and my example is just one.  Keep playing and you'll learn.

#import sqlite3
#conn = sqlite3.connect('/home/johnf/asqldemo/example.db')

### Create table
#conn.execute("drop table customers")
#conn.execute("create table customers (id INTEGER PRIMARY KEY, fname 
CHAR,valid INT)")
#conn.execute("insert into customers (fname, valid) values ('John', 1)")
#conn.execute("insert into customers (fname, valid) values ('Larry', 2)")
#conn.execute("insert into customers (fname, valid) values ('Ed', 3)")
#conn.execute("insert into customers (fname, valid) values ('Viola', 4)")
#conn.execute("insert into customers (fname, valid) values ('Bill', 5)")
#conn.execute("insert into customers (fname, valid) values ('Pascale', 6)")
#conn.execute("insert into customers (fname, valid) values ('Donna', 7)")
####conn.execute("commit")
##print conn.execute('Select * from customers').fetchall()
##c.close()
"""I created the database and table from above.  You should use your 
database"""

import dabo
dabo.ui.loadUI('wx')


class MainForm(dabo.ui.dForm):
    """If you are using ClassDesigner you might have a different name for this 
class.  I could be 'dForm' or 'DesForm'.
    Or you could have renamed the MainFormClass"""
    def afterInit(self):
        """ The ClassDesigner does most of this for you when it runs.  So 
Normally you do NOT see the code below.
        But I thought it would be nice if you saw the code using hand 
coding."""
        self.Sizer=vs=dabo.ui.dSizer('v')
        vs.appendSpacer(10)
        # I thought it might be nice to see your data.  To that end I provided 
a simple grid
        custGrid = dabo.ui.dGrid(self,RegID="custgridID",AlternateRowColoring 
=True,ColumnCount=2,SelectionMode = "Row",Editable = True,MovableColumns = 
False)
        custGrid.DataSource = 'customers'
        custGrid.Columns[0].Caption ="Name"
        custGrid.Columns[0].DataField = "name"
        custGrid.Columns[1].Caption ="Valid"
        custGrid.Columns[1].DataField = "valid"
        vs.append(custGrid,1,'x')
        
        """ Ok below is the button you wanted to create the spreadsheet.  I am 
using a short cut by using the "OnHit".
        But all it does is call a method "createSpreadSheet" the same as if 
you were to use the edit of the button in ClassDesigner"""
        
        vs.append(dabo.ui.dButton(self,Caption='Create 
Spreadsheet',RegID='thebuttonID',OnHit=self.createSpreadSheet))

    def createSpreadSheet(self,evt):
        """clicking on the button causes Dabo run the code below - your 
code"""
        import ooolib  ##place the ooolib.py in the same folder as your code
        doc = ooolib.Calc()
        
        localDataSet=self.PrimaryBizobj.getDataSet()
        
        row_num=1
        for row in localDataSet:
            col_num=1
            for cols in row.keys():
                if type(row[cols]) is bool:
                    columntype='bool'
                elif type(row[cols]) is int:
                    columntype='float'
                elif type(row[cols]) is unicode:
                    columntype='string'
                # OK let's write out the data to spreadsheet
                doc.set_cell_value(col_num, row_num, columntype,row[cols])
                col_num=col_num+1
            row_num=row_num+1
        # Save the document to the file you want to create.
        # You need to change the path to match your environment
        doc.save("dabo-example01.ods")
        
    def afterInitAll(self):
        """I have to tell Dabo to get the data from the database"""
        self.requery()
    
    def createBizobjs(self):
        self.Application.addConnectFile("expamleConnection.cnxml")
        self.conn = self.Application.getConnectionByName("myconnName")
        """ The above uses a connect file created by CxnEditor.  Nothing 
special
        is being done here.  ClassDesigner will create a similar connect for 
you"""
        
        class customerBizobj(dabo.biz.dBizobj):
            """Below I need to describe the data I want to use"""
            def afterInit(self):
                self.DataSource = "customers"
                self.addFrom("customers")
                self.addField("name")
                self.addField("valid")
                
        """The above was a class.  So now I need to use (create an instance) 
of the class.
        Then I tell Dabo to add the instance as a biz-object"""    
        custBizobj = customerBizobj(self.conn)
        self.addBizobj(custBizobj)
       

if __name__ == "__main__":
    """This the normal way of starting a Dabo application.  The 'app' is a 
instance of dabo.dApp()"""
    app = dabo.dApp()
    app.BasePrefKey = "Example"
    app.setAppInfo("appName", "example")
    app.MainFormClass = MainForm
    app.start() 



-- 
John Fabiani


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to