I'm trying to code a GUI to interface with a SQL database like postgresql
And I'm looking for some tutorial or resources.
Specialy I'm looking for good practice for coding how to fetch data from
widgets and update database.
Psycopg2 is OK for me (well a little...). My problem is the code that
"connect" wxPython to psycopg2
Thanks for your help
There is some information on this on the wxPython wiki.
http://wiki.wxpython.org/FrontPage?action=fullsearch&context=180&value=data+aware&titlesearch=Titles
You might also want to check out Dabo, a framework on top of wxPython.
http://dabodev.com/
Werner
I'm currently using SQLite3 more than PostgreSQL, so I don't recall the
psycopg syntax. Regardless, the first thing you do is establish a connection
to the database and define a cursor.
To get values from the widgets, use variablename = <widgetname>.GetValue()
for text and variablename = <widgetname>.GetStringSelection() for radioboxes
and similar widgets that use enumerations. If you have spin controls with
numbers, you'll probably be casting them from the displayed strings to
floats/reals for insertion into the database. Similarly, when you retrieve
those data you'll need to cast them to str() before .SetValue or
.SetStringSelection() is used to display them.
As I recall, pysopg has decent documentation, and there may be a mail list
specific to the library, too.
HTH,
Rich
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
> Dabo was created for this type of work. Sqlite and Postgres are well
> supported. Take the time and visit http://www.dabodev.com.
Depends on the application, John. Like in every other situation, one size
does not fit all.
Rich Shepard schrieb:
hey. I just had the same problem.
I used the following. I hope it helps, but I dont know whether it is the
right way to fill the listbox...
db = pgdb.connect(host = '63.216.13.25', database = 'fohen',
user = 'foh', password = 'xxx')
cursor = db.cursor()
cursor.execute ('SELECT "tbl_Produkte"."Artikelnr",
"tbl_Produkte"."Farbe" FROM "tbl_Produkte" '
'WHERE "tbl_Produkte"."HerstellerID" = \'' + strHerstellerID +
'\' ')
dbNestedList = cursor.fetchall()
dbList = []
#for i in range (0,len(dbNestedList)):
# dbList = dbList + [dbNestedList[i][0]] + '\', \'' +
[dbNestedList[i][1]]
#print dbList
self.ListboxQuelle.Clear()
self.ListboxQuelle.InsertItems( dbList, 0)
Rich Shepard wrote:
> On Sat, 13 Oct 2007, johnf wrote:
>
>> Dabo was created for this type of work. Sqlite and Postgres are well
>> supported. Take the time and visit http://www.dabodev.com.
>
> Depends on the application, John. Like in every other situation, one
> size
> does not fit all.
>
and if you get it to work ;-)
Dabo is undoubted meant as a solid "professional" package,
it has a very professional looking website, but ...
... I think many people won't give the feedback Dabo definitely needs ...
... and I wasn't given it either, until this message triggered me.
Why I didn't give my feedback:
"if I can't run such a professional package, it must be my own stupid /
limited behavior !!"
So it here it goes (no offences, Ed helped me with a lot of other
problems ;-):
I tried to use Dabo at least twice and have thrown in the garbage can
also twice.
The last time was last week,
I downloaded and tried about everything,
- I couldn't get Dabo working: complaining about all kinds ob missing
modules
- The demos worked ok.
- The IDE only give a flash of a black screen.
After running it from a DOS box explicitly (which is quit complicated
for windows modern users !!),
I saw the message, something like "the IDE is not realized yet" .
- The windows installer didn't work, don't know the error message (if I
did see any at all)
So maybe the website should look somewhat less professional ;-)
giving real information (like the IDE not yet working, and no download
for the IDE),
and more inviting for people to report their problems.
-- quote --
Oh, and if you are a disenchanted *Visual Basic* developer, you've found
the right place, too. wink!
-- end quote --
I was one of the first users of VB, (switched to Delphi as soon as it
was released)
and even that first version of VB did want it promised and worked right
out the box,
which can't be said of Dabo ;-)
keep on the good work,
cheers,
Stef
> I'm forwarding this to Ed, with the suggestion that things like the
> IDE that aren't working should either be removed, or display a
> messagebox-type explanation instead of a printout to a terminal.
That's a good suggestion. I've just deleted IDE.py from Subversion.
Are there any other cases of "dead wood" that need to be cleaned up?
> Not everyone using Windows is capable of using the command prompt.
<rof,l!>
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
> - The IDE only give a flash of a black screen.
> After running it from a DOS box explicitly (which is quit complicated
> for windows modern users !!),
> I saw the message, something like "the IDE is not realized yet" .
This confused me, too, until I asked on the list and was told to run
the separate tools (Class Designer, etc.) separately. Once I ran that,
I was able to create great-looking apps in almost no time.
I'm forwarding this to Ed, with the suggestion that things like the
IDE that aren't working should either be removed, or display a
messagebox-type explanation instead of a printout to a terminal. Not
everyone using Windows is capable of using the command prompt.
--
# p.d.
> > I'm forwarding this to Ed, with the suggestion that things like the
> > IDE that aren't working should either be removed, or display a
> > messagebox-type explanation instead of a printout to a terminal.
>
> That's a good suggestion. I've just deleted IDE.py from Subversion.
> Are there any other cases of "dead wood" that need to be cleaned up?
Wow, that was fast. I suppose I should be used to quick responses from
the Dabo team by now, but I'm still impressed.
I'll let you know if I find anything else.
--
# p.d.
> Dabo 0.8.0.2 is really a great improvement over previous releases,
> (at least for windows users ;-)
> everything works just right out of the box,
> my compliments !!
Thanks! We have been working hard on it.
> The only thing I couldn't run to the end was the application wizard,
> I downloaded webtest.sqlite,
> the app wizard sees 4 tables in the database,
> so I can get to "finish"
> but pressing "finish" hangs the program.
Did you get any traceback or anything else that would give a clue?
Could it be a permissions thing? (i.e., did you select to create your
app in a directory in which you do not have write permission?)
Dabo 0.8.0.2 is really a great improvement over previous releases,
(at least for windows users ;-)
everything works just right out of the box,
my compliments !!
The only thing I couldn't run to the end was the application wizard,
I downloaded webtest.sqlite,
the app wizard sees 4 tables in the database,
so I can get to "finish"
but pressing "finish" hangs the program.
cheers,
Stef Mientki
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-user...@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-...@lists.wxwidgets.org
>
>
>
Sorry, can't help any more with the Runtime for 0.8.2 as in my win2000
it doesn't even start up.
Uwe
> No, I've write permission all over the place so that can't be the
> problem.
OK, just ruling out the obvious. Also, did you install the regular
or the 'console' version of the runtime engine? You won't get any
debug output from the regular version.
> But maybe you help me to get in running in my IDE,
> so I can follow what's happening,
> and trace the problem.
>
> I've installed dabo runtime : at P:\Dabo Runtime\....
> So to get it running in my IDE, I added
>
> sys.path.append ( 'P:\\Dabo Runtime\\' )
>
> to the top of: AppWizard.py
That shouldn't be necessary, but then again, I haven't tried running
AppWizard from inside any IDEs.
> Now the program hangs in about.py, at
> class About(dabo.ui.dDialog):
>
> telling me: AttributeError: 'module' object has no attribute
> 'dDialog'
> and indeed I can't find a "dDialog.py'.
It's most likely because you are not setting the UI to "wx". There
are lots of places in Dabo where there is code like:
if __name__ == "__main__":
dabo.ui.loadUI("wx")
...which loads the ui.uiwx namespace into the ui namespace. Since you
are running from an IDE, these would never execute. The AppWizard
also has some code that is bracketed by another __name__ test, so you
would be missing that, too. And if your IDE is wxPython based (such
as SPE), you won't have the correct Application object.
Let's keep things simple. Did you install the icons on the desktop?
Then there should be a 'Dabo Shortcuts' icon. Open that, and double-
click the 'AppWizard' icon. When you run it this way, does the
AppWizard work correctly?
> Is there a better way to run the program from an IDE ?
> Which paths do I have to the PythonPath ?
If you have an IDE that you use to run Python and wxPython stuff
from, I'm wondering why you chose the Runtime Engine, which comes
with its own copy of those and other prerequisites. Why not just
install the regular Dabo package?
Ed Leafe wrote:
> On Oct 28, 2007, at 11:18 AM, Stef Mientki wrote:
>
>> I used the regular MSI installer.
>> So now I also installed the console MSI installer,
>> and that works great.
>
> You mean that it doesn't hang when you run AppWizard from your IDE?
Back to the base:
I download and run the regular MSI installer from the shortcuts on my
desktop: appwizard hangs on the "finish" button.
I download and run the console MSI installer from the shortcuts on my
desktop: appwizard runs fine.
>> - So still wonder why the regular version is not working ?
>
> They are identical, except for the setup.py keyword of "windows"
> instead of "console".
so there must be some differences ;-)
>
>> - Also wonder why the console version knows what database I used
>> previous in the regular version,
>> while I thought I've read somewhere about not using windows registry ??
>
> You think that the registry is the only place information can be
> stored? ;-)
>
> Look in "c:\Documents and Settings\<your login>\Application
> Data\Dabo". There is a small SQLite database that is used for
> settings, preferences and saved values. Did you notice that windows
> remember their size and position between runs? That's also stored there.
Nice trick, didn't release that, because for me that's the same as the
registry ;-)
my company runs Managed Workplaces, so whatever is in the documents and
settings is spread wherever I log in ;-)
Why not place that information in the program directory,
portable applications are becoming very popular ;-)
>
>> I started just as simple as you now advice ....
>> ... but then the problem occurred: it hangs ;-)
>
> After clicking 'Finish', or when you launch it?
after clicking " Finish"
>
>>> If you have an IDE that you use to run Python and wxPython stuff
>>> from, I'm wondering why you chose the Runtime Engine, which comes
>>> with its own copy of those and other prerequisites. Why not just
>>> install the regular Dabo package?
>>>
>> For the moment I'm just looking at Dabo,
>> and to locate problems it's the best to eliminate as much
>> uncertainties as possible,
>> so that's why I choose to use my default IDE ;-)
>
> That's funny, actually, because by running it from an IDE, you're
> adding more uncertainties! ;-)
>
yes you might be right !
> BTW, which IDE are you using? We've had some problems in the past
> with users running under Wing, as Wing changes the Python environment
> when it is running.
I use PyScripter with a remote Python engine,
and so it might run my default Python version, (that's one of the things
I still don't understand )
and might introduce more uncertainties ;-)
thanks,
Stef Mientki