Re: [dabo-users] Dabo! Everyone's answer to my question!

Author: John Fabiani

Posted: 2012-06-05 at 19:38:23

On 06/05/2012 05:24 PM, Simon Cropper wrote:

> On 06/06/12 10:10, Paul McNett wrote:

>> On 6/5/12 4:49 PM, Simon Cropper wrote:

>>> Well I'm here. I am willing to be shown...

>>>

>>> So, I will throw up an apparently simple challenge. John, show me how I

>>> can open a simple sqlite table and present the data in a window/frame in

>>> an editable grid. Don't worry about the fluff, just the basic bones. The

>>> code should be able to be pointed at any sqlite table. In other words

>>> the grid is created and populated on the fly. In VFP parlance an

>>> editable "browse" window that supposedly could be pointed at any

>>> database table.

>> Here's a single script that creates the database, a bare-bones bizobj, and a

>> bare-bones UI. I hope this gets you started!

>>

>> http://paulmcnett.com/test_grid_editable_sqlite.py

>>

>> Paul

>> _______________________________________________

>> Post Messages to: Dabo-users@leafe.com

>> 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/4FCE9FE9.3040208@ulmcnett.com

> Hi Paul,

>

> Considering the bulk of this script is involved with creating a table

> with data that is quite a small amount of code.

>

> The code does however implies a knowledge of the underlying table

> structure. Is it possible to extract the structural elements of a table,

> like the field names, field type, etc so a grid could be created on the fly?

>

> The pseudo code would be something like...

>

> 1. connect to table

> 3. work out number of fields (F#)

> 4. create a grid with same number of columns

> 5. populate said grid

>

Dabo has a method "browse" (like in VFP) that will accept any dataset.

Read below:

def browse(dataSource, parent=None, keyCaption=None, includeFields=None,

colOrder=None, colWidths=None, colTypes=None, autoSizeCols=True):

"""

Given a data source, a form with a grid containing the data

is created and displayed. If the source is a Dabo cursor object,

its getDataSet() method will be called to extract the data.

If parent is passed, the form isn't created, and the browsegrid

becomes a child of parent instead.

The columns will be taken from the first record of the dataset,

with each

column header caption being set to the field name, unless the

optional

keyCaption parameter is passed. This parameter is a 1:1 dict containing

the data set keys as its keys, and the desired caption as the

corresponding value.

If the includeFields parameter is a sequence, the only columns

added will

be the fieldnames included in the includeFields sequence. If the

includeFields parameter is None, all fields will be added to the

grid.

The columns will be in the order returned by ds.keys(), unless the

optional colOrder parameter is passed. Like the keyCaption property,

this is a 1:1 dict containing key:order.

"""

So your job is to learn how to make a connection to the database. But

first you need to insure the setup is right - many newbies run into

trouble when they setup.

Johnf

_______________________________________________

Post Messages to: Dabo-users@leafe.com

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/4FCEA67F.2080007@jfcomputer.com

©2012 John Fabiani