Snee's advice is good!
SQLIte, small, powerful, standard pymodule :)
Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster
stvrich commented: Kindly contributed His Own experience +1
Snee's advice is good!
SQLIte, small, powerful, standard pymodule :)
wxPython isn't yet out and I asked on the mail list, there is no nearby plan to port it to 3k. So Stick with your python 2.x version.
I also hope haven't missed any module apart from mentioned above
IDLE have been reported to be troublesome, especially in GUI apps
Just check for modified version that can be downloaded at www.vpython.org
I got help form www.python-forum.org and I came up with this version of the program. Although it works, it throws errors:
Code
import wx
class TestTree(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
#Menu & toolbar stuffs
menubar = wx.MenuBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_EXIT, "Exit", "Exit this small app")
self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_EXIT)
menubar.Append(filemenu, "File")
self.SetMenuBar(menubar)
self.CreateToolBar()
self.CreateStatusBar()
self.SetStatusText("This small app")
self.panel = wx.Panel(self, -1)
self.books = wx.TreeCtrl(self.panel, -1, size = (120, 200), style = wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
self.child = self.books.AddRoot("The Library")
self.Populate()
#Bind to events
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnChanged, self.books)
self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnExpanded, self.books)
self.tc = wx.TextCtrl(self.panel, -1, style = wx.TE_MULTILINE|wx.NO_BORDER)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.books, 0, wx.EXPAND)
hbox.Add(self.tc, 1, wx.EXPAND)
self.panel.SetSizer(hbox)
self.Layout()
def OnExpanded(self, evt):
selected = evt.GetItem()
self.bookparent = self.books.GetItemText(selected)
def OnChanged(self, evt):
selected = evt.GetItem()
parent = self.books.GetItemParent(selected)
text = "\t Selected Book "+self.books.GetItemText(selected)+ " of type "+ self.books.GetItemText(parent)+"\n"
self.tc.WriteText(text)
def OnClose(self, evt):
self.Close()
def Populate(self):
BooksList = ["Biology", "Physics", "History", "Computer", "Telecommunications"]
for book in BooksList:
j = self.books.AppendItem(self.child, book)
index = BooksList.index(book)
for k in range(1,5):
self.books.AppendItem(j, str(k))
if (__name__ == "__main__"):
app = wx.App(False)
f = TestTree(None, -1, "Testing tree control")
f.Show()
app.MainLoop()
Error:
Traceback (most recent call last):
File "i:\Hosanna\Programmer Codes\Python\treectrl.py", line 43, in OnChanged
text = "\t Selected Book "+self.books.GetItemText(selected)+ " of type "+ self.books.GetItemText(parent)+"\n"
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 5303, in GetItemText
return _controls_.TreeCtrl_GetItemText(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "tvItem->hItem != ((HTREEITEM)(ULONG_PTR)-0x10000)" failed at ..\..\src\msw\treectrl.cpp(854) in wxTreeCtrl::DoGetItem(): can't retrieve virtual root item
for more info just perruzzi here at wikipedia
http://en.wikipedia.org/wiki/Application_programming_interface
Loong explanations that will take you up and running :)
Thanks digital-ether
I will check
try this (Not sure if that is what you ask)
http://mail.python.org/pipermail/python-list/2003-May/202785.html
If you missed Avisser then you need to pass here:
http://www.python-forum.org/pythonforum/viewtopic.php?f=18&p=67006
Hello All,
I want to make a CD/DVD Library where by an admin can do all the operations while any other norma user can do limited operations (simply browsing and searching). I'm still organizing and doing simple design and I need your opinions on this:
1. What is the best login technique (after storing users and passwords in database?). I can get usernames from database as well as from login forms but I'm not sure how to implement comparison the best way!
2. What is the best way of storing password? (secure way)
3. How do I redirect them to the right page after successful login
4. How do I prevent any unlogged user from accessing the Library script
Any answer to any question is appreciated
I know that AddSeparator() works with AddSimpleTool(). Why are you using AddLabelTool()?
Because I want to show both text and Icon and I cannot do it with AddSimpleTool(). If there is a way of showing both text and icon, I will be happy to change from Label tool.
Just addition Question, is there any similar method with AddLabel Tool?
I have tables already. How do I search for a given keyword?
Thanks
How do i search table for a given keyword? I want to use it with Python.
Cheers!
Hi,
I cannot see a separator, though it adds spaces between tools. What am I doing wrong?
Here is a code below
self.toolbar.AddLabelTool(wx.ID_REDO, "redo", wx.Bitmap("./icons/edit-redo.png"))
self.toolbar.AddSeparator()
Also what is difference between AddLabelTool() and AddSimpleTool() ?
Thanks alot,
waiting to hear others
Big sign of business immaturity!
In Code::Blocks IDE, select menu item Settings --> Compiler and Debugger. Click the Linker Settings tab. Then click the Add button and enter the name of the library.
Thanks Sir
return (("%0.7f" %(float(A*log(t) + B*t + C*((pow(t,2.))/2.) + D*((pow(t,3.))/3.) - (E/(2.*(pow(t,2.)))) + G)/1000)))
I see A, B...et al included but what are they?
You need to define the like A = 2, B = "You"
Oh I will do a try. I'm now at work (Electronics & Telecommunications Engineer interested in IT). I'm exhausted as far as my head is concerned. That's why I will do it later.
Thanks alot!
Hope someone using codeblocks will say something, before I close the thread. I'm happy that very soon I will say bye to boring Looong LoadLibrary/GetProcAddress method :)
You are welcome :)
BTY: for your compiler you should have a library with *.a extension, not *.lib.
Not sure, but I thought Windows have .lib .dll and linux .so .a, am I right?
Thanks for good explanation. I have one more question on this, will the output exe just link to DLL or it will be Huge exe File? I mean using tedious GetProcAddress (Believe me I don't like even to say it) It will Link to DLL and maintain small exe file. Is it so with .lib option?
Do I need to distribute .lib with program?
Thanks
If you don't miss 9hrs that are remaining, Paragon are giving away their partition manager pro. Check before it is too late.
www.giveawayoftheday.com
I have the .lib file, but I'm very ignorant on how to use it!
Can you explain me with little grain of salt how to use it instead of using the tedious GetProcAddress?
Thanks for reply
I use Firefox, Freedownload manager (Have integrated torrent ability)
On security:
Avast Home,
COMODO Firewall
Is it possible to export MySQL database to SQLite?
If possible, how do you do that?
Hi All,
so far I have managed to get Book number and type as shown below. The problem is, when all books are expanded and you jump to
let say Biology book 1 it shows the last parent. I wonder if there is easy way I can do to get a parent of currently selected items, like when I select
book 1 from biology then I get both Book 1 and its parent i.e biology
import wx
class TestTree(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
#Menu & toolbar stuffs
menubar = wx.MenuBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_EXIT, "Exit", "Exit this small app")
self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_EXIT)
menubar.Append(filemenu, "File")
self.SetMenuBar(menubar)
self.CreateToolBar()
self.CreateStatusBar()
self.SetStatusText("This small app")
self.panel = wx.Panel(self, -1)
self.books = wx.TreeCtrl(self.panel, -1, size = (120, 200), style = wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
self.child = self.books.AddRoot("The Library")
self.Populate()
#Hold current parent?
self.bookparent = ""
#Bind to events
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnChanged, self.books)
self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnExpanded, self.books)
self.tc = wx.TextCtrl(self.panel, -1, style = wx.TE_MULTILINE|wx.NO_BORDER)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.books, 0, wx.EXPAND)
hbox.Add(self.tc, 1, wx.EXPAND)
self.panel.SetSizer(hbox)
self.Layout()
def OnExpanded(self, evt):
selected = evt.GetItem()
self.bookparent = self.books.GetItemText(selected)
def OnChanged(self, evt):
selected = evt.GetItem()
text = "\t Selected Book "+self.books.GetItemText(selected)+ " of type "+ self.bookparent+"\n"
self.tc.WriteText(text)
def OnClose(self, evt):
self.Close()
def Populate(self):
BooksList = ["Biology", "Physics", "History", "Computer", "Telecommunications"]
for book in BooksList:
j = self.books.AppendItem(self.child, book)
index = BooksList.index(book)
for k in range(1,5):
self.books.AppendItem(j, str(k))
if (__name__ == "__main__"):
app = wx.App(False)
f = TestTree(None, -1, "Testing tree control")
f.Show()
app.MainLoop()
Hi,
I want to Load .dll library on my program. I was using LoadLibrary and GetProcAddress which is tedious work. I saw somewhere Idea of using .lib files but have no clue. I have used google but I got lost. Please help me :(
Codeblocks 8.02
MINGW 3.4.5
Windows Vista
hi i want to creat activity by Pygtk for OLPC-xo. so how i work pygtk in eclipse? sorry for my english skill. e.x import pygtk. it's not import
re-read my above post ;)
Get your eclipse IDE (Though it is very heavy and Javaic IMHO) and then get python extensions for eclipse here
http://pydev.sourceforge.net/
Happy Pythoning
Just visit a stick on this forum and swim with python :)
I have read a little bit on XML and I will need it to get some information from already available XML files. I would like to learn it by making very small playlist. However I have encountered the two beasts. I don't know much of XML, especially with python. So I ask, which is the best way to go? (May be some tutorials on python/XML)
Thanks :)
I found example here by vega,
I'm lost alittle in the three(may be four) events on the same widget. I need some little light on the events so that I don't just copy and paste without knowing what I'm doing
Thanks for the help.
I'm the kind of person that googles everything first. I'm pretty sure everyone does. That's the point of my response.
Don't worry, hope other have done what I failed to do :)
no hate, more of love :)
Note the quotation marks, so it is just a string so you can substitute anything you like.
SQL_str="CREATE TABLE %s (name_last VARCHAR(20), age INT)" % (name_to_use) cur.execute(SQL_str)
That settled this problem once and for all
Thanks alot
Hello guys,
Please help me with wxTreeCtrl events (I have never dealt with TreeCtrl before). I want to get simple basics how to catch events
As example to clarify my question, I have tree of books and I want just the TextCtrl to display the chosen parent and Item, like "Biology 1" or "Physics 2". Main purpose is to learn TreeCtrl.
I have googled (and still checking google) and the demo+api, but haven't got in good place.
Thanks alot
import wx
class TestTree(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
#Menu & toolbar stuffs
menubar = wx.MenuBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_EXIT, "Exit", "Exit this small app")
self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_EXIT)
menubar.Append(filemenu, "File")
self.SetMenuBar(menubar)
self.CreateToolBar()
self.CreateStatusBar()
self.SetStatusText("This small app")
self.panel = wx.Panel(self, -1)
self.books = wx.TreeCtrl(self.panel, -1, size = (120, 200), style = wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
self.child = self.books.AddRoot("The Library")
self.Populate()
self.tc = wx.TextCtrl(self.panel, -1, style = wx.TE_MULTILINE|wx.NO_BORDER)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.books, 0, wx.EXPAND)
hbox.Add(self.tc, 1, wx.EXPAND)
self.panel.SetSizer(hbox)
self.Layout()
def OnClose(self, evt):
self.Close()
def Populate(self):
BooksList = ["Biology", "Physics", "History", "Computer", "Telecommunications"]
for book in BooksList:
j = self.books.AppendItem(self.child, book)
index = BooksList.index(book)
for k in range(1,5):
self.books.AppendItem(j, str(k))
if (__name__ == "__main__"):
app = wx.App(False)
f = TestTree(None, -1, "Testing tree control")
f.Show()
app.MainLoop()
Are you offended? You missed my point.
Actually one of links i gave have even example that is very similar to your problem. I did it as part to help, and you get me back such discouraging answer, very sad!
Anyway here is the example from:
http://www.codersource.net/cpp_tutorial_inheritance.html
class vehicle //Sample base class for c++ inheritance tutorial
{
protected:
char colorname[20];
int number_of_wheels;
public:
vehicle();
~vehicle();
void start();
void stop();
void run();
};
class Car: public vehicle //Sample derived class for C++ inheritance tutorial
{
protected:
char type_of_fuel;
public:
Car();
};
You would use a variable like "table_name" in the first line here, and pass that to the connect function. If you are creating a new table, then you would also have to input the field names and type, or use a standard layout for all databases.
table_name = "people_db" con = sqlite.connect(table_name ) # Get a Cursor object that operates in the context of Connection con cur = con.cursor() ##--- ONLY CREATE FIRST TIME cur.execute("CREATE TABLE [B]people[/B] (name_last VARCHAR(20), age INT)")
No problem now on using database placeholder. I want now table name to be a variable and not fixed value. As an example, can you change the statement to use place holder instead of fixed tablename people? (Red coloured one)
Sorry,
duplicate posts
why not start with http://wiki.python.org/moin/BeginnersGuide
then move to:
http://docs.python.org/tutorial/
from there you can start flying for more :)
It's just
self.conn = sql.connect(dbname)Here's some code (just a bunch of crap really) from when I was first testing SQLite that shows how to add, change and delete recs. Note that when you retrieve records you have to test for None, i.e. no records found in db. That threw me for a curve when first starting out.
import sqlite3 as sqlite ##---------------------------------------------------------------------- def add_rec(cur, con): ##cur.execute("INSERT INTO people (name_last, age) values ('Yeltsin', 72)") cur.execute("INSERT INTO people (name_last, age) values ('Putin', 50)") cur.execute("INSERT INTO people (name_last, age) values ('Putin', 50)") cur.execute("INSERT INTO people (name_last, age) values ('Putin', 50)") cur.execute("INSERT INTO people (name_last, age) values ('Yeltsin', 70)") ##--- add using a tuple instead person_tuple = ('Barisinov', '30') cur.execute("insert into people (name_last, age) values (?, ?)", person_tuple) con.commit() ##---------------------------------------------------------------------- def change_recs_test(cur, con): cur.execute("UPDATE people SET name_last==:who_dic WHERE age==:age_dic", {"who_dic": "Chg_Yeltsin", "age_dic": 70}) con.commit() ##---------------------------------------------------------------------- def del_recs_test(cur, con): who = "Putin" age=50 cur.execute("DELETE from people where name_last==:who_dic and age==:age_dic", {"who_dic": who, "age_dic": age}) con.commit() print "-" * 30, "AFTER Delete" print_all_recs(cur) print ##---------------------------------------------------------------------- def print_all_recs(cur): # Execute the SELECT statement: print "Printing all recs" cur.execute("select * from people order by age") # Retrieve all rows as a sequence and print that sequence: print cur.fetchall() #========================================================================== if __name__ == "__main__": # Create a connection to the database file table_name = "people_db" con = sqlite.connect(table_name ) # Get a Cursor object that operates in the context of Connection con cur = con.cursor() ##--- ONLY CREATE FIRST TIME cur.execute("CREATE TABLE people (name_last VARCHAR(20), age INT)") …
Thanks woeeee for code.
Please jlm699, can you correct me where I go wrong. Sometimes you do mistakes and you just don't see them until they are pointed out :)
Please someone help me how to populate wxListCtrl (in report mode)
Thanks
import os
os.system("tasklist")
run this script and Get jlm699's flavour
It throws errors
CreateDb
TypeError: a float is required
File "f:\Hosanna\CodeBase\PyCodeBase\sqlite_on_test.py", line 25, in <module>
test.CreateDb("test.cb")
File "f:\Hosanna\CodeBase\PyCodeBase\sqlite_on_test.py", line 8, in CreateDb
self.conn = sql.connect("?", (dbname, ))
When i pass fixed value "test.db" explicitly Then CreateNewTable throws the following error
sqlite3.OperationalError: near "?": syntax error
File "f:\Hosanna\CodeBase\PyCodeBase\sqlite_on_test.py", line 26, in <module>
test.CreateNewTable("testing")
File "f:\Hosanna\CodeBase\PyCodeBase\sqlite_on_test.py", line 12, in CreateNewTable
self.cur.execute("CREATE TABLE IF NOT EXISTS ?(id INTEGER, name TEXT)", (tablename, ))
I cannot get the code work. I want to use placeholder than a fixed value. When use fixed value it works but not placeholder. Please correct me!
import sqlite3 as sql
class Tables(object):
def __init__(self):
print "Class created!"
def CreateDb(self, dbname):
self.conn = sql.connect("?", (dbname, ))
self.cur = self.conn.cursor()
def CreateNewTable(self, tablename):#, tablename
self.cur.execute("CREATE TABLE IF NOT EXISTS ?(id INTEGER, name TEXT)", (tablename, ))
listed = [(1, "Mary"), (2, "Martha"), (3, "Jesca"), (4, "Don")]
for i in listed:
self.cur.execute("INSERT INTO test(id, name) VALUES(?, ?)", i)
print self.cur.execute("SELECT * FROM test").fetchall()
def DropTable(self, tablename):
self.cur.execute("DROP TABLE ?", (tablename, ))
test = Tables()
test.CreateDb("test.cb")
test.CreateNewTable("testing")
import sqlite3 as sql
class Tables(object):
def __init__(self):
print "Class created!"
def CreateDb(self, dbname):
self.conn = sql.connect("?", (dbname, ))
self.cur = self.conn.cursor()
def CreateNewTable(self, tablename):#, tablename
self.cur.execute("CREATE TABLE IF NOT EXISTS ?(id INTEGER, name TEXT)", (tablename, ))
listed = [(1, "Mary"), (2, "Martha"), (3, "Jesca"), (4, "Don")]
for i in listed:
self.cur.execute("INSERT INTO test(id, name) VALUES(?, ?)", i)
print self.cur.execute("SELECT * FROM test").fetchall()
def DropTable(self, tablename):
self.cur.execute("DROP TABLE ?", (tablename, ))
test = Tables()
test.CreateDb("test.cb")
test.CreateNewTable("testing")
The popular Geany IDE is written with GTK (not PyGTK).
Wing IDE is written in PyGTK
I would suggest wxPython, for easy learning curve (to my experience). Why? Because I grasped the basics even before I could be fluent in Python. I almost learned them simultaneously (though Python came first) :)
PyQT? No, unless you will never develop any commercial app or you are willing to $. PyGTK? Yes why not? But if you want to!
There was a man who travelled thousands of miles away. And he started at home. Isn't home 0 miles :)
Learning means asking then trying yourself.