Re: [Tutor] adjust key bindings
Luke, Thanks for the response. I am trying to help someone out on the Pygtk list. I forgot to enclose his reasons for wanting to assign the key press. They are below: It looks like he likes his keys set out in a certain way. I am happy with mine the way they are! I used "z" in isolation just to get the logic right. I know I can assign a function to Z and make the Treeview move down one row and select the row below but I don't want to have to do this for all the different buttons. I am trying to do it without having to assign and call a whole load of different functions. > I just start to use pygtk ... so it is just my first > question :-) > > I would like to create a small file manager based on 'lfm' (curses > based file manager). I used glade for the gui and I am able to display > the existing files and directories using two treeview widgets. > Now, at the beginning I am kind of stuck with the key bindings. In 'lfm' > it was pretty easy to define special key bindings: > > > keytable = { > # movement > ord('p'): 'cursor_up', > ord('k'): 'cursor_up', > ord('K'): 'cursor_up2', > ord('P'): 'cursor_up', > curses.KEY_UP: 'cursor_up', > ord('n'): 'cursor_down', > ord('j'): 'cursor_down', > ord('J'): 'cursor_down2', > ord('N'): 'cursor_down', > curses.KEY_DOWN: 'cursor_down', > curses.KEY_PPAGE: 'page_previous', > curses.KEY_BACKSPACE: 'page_previous', > 0x08: 'page_previous', # BackSpace > 0x10: 'page_previous', # Ctrl-P > curses.KEY_NPAGE: 'page_next', > ord(' '): 'page_next', > 0x0E: 'page_next', # Ctrl-N > curses.KEY_HOME: 'home', > 0x16A: 'home', > ord('H'): 'home', > 0x001: 'home', > curses.KEY_END: 'end', > ord('G'): 'end', > 0x181: 'end', > 0x005: 'end', > ord('h'): 'cursor_left', > ord('l'): 'cursor_right', > curses.KEY_LEFT: 'cursor_left', > curses.KEY_RIGHT: 'cursor_right', > ord('g'): 'goto_dir', > 0x13: 'goto_file', # Ctrl-S > 0x14: 'tree', # Ctrl-T > ord('0'): 'bookmark_0', > ord('1'): 'bookmark_1', > ... > > > with such a keytable I am able to bind different 'def's to every > existing key. As you can see, I like it a lot to use 'vim-like' keys > for moving around; 'j' and 'k' to move a row up and down. In glade I > found those 'accelerators', but it is just for certain functions. > Does anyone have an idea about using such a keybinding in > pygtk? Would be nice! > I have attempted to answer his question but I am not sure I am on the right track. Is there a better way to do it? Regards, John. -Original Message- From: Luke Paireepinart [mailto:[EMAIL PROTECTED] Sent: 27 November 2006 01:30 To: [EMAIL PROTECTED] Cc: tutor@python.org Subject: Re: [Tutor] adjust key bindings John CORRY wrote: > Hi All, > > I have been trying to bind the "z" key to the "Down" key using Python > 2.4, Glade 2 and Pygtk. I have posted this problem on the Pygtk list > but have had no response. I was hoping somebody on the tutor list could > help. I think that I am close. I can capture the "z" key press and > assign a "Down" key press but I can't get the "Down" key press to > register on the Treeview in the GUI. > > Any thoughts greatly appreciated. > > Thanks, > > John. I highly doubt that what you want to do when someone hits a 'z' is to generate a 'down' keypress. What if the user assigned the down key to z? then you'd have a z -> down -> z -> down -> infinite loop. What I expect you want is that each key, z and down, perform the same action. In other words, they both call the same function. So basically what you'd want is something like this (non-pyGTK specific code) def aFunc(): print "Hello, World!" bindKey = {'down':aFunc} keypress = raw_input("What keypress do you want to perform?") bindKey[keypress]()#this will call the 'aFunc' function if they type 'down', otherwise, it'll probably crash. bindKey['z'] = aFunc bindKey['z']()# now performs the same function as bindkey['down']()#this does. If you really do want to generate 'down' keypresses when someone hits 'z', please explain why, and I will try to the best of my abilities to help you in that regard! Good Luck! -Luke > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] adjust key bindings
Hi All, I have been trying to bind the "z" key to the "Down" key using Python 2.4, Glade 2 and Pygtk. I have posted this problem on the Pygtk list but have had no response. I was hoping somebody on the tutor list could help. I think that I am close. I can capture the "z" key press and assign a "Down" key press but I can't get the "Down" key press to register on the Treeview in the GUI. Any thoughts greatly appreciated. Thanks, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John CORRY Sent: 25 November 2006 17:23 To: 'Fabian Braennstroem'; pygtk@daa.com.au Subject: RE: [pygtk] Re: adjust key bindings Fabian, I have had a go at binding the "z" key to the down cursor key. I can block the Z key press and assign the "down" cursor key press and print out the "down" key press but I can't redirect the signal back to the widget. I have enclosed the code below, maybe someone else on the list can finish off the code. The code below assumes that you have a window in Glade with one treeview widget. Both widgets have the "key_press_event" assigned in glade. import shutil import pygtk import findgtk import gtk import gtk.glade import gobject import os import sys class Shopcard: def __init__(self): self.wTree = gtk.glade.XML ("project12.glade", "window1") dic={"on_window1_delete_event" : self.quit100, } self.wTree.signal_autoconnect (dic) tree1 = self.wTree.get_widget("treeview1") windy = self.wTree.get_widget("window1") tree1.connect("key_press_event",self.callback3000,tree1,windy) model = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.hostmodel = model host_inter=self.insert_row(model,None,"test",'Test') host_inter=self.insert_row(model,None,"test1",'Test') host_inter=self.insert_row(model,None,"test2",'Test') host_inter=self.insert_row(model,None,"test3",'Test') host_inter=self.insert_row(model,None,"test4",'Test') tree1.set_model(model) renderer=gtk.CellRendererText() column=gtk.TreeViewColumn("Col1",renderer,text=0) column.set_resizable(True) tree1.append_column(column) renderer=gtk.CellRendererText() column=gtk.TreeViewColumn("Col2",renderer,text=1) column.set_resizable(True) tree1.append_column(column) def insert_row(self,model,parent,firstcolumn,secondcolumn, thirdcolumn=None): myiter=model.insert_after(parent,None) model.set_value(myiter,0,firstcolumn) model.set_value(myiter,1,secondcolumn) if thirdcolumn !=None: model.set_value(myiter,2,thirdcolumn) return myiter def callback3000(self,widget,event,tree1,windy): import re """prevents the possibility of inputting wrong chars""" ## fixme: missing comma, and cut&paste key = gtk.gdk.keyval_name (event.keyval) ONLYDIGITS="([0-9.,z]|BackSpace|Left|Right|F1|period|Tab|Up|Down)" if not re.match (ONLYDIGITS, key): print "True" return True else: if key == "z": tree1.emit_stop_by_name("key_press_event") # This blocks the signal from the key press event = gtk.gdk.Event(gtk.gdk.KEY_PRESS) event.keyval = 65364 # This is the code for the down key event.state = gtk.gdk.CONTROL_MASK event.time = 0 # assign current time print gtk.gdk.keyval_name(event.keyval) tree1.emit('key_press_event', event) tree1.connect("key_press_event",self.callback3001) else: print event.keyval print "else" return False def callback3001(self,widget,event): import re """prevents the possibility of inputting wrong chars""" ## fixme: missing comma, and cut&paste key = gtk.gdk.keyval_name (event.keyval) print key print "made it" ONLYDIGITS="([0-9.,z]|BackSpace|Left|Right|F1|period|Tab|Up|Down)" if not re.match (ONLYDIGITS, key): print "True2" return True def quit(self,obj): gtk.main_quit() sys.exit(1) def quit100(self,obj,wind): gtk.main_quit() sys.exit(1) if __name__ == '__main__': Shopcard() try: gtk.threads_init() except:
[Tutor] Dates
Bob and Alan, Thanks for the help. I have gone with the following code and it works! a = "date(%i,%i,%i)" % (2006,01,31) b = "date(%i,%i,%i)" % (2006,12,31) sql = 'SELECT * FROM times where rt_weekst >= %s and rt_weekst <= %s and rt_type = "%s" ' % (a,b,"R",) db = mx.ODBC.Windows.DriverConnect('DSN=tnt') c = db.cursor() c.execute(sql) As you rightly pointed out, I needed to get my sql string formatted and working before putting it anywhere near the c.execute command. Many thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dates
Alan, Thanks for the help. I have converted the dates to strings but I get the same error. Please see the updated code below, is this what you meant by converting the dates to strings? import mx.ODBC import mx.ODBC.Windows import mx.DateTime import datetime a = datetime.date(2006,01,31) b = datetime.date(2006,12,31) c = str(a) d = str(b) print a,b,c,d db = mx.ODBC.Windows.DriverConnect('DSN=tnt') c = db.cursor() c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <= ? and rt_type == ?', (c,d,"R",)) for row in c.fetchall(): print row row = str(row) c.close() The output is below: 2006-01-31 2006-12-31 2006-01-31 2006-12-31 Traceback (most recent call last): File "C:\test\timemanager.py", line 18, in ? c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <= ? and rt_type == ?', (c,d,"R",)) DataError: ('22005', 301, '[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch.', 4579) Is there another way I can approach this problem? Say if I use something like: c.execute('SELECT * FROM times where rt_weekst >= date(?) and rt_weekst <= date(?) and rt_type == ?', (c,d,"R",)) I get the following error: 2006-01-31 2006-12-31 2006-01-31 2006-12-31 Traceback (most recent call last): File "C:\test\timemanager.py", line 18, in ? c.execute('SELECT * FROM times where rt_weekst >= date(?) and rt_weekst <= date(?) and rt_type == ?', (c,d,"R",)) ProgrammingError: ('37000', 229, '[Microsoft][ODBC Visual FoxPro Driver]Too few arguments.', 4579) Thanks for any suggestions. John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dates
Hi All, I am using the code below to select items from a visual foxpro database where the dates are between the 31/01/2006 and 31/12/2006. The good news is that the code below works. However, I want to make the from and to dates variable. I want to change the range depending on user input. I can't get this to work. I have tried the code below marked "Tried" but I get the error: Traceback (most recent call last): File "C:\test\timemanager.py", line 16, in ? c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <= ? and rt_type == ?', (a,b,"R",)) DataError: ('22005', 301, '[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch.', 4579) Code that works is below: import mx.ODBC import mx.ODBC.Windows import mx.DateTime db = mx.ODBC.Windows.DriverConnect('DSN=tnt') c = db.cursor() c.execute('SELECT * FROM times where rt_weekst >= date(2006,01,31) and rt_weekst <= date(2006,12,31) and rt_type == ?', ("R",)) for row in c.fetchall(): print row row = str(row) c.close() Tried but get errors: import mx.ODBC import mx.ODBC.Windows import mx.DateTime import datetime a = datetime.date(2006,01,31) b = datetime.date(2006,12,31) db = mx.ODBC.Windows.DriverConnect('DSN=tnt') c = db.cursor() c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <= ? and rt_type == ?', (a,b,"R",)) for row in c.fetchall(): print row row = str(row) c.close() Is there a way to format the date so that the Select statement works? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [pygtk] key_press_event
Sandro, That's exactly what I need. Thanks, John. > def callback3(self,data,widget): > > input = data.get_text() > print input > data.set_text("test") If you don't return True, default callback will be called that insert the 'a'. I have something like this: def digits_check_input_cb(self, widget, event): """prevents the possibility of inputting wrong chars""" ## fixme: missing comma, and cut&paste key = gtk.gdk.keyval_name (event.keyval) ONLYDIGITS="([0-9.,]|BackSpace|Left|Right|F1|period|Tab|Up|Down)" if not re.match (ONLYDIGITS, key): return True Not sure whether this is the best way thought... sandro *;-) -- Sandro Dentella *:-) http://www.tksql.orgTkSQL Home page - My GPL work ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] key_press_event
Hi, I'm using Python 2.4, pygtk and Glade2. I have a few text entries. I am trying to put validation on the text entry boxes. I am trying to catch the key_press_event, check the key that has been pressed and either allow it or put back the old text. The code is below with the output after it. class Test: def __init__(self): self.wTree = gtk.glade.XML ("test.glade", "window1") dic={"on_window1_delete_event" : self.quit10, } self.wTree.signal_autoconnect(dic) cancel = self.wTree.get_widget("button2") cancel.connect("clicked", self.quit, ) text1 = self.wTree.get_widget("entry1") text2 = self.wTree.get_widget("entry2") text2.connect("key_press_event",self.callback3) login = self.wTree.get_widget("button1") login.connect("clicked", self.callback2, text1,text2) def callback3(self,data,widget): input = data.get_text() print input data.set_text("test") def callback2(self,data,text1,text2): print 'hello' def quit10(self,obj,data): gtk.main_quit() sys.exit(1) def quit(self,obj): gtk.main_quit() sys.exit(1) if __name__ == '__main__': Test() try: gtk.threads_init() except: print "No threading was enabled when you compiled pyGTK!" import sys sys.exit(1) gtk.threads_enter() gtk.main() gtk.threads_leave() The box starts of with 123 in it. If I hit the 'a' key on the key board I get the following result. 123 is printed and 'atest' appears in the text entry box. Is there a way to catch the key_press (in this case the 'a') and check to see if it is a number. If it is not a number, ignore it. If it is a number accept it. Why does the 'a' appear in 'atest'. It is like the code works first, sets the text to 'test' and then the key press works and inserts the 'a'. Do I need to disconnect the key press signal? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] loops to assign variables
Hi, I am refactoring my code. I am trying to reduce the amount of lines by using more loops. I tend to use copy and paste a lot instead of writing a loop to do the work. For example, I have 30 textentry boxes numbered from entry20 to entry50. I have used the following code to assign the entryboxes to a local name. text20 = self.wTree.get_widget("entry20") text21 = self.wTree.get_widget("entry21") I have had a go at writing a loop for the above 30 textentry boxes. It is below, but it does not work. for x in range(20,51): ent = "entry%s" % (str(x)) text_x = self.wTree.get_widget(ent) Is it possible to do what I want it to do? Am I on the right lines? Any help or advice would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Good teamwork!
George/Kent, Thanks guys for the pointers. Kent – The gtk-entry-set-alignment() works a treat. George – I like the look of the sample code you posted. At the moment it doesn’t give me exactly what I need but I am still playing with it. There may be another question on this later! I have downloaded the ValidatedEntry extension and had a quick look at it. It looks like it will sort out my validation problems. A good team effort! Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help me make it look pretty!
Good evening all. I am writing a program using python 2.4, glade 2 and pygtk. It takes input from the user using textentry boxes. The input should be a number. When the user keys the data in, it automatically left justifies. The function below, takes the input for four boxes and right justifies it by using an ugly, string format. The boxes are 45 characters big, so I use the len function to fit them into the box. The code is below. I am looking for a way to set the text entry up, so that there is a decimal point in the box regardless of what the user does and I am also looking for a way to keep the numbers right justified. Any suggestions or comments as always are greatly appreciated. Regards, John. def callback36(self,data,text37,text38,text39,text40,text41,text42,label): a = text37.get_text() b = text38.get_text() c = text39.get_text() d = text40.get_text() a= float(a) b= float(b) c= float(c) d= float(d) try: e = float(a + b + c + d) g = e/a e = "%0.2f" % e g = "%0.2f" % g g = str(g) label.hide() e = " %s" % e a = " %s" % a b = " %s" % b c = " %s" % c d = " %s" % d g = "%s%%" % g text42.set_text(str(g)) if len(e)>45: x = len(e) - 45 x = x + 4 y = e[x:] text41.set_text(str(y)) return else: text41.set_text(str(e)) return except: label.show() return ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
Amresh, I had this problem a few months back. I approached it backwards. Maybe not the right way to do it. I removed all the files and directories and then had my exception handle the file if it was read only. The exception handler changes the file from read-only to not read only and then calls the function again. Is there a better way to do it? Would appreciate feedback on the code below. import shutil import os def zaps(self): try: shutil.rmtree('f:/m2m') except OSError, inst: print OSError os.chmod(inst.filename, 0666) self.zaps() Regards, John. -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Amresh KulkarniSent: 16 June 2006 16:27To: tutor@python.orgSubject: [Tutor] Delete directories recursivelyHi,I need to delete a directory and its sub directories. However all dir's, sub dir;s and files have read only access. How do i do this efficeintly using the os.walk command. I cannot run this command on the dir as it gives me an error due to the read only attribute. Is there any other way to do this? -- ~~AMRESH~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Treeview
Hi, I have managed to find the solution to my problem. I have defined iter as Iter = model.get_iter(combo3) The code now works. I will show it below for completeness: combo3 = self.wTree.get_widget("treeview1") model=gtk.TreeStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING) self.hostsmodel = model combo3.set_model(model) combo3.connect("row_activated", self.callback53, combo3,model) def callback53(self,data,combo3,data2,data3,model): lookup = [] iter = model.get_iter(combo3) counter = 0 while counter < 8: result = model.get_value(iter,counter) lookup.append(result) counter = counter + 1 print lookup Technically this is the first solution that I have been able to post on the mailing list. Does this mean I am improving? Or does it not count as I have solved my own problem? Regards, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problems with Treeview
Hi, I am having problems selecting a row in treeview. I am using Pythoncard, Glade 2 and Python 2.4. I am using the following code:- combo3 = self.wTree.get_widget("treeview1") model=gtk.TreeStore(gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING,gobject.TYPE_STRING) self.hostsmodel = model combo3.set_model(model) combo3.connect("row_activated", self.callback53, combo3,model) def callback53(self,data,combo3,data2,data3,model): view = gtk.TreeView(model) selection = view.get_selection().get_selected() print selection result = model.get_value(iter,0) print result I get the following error: (, None) Traceback (most recent call last): File "C:\Documents and Settings\Johnc\Projects\project7\shopcall.py", line 1 , in callback53 result = model.get_value(iter,0) TypeError: iter must be a GtkTreeIter What do I need to assign to iter to make this code work? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Button Signals
Liam, Thanks for the prompt reply. That is working for me. Regards, John, -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: 07 May 2006 13:06 To: [EMAIL PROTECTED] Cc: tutor@python.org Subject: Re: [Tutor] Button Signals Hi John, I'll answer your questions, but first: Pythoncard is for wxPython. wxPython is vastly different to PyGTK afaik. The docs you quote answer your question: The return value from a connect () call is an integer tag that identifies your callback. As stated above, you may have as many callbacks per signal and per object as you need, and each will be executed in turn, in the order they were attached. This tag allows you to remove this callback from the list by using: object.disconnect(id) So, by passing in the tag returned by one of the signal connect methods, you can disconnect a signal handler. Your code needs the following: self. callback_id1 = process.connect("clicked", self.callback1, start_date, process) def callback1(self,data,start_date,process ): process.disconnect(self.callback_id1) On 5/7/06, John CORRY < [EMAIL PROTECTED]> wrote: Hi, I am having difficulty with using signal handlers. I am using Glade 2 and Pygtk. My editor is Pythoncard. The following code connects to button one and calls a function which hides button one. self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) process = self.wTree.get_widget("button1") process.connect("clicked", self.callback1, start_date, process) def callback1(self,data,start_date,process ): process.hide() The above code works fine. However I want button one to remain on my GUI. Thus, I want to just stop the signal being emitted after it is pressed once. I have used the following code which is trying to disconnect the button one: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) process = self.wTree.get_widget("button1") process.connect("clicked", self.callback1, start_date, process) def callback1(self,data,start_date,process ): process.disconnect() When I run this code I get the error TyoeError: Object takes exactly one argument(0 given) When I put an argument in, it says that the argument must be an integer. I have tried a number of integers at random but none work. On the Pygtk tutorial it states the following: 3.1. More on Signal Handlers Lets take another look at the connect() call. object.connect(name, func, func_data) The return value from a connect() call is an integer tag that identifies your callback. As stated above, you may have as many callbacks per signal and per object as you need, and each will be executed in turn, in the order they were attached. This tag allows you to remove this callback from the list by using: object.disconnect(id) So, by passing in the tag returned by one of the signal connect methods, you can disconnect a signal handler. How do I find out what the integer tag is, so that I can put this in my code? I have tried the pygtk faq page but it is currently unavailable. Any help greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Button Signals
Hi, I am having difficulty with using signal handlers. I am using Glade 2 and Pygtk. My editor is Pythoncard. The following code connects to button one and calls a function which hides button one. self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) process = self.wTree.get_widget("button1") process.connect("clicked", self.callback1, start_date, process) def callback1(self,data,start_date,process): process.hide() The above code works fine. However I want button one to remain on my GUI. Thus, I want to just stop the signal being emitted after it is pressed once. I have used the following code which is trying to disconnect the button one: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) process = self.wTree.get_widget("button1") process.connect("clicked", self.callback1, start_date, process) def callback1(self,data,start_date,process): process.disconnect() When I run this code I get the error TyoeError: Object takes exactly one argument(0 given) When I put an argument in, it says that the argument must be an integer. I have tried a number of integers at random but none work. On the Pygtk tutorial it states the following: 3.1. More on Signal Handlers Lets take another look at the connect() call. object.connect(name, func, func_data) The return value from a connect() call is an integer tag that identifies your callback. As stated above, you may have as many callbacks per signal and per object as you need, and each will be executed in turn, in the order they were attached. This tag allows you to remove this callback from the list by using: object.disconnect(id) So, by passing in the tag returned by one of the signal connect methods, you can disconnect a signal handler. How do I find out what the integer tag is, so that I can put this in my code? I have tried the pygtk faq page but it is currently unavailable. Any help greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Stumbled onto the answer!
Hi, I have managed to “fix” my two combo box problem. I have used the following code:- self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) combo2 = self.wTree.get_widget("comboboxentry1") combo2.connect("changed", self.callback3, "comboboxentry1") store = gtk.ListStore(gobject.TYPE_STRING) store.append (["Mon"]) store.append (["Tue"]) store.append (["Wed"]) store.append (["Thu"]) store.append (["Fri"]) store.append (["Sat"]) store.append (["Sun"]) combo2.set_model(store) combo2.set_text_column(0) combo2.set_active(0) It works but I am not sure why. Regards, A Very Happy John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] 2 Combo Boxes! What was I thinking?
Hi, I have set up a GUI which has amongst other widgets two combo boxes. I am using: PythonCard version: 0.8.1 wxPython version: 2.6.1.0 Python version: 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] Platform: win32 Glade 2 I started by setting up comboboxentry2 to accept two settings in its drop down list. (open + closed). This worked fine. Code below: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) My problems started when I went to set up comboboxentry3. I used the following code: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo3 = self.wTree.get_widget("comboboxentry3") combo3.connect("changed", self.callback3, "comboboxentry3") combo3.append_text ("Mon") combo3.append_text ("Tue") combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) I got the following error: Gtkwarning: gtk_combo_box_append_text: assertion GTK_IS_LIST_STORE(Combobox->Priv->Model) Failed Combo3.append_text(“Mon”) Gtkwarning: gtk_combo_box_append_text: assertion GTK_IS_LIST_STORE(Combobox->Priv->Model) Failed Combo3.append_text(“Tue”) I then tried the code: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo3 = self.wTree.get_widget("comboboxentry3") combo3.connect("changed", self.callback3, "comboboxentry3") combo3.child.append_text ("Mon") combo3.child.append_text ("Tue") combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) I get the following error message: DeprecationWarning: use GtkEditable.insert_text Combo3.child.append_text(“Mon”) DeprecationWarning: use GtkEditable.insert_text Combo3.child.append_text(“Tue”) The combobox3 is populated on the GUI but instead of being a drop down list it appears as a string on one line and looks like this: MonTue I have to confess I am not really sure what I am doing. I just guessed at putting the child command in. It gets me close but not close enough. Can anyone tell me what I am doing wrong or explain what happens when you put two combo boxes on the one GUI? Any help greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] 2 Combo Boxes! What was I thinking?
Hi, I have set up a GUI which has amongst other widgets two combo boxes. I am using: PythonCard version: 0.8.1 wxPython version: 2.6.1.0 Python version: 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] Platform: win32 Glade 2 I started by setting up comboboxentry2 to accept two settings in its drop down list. (open + closed). This worked fined. Code below: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) My problems started when I went to set up comboboxentry3. I used the following code: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo3 = self.wTree.get_widget("comboboxentry3") combo3.connect("changed", self.callback3, "comboboxentry3") combo3.append_text ("Mon") combo3.append_text ("Tue") combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) I got the following error: Gtkwarning: gtk_combo_box_append_text: assertion GTK_IS_LIST_STORE(Combobox->Priv->Model) Failed Combo3.append_text(“Mon”) Gtkwarning: gtk_combo_box_append_text: assertion GTK_IS_LIST_STORE(Combobox->Priv->Model) Failed Combo3.append_text(“Tue”) I then tried the code: self.wTree = gtk.glade.XML ("phonelog.glade", "window1") dic={"on_window1_destroy" : self.quit, } self.wTree.signal_autoconnect (dic) combo3 = self.wTree.get_widget("comboboxentry3") combo3.connect("changed", self.callback3, "comboboxentry3") combo3.child.append_text ("Mon") combo3.child.append_text ("Tue") combo1 = self.wTree.get_widget("comboboxentry2") combo1.append_text("Open") combo1.append_text("Closed") combo1.set_active(0) combo1.connect("changed", self.callback2, combo1) I get the following error message: DeprecationWarning: use GtkEditable.insert_text Combo3.child.append_text(“Mon”) DeprecationWarning: use GtkEditable.insert_text Combo3.child.append_text(“Tue”) The combobox3 is populated on the GUI but instead of being a drop down list it appears as a string on one line and looks like this: MonTue I have to confess I am not really sure what I am doing. I just guessed at putting the child command in. It gets me close but not close enough. Can anyone tell me what I am doing wrong or explain what happens when you put two combo boxes on the one GUI? Any help greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] My Name is John and I copy and paste
Hi, Thanks for all the help so far on my database questions. I have now developed a program that reads in info from a csv file and updates already existing records in my database. I have enclosed the code below. The good news is that it is working. However, I used copy and paste and amended the text to write the code and it seems rather longwinded. Is there a quicker/better way to write the code below? path = "c:/test/import.csv" import mx.ODBC import mx.ODBC.Windows import csv reader = csv.reader(open(path,"rb")) for row in reader: db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute('UPDATE cost_grid SET cost_1 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[3]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_1 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[4]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_1 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[5]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_2 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[6]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_2 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[7]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_2 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[8]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_3 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[9]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_3 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[10]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_3 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[11]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_4 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[12]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_4 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[13]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_4 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[14]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_5 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[15]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_5 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[16]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_5 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[17]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_6 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[18]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_6 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[19]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_6 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[20]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_7 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[21]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_7 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[22]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_7 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[23]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_8 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[24]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_8 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[25]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_8 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[26]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_9 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[27]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_9 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[28]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_9 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[29]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_10 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[30]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_10 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[31]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_10 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[32]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET cost_11 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[33]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET rrp_11 = ? where cost_grid_id = ? and finish_dro = ?', ( float(row[34]), row[0], float(row[2]))) c.execute('UPDATE cost_grid SET ie_rrp_11 = ? where cost_grid_
[Tutor] School Boy Error - Update
Hi, I have taken on board the advice in relation to the cvs module and setting the list to a tuple. I am now using the following code and getting a different error. I think it is a small step forward? import string, re path = "c:/test/import.csv" listy = [] import csv reader = csv.reader(open(path,"rb")) for row in reader: listy.append(tuple(row)) sql_list = listy[0] stat = """Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)""" t = 5000 d = "PF2" b = 91.4 a = 95.00 print stat print sql_list import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute(stat, sql_list) db.commit() c.close() I now get the following ouput + error: Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) ('961', 'TM BLIND', 'RO', 'PF1', 'Plain Finish Range One', '91.4', '', '45.7', '10', '20', '0', '24', '61', '8.69', '20', '0', '27', '81.3', '11.03', '25', '0', '34', '101.6', '12.36', '28', '0', '38', '121.9', '14.36', '32', '0', '44', '142.2', '16.7', '37', '0', '51', '162.6', '18.71', '41', '0', '58', '182.9', '20.72', '45', '0', '64', '198.1', '22.71', '49', '0', '70', '223.5', '27.39', '60', '0', '84', '243.8', '30.07', '66', '0', '92', '274.3', '34.41', '76', '0', '105', '304.8', '37.42', '82', '0', '115', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0') Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 35, in ? c.execute(stat, sql_list) ProgrammingError: ('37000', 200, '[Microsoft][ODBC Visual FoxPro Driver]Syntax error.', 4347) I assume this error is telling me that the database does not like the syntax of the data I am importing. The data that I am importing is actually data that I exported, so I know that it is in the right order and the right amount. The only thing that I can think of is that, the database requires floats for the numbers instead of strings. I assume that the numbers in listy[0] are now strings. Am I now going to have to throw listy[0] through a function to make the numbers into floats or is there another way to do this? Am I on the right track? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] School Boy Error
Bri, Print stat gives Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 31, in ? c.execute(stat, sql_list) TypeError: parameters must be a list of tuples Unfortunately sql_list gives the same error. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] School Boy error
Hi, I couldn’t sleep last night with all the code running though my head. Counting sheep didn’t work as I kept wanting to turn them into a loop! listy[-1] Outputs the following:- ['432', 'TM BLIND', 'RO', 'PF1', 'Plain Finish Range One', '304.8', '', '45.7', '80', '90', '0', '39', '61', '15.03', '33', '0', '46', '81.3', '19.38', '42', '0', '60', '101.6', '22.39', '49', '0', '69', '121.9', '26.39', '58', '0', '81', '142.2', '30.4', '67', '0', '93', '162.6', '34.41', '75', '0', '105', '182.9', '38.08', '83', '0', '117', '198.1', '41.42', '90', '0', '127', '223.5', '48.77', '106', '0', '149', '243.8', '53.12', '117', '0', '163', '274.3', '60.8', '133', '0', '186', '304.8', '66.14', '145', '0', '202', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0\n'] The full error is Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 30, in ? c.execute(stat, listy[-1]) TypeError: parameters must be a list of tuples Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] School Boy Error
Thanks Brian for the help on the last one. I couldn’t see the wood for the trees. I have a tougher one for you. I am reading in a CSV file. Each line represents a line that I want to upload into my database. I am trying to upload the first line in the file to get myself started. The code is below:- import string, re path = "c:/test/import.csv" listy = [] input = file(path, "r") for line in input.readlines(): line = line.split(",") listy.append(line) print listy[-1] stat = """Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)""" t = 5000 d = "PF2" b = 91.4 a = 95.00 import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute(stat, listy[-1]) db.commit() c.close() I get the following error: TypeError: parameters must be a list of tuples Any suggestions would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Didn't take long to hit my next wall!
Hi, I am having problems amending records in my database. If I use the following code my database is updated fine. c = '"PF1"' b = 91.4 a = 85.00 import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute('UPDATE cost_grid SET cost_1 = ? where cost_grid_id = "PF1" and finish_dro = ?', ( a, b,)) db.commit() c.close() However if I use the following code:- Where the only difference is I use the c variable instead of the actual “PF1”. The database does not get updated. I have also tried C = ”PF1” but this does not work either. c = '"PF1"' b = 91.4 a = 85.00 import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute('UPDATE cost_grid SET cost_1 = ? where cost_grid_id = ? and finish_dro = ?', ( a, c,b,)) db.commit() c.close() Any suggestions would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Good Hustle Hit the Showers!
Hi, Good advice. I configured the ODBC data sources as advised and I am now able to query my database files. Thanks, John. -Original Message- From: Lloyd Kvam [mailto:[EMAIL PROTECTED] Sent: 15 April 2006 16:04 To: [EMAIL PROTECTED] Cc: Kent Johnson; Tutor Python Subject: Re: [Tutor] odbc On Sat, 2006-04-15 at 16:03 +0100, John Corry wrote: > Kent, > > I am not sure what you mean. I am feeling about in the dark on this > subject. > > Do you have an example? You should have a Control Panel Application for configuring ODBC data sources. The program using an ODBC driver is separated from the actual file. Instead the DSN name is matched against a registry entry to find the actual file or database. So you won't get anywhere until you get the ODBC registry stuff straight. That's also why the unit tests fail. (This is from a Linux guy, so the exact details could be off a little bit, but hopefully it points you in the right direction.) > Among my visual foxpro database files I have a file > called tng.dbc. When I acces the database files through excel, I select the > tng.dbc before I can see the fields in the databases. Is this what I need > to log onto with python first before I access the database file? > > Regards, > > John. > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Kent Johnson > Sent: 15 April 2006 15:40 > Cc: tutor@python.org > Subject: Re: [Tutor] odbc > > > John CORRY wrote: > > I have just run the test package within mxODBC. I get the following > result. > > OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data > > source name not found and no default driver specified', 6044) > > > > It gives me the same error that I am experiencing when I run my code. > > Does this mean that I have not installed something that I need or have > > not installed something properly. > > Have you configured an ODBC data source for the database you are trying > to access? I don't remember how to do this but I know it was a necessary > step for accessing MS-Access databases from ODBC. > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-653-8139 fax:320-210-3409 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] odbc
Kent, I am not sure what you mean. I am feeling about in the dark on this subject. Do you have an example? Among my visual foxpro database files I have a file called tng.dbc. When I acces the database files through excel, I select the tng.dbc before I can see the fields in the databases. Is this what I need to log onto with python first before I access the database file? Regards, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Kent Johnson Sent: 15 April 2006 15:40 Cc: tutor@python.org Subject: Re: [Tutor] odbc John CORRY wrote: > I have just run the test package within mxODBC. I get the following result. > OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data > source name not found and no default driver specified', 6044) > > It gives me the same error that I am experiencing when I run my code. > Does this mean that I have not installed something that I need or have > not installed something properly. Have you configured an ODBC data source for the database you are trying to access? I don't remember how to do this but I know it was a necessary step for accessing MS-Access databases from ODBC. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] odbc
Hi, I have just run the test package within mxODBC. I get the following result. mx.ODBC Test Suite Subpackage Name [Windows]: Available Datasources: Excel Files - Microsoft Excel Driver (*.xls) MS Access Database - Microsoft Access Driver (*.mdb) Visual FoxPro Database - Microsoft Visual FoxPro Driver Visual FoxPro Tables - Microsoft Visual FoxPro Driver dBASE Files - Microsoft dBase Driver (*.dbf) DriverConnect arguments [DSN=test;UID=test;PWD=test]: Clear AUTOCOMMIT ? (1/0) [1] Run tests continuously to check for leaks ? (y/n) [n] Use direct execution of SQL statements ? (y/n) [n] Run long benchmark ? (y/n) [n] Show driver type information ? (y/n) [n] Output file [stdout]: Testing package mx.ODBC.Windows version: 2.0.5 compiled with Unicode support using Python version: 2.4 Test suite: Connecting to the database. Traceback (most recent call last): File "C:\Python24\Lib\site-packages\mx\ODBC\Misc\test.py", line 2346, in ? rc = main(packagename) File "C:\Python24\Lib\site-packages\mx\ODBC\Misc\test.py", line 2278, in main connection = apply(connectapi,connectargs) OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 6044) It gives me the same error that I am experiencing when I run my code. Does this mean that I have not installed something that I need or have not installed something properly. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difficulty connecting with odbc drivers
Liam, Thanks for the quick response. I have changed the code so that dsn is now DSN. However I get the same error. Any other thoughts? Regards, John. -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: 15 April 2006 15:02 To: [EMAIL PROTECTED] Cc: tutor@python.org Subject: Re: [Tutor] Difficulty connecting with odbc drivers According to the eGenix docs: Please refer to the ODBC manuals of your ODBC manager and database for the exact syntax of the DSN_string. It typically has these entries: 'DSN=datasource_name;UID=userid;PWD=password;' (case is important !). So, you've got DSN lowercase... On 4/16/06, John CORRY <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I have downloaded the mxodbc product. I am using windows xp, python 2.4 and > I am trying to log onto a visual foxpro database file. I have downloaded > the visual foxpro driver. I use the following code: > > > > import mx.ODBC > > import mx.ODBC.Windows > > db = > mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > > c = db.cursor() > > > > and I get the following error: > > > > Traceback (most recent call last): > > File "C:\Python24\Lib\site-packages\databasemanager.py", > line 4, in ? > > db = > mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > > OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source > name not found and no default driver specified', 6044) > > > > What am I doing wrong and what do I need to do? Any help would be greatly > appreciated. > > > > Thanks, > > > > John. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Difficulty connecting with odbc drivers
Hi, I have downloaded the mxodbc product. I am using windows xp, python 2.4 and I am trying to log onto a visual foxpro database file. I have downloaded the visual foxpro driver. I use the following code: import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') c = db.cursor() and I get the following error: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 6044) What am I doing wrong and what do I need to do? Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Difficulty connecting with odbc drivers
Hi, I have downloaded the mxodbc product. I am using windows xp, python 2.4 and I am trying to log onto a visual foxpro database file. I have downloaded the visual foxpro driver. I use the following code: import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') c = db.cursor() and I get the following error: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 6044) What am I doing wrong and what do I need to do? Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Databases
Hi, I have some database files that are written in visual foxpro. I want to be able to access them, read them and amend them. Can I do this with python? Are there any good links or websites that would specifically deal with interrogating visual foxpro databases with Python? I have limited knowledge with databses. I have created and modified some gadfly databases but on a very simple level. Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Space the final frontier
Dear All, Thanks for the prompt replies. I have now processed my file with 999 lines and it took seconds. It was beautiful. Your advice was spot on. I have enclosed the code that I ended up with. Instead of appending it to a list, I just wrote it to another file in the corrected format. filename = "a:/calllist.csv" filename2 = "c:/calllist.csv" import string import os import re listy = [] input = open( filename, 'r')#read access input2 = open(filename2, 'w') for line in input.readlines(): line = re.sub('[\s]+', '', line) y = line x = "\n" z = y + x input2.write(z) del input del input2 Thanks again, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Space the final frontier!
Dear All, I am having difficulty removing white spaces from my file. The file is 999 lines long and looks like the sample below: 001, new field,dial= 028 90 79 0154, dial= 002, borfiled, dial= 02890 618521, dial= 003, newcomp, dial=02890419689, dial= The program, I am using to import the file does not like the spaces around the numbers. The number should look like the "dial=02890419689" in the third line. Thus the sample above should look like: 001,newfield,dial=02890790154,dial= 002,borfiled,dial=02890618521,dial= 003,newcomp,dial=02890419689,dial= I have searched the tutor mailbag already and have picked up some good tips on join, split and re but I can't seem to get it to work. I am using the following code. filename = "c:/test.txt" import string import os import re listy = [] input = open( filename, 'r')#read access for line in input.readlines(): y = line listy.append(y) print listy x = listy.pop() re.sub(r'\s', '', x) print y,x del input It produces the output: ['001, new field,dial= 028 90 79 0154, dial=\n'] 001, new field,dial= 028 90 79 0154, dial= 001, new field,dial= 028 90 79 0154, dial= ['002, borfiled, dial= 02890 618521, dial=\n'] 002, borfiled, dial= 02890 618521, dial= 002, borfiled, dial= 02890 618521, dial= ['003, newcomp, dial=02890419689, dial='] 003, newcomp, dial=02890419689, dial= 003, newcomp, dial=02890419689, dial= Any help would be greatly appreciated. Regards, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Gadfly Database Problems
Hi, I have a python program that accesses glade and a gadfly database. The program works fine on my computer but I want to compile it so that I can put it on other computers without having to install everything that my computer has. I have had a go at compiling it using py2exe. I have used the standard setup.py from the example. I have listed the glade file and my two database files as my data_files. The compiler runs and I get the dist + build folders. When I double click the exe, the program loads and runs ok. When I get to the point of the program where the program accesses the database, the program freezes. The error log message says: Traceback (most recent call last): File "shopcard.py", line 188, in callback4 File "shopcard.py", line 228, in calc File "gadfly\dbapi20.pyo", line 26, in connect File "gadfly\dbapi20.pyo", line 46, in __init__ File "gadfly\database.pyo", line 27, in __init__ File "gadfly\sql.pyo", line 16, in getSQL ImportError: Couldn't find sql_mar.py - has setup.py been run? Callback4 is a function which calls the calc function. The calc function tries to connect to the database files. I can see the database files in the dist folder. Are there other files which I have to manually copy into the dist folder such as the sql_mar.py? Any help or pointers would be greatly appreciated. I know that this is a py2exe specific question but I have already e-mailed that list and have had no reply. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Landscape Printing
Hi, My text file is printing out in portrait. Is there any instruction that I can use so that notepad prints it in landscape? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Nearly there
Terry, Your suggestion works. It also works consistently if you fully define the path of 'filename'. eg filename = "c:/test/testprint.txt" You are right, shell execute seems to need the full path name with windows 98SE. It is strange that it does not need the full path for win xp + win 2k. Onto my next problem. My text file is printing out in portrait. Is there any instruction that I can use so that notepad prints it in landscape? Thanks, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Terry Carroll Sent: 07 January 2006 00:24 To: tutor@python.org Subject: Re: [Tutor] Nearly there This is itching at me, too. On Fri, 6 Jan 2006, John Corry wrote: > Can anyone understand or tell me why this works but the following code does > not:- > > import win32api > filename = "testprint.txt" > fileobj=open (filename, "w") > fileobj.write ("This is a test") > fileobj.close() > win32api.ShellExecute ( > 0, > "print", > filename, > None, > ".", > 0 > ) I'm wondering if ShellExecute needs a full path to find it under W98. Try this; add to the top of your code: import os.path and change your ShellExecute to this: win32api.ShellExecute ( 0, "print", os.path.abspath(filename), None, ".", 0 ) I have no idea if this will work; and the error message you're getting, > The code above gives me the error: (31, 'ShellExecute', 'A device attached > to the system is not functioning.') doesn't seem to indicate it, but it's one less thing. I'd love to know the answer when you get it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Nearly there
Thanks for all the feedback and help. The good news is that I have managed to get my windows 98 SE machine to print a text file using the follwing code:- import tempfile import win32api filename = tempfile.mktemp (".txt") open (filename, "w").write ("This is a test") win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) Can anyone understand or tell me why this works but the following code does not:- import win32api filename = "testprint.txt" fileobj=open (filename, "w") fileobj.write ("This is a test") fileobj.close() win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) The code above gives me the error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') However this code works fine on the windows xp + windows 2k. I am so happy it is like Christmas all over again! Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Further help needed!
Notepad opens and prints the text file. Regards, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Fouhy Sent: 04 January 2006 21:54 To: Tutor Subject: Re: [Tutor] Further help needed! [resending 'cause I forgot to address to tutor..] On 05/01/06, John Corry <[EMAIL PROTECTED]> wrote: > This code works on windows XP + Windows 2000. However it does not work on > windows 98SE. I have tried this code on 3 seperate machines with windows > 98SE. They all come up with the same error: > > File > "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File "C:\test\Script1.py", line 12, in ? > 0 > error: (31, 'ShellExecute', 'A device attached to the system is not > functioning.') Have you verified that the printer on your Win98 machine does work? For example, create a text file on that computer. In Windows Explorer, right-click on the text file and select 'print' from the context menu. What happens? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Further help needed!
I am using the following code to send a text file to the printer:- import win32api filename = "testprint.txt" fileobj=open (filename, "w") fileobj.write ("This is a test") fileobj.close() win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) This code works on windows XP + Windows 2000. However it does not work on windows 98SE. I have tried this code on 3 seperate machines with windows 98SE. They all come up with the same error: File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\test\Script1.py", line 12, in ? 0 error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') Is there another way to print out a text file on windows 98SE? Do I have to do something different on the windows 98SE machine? Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing error on Win 98SE
Hi + Happy New Year, With help from several people from the mailing list I have been able to print out text files on my windows XP machine. I have tried using the same program on my windows 98SE machine and I get the following error: PythonWin 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright information. Traceback (most recent call last): File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\test\Script1.py", line 12, in ? 0 error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') >>> I can manually right click the text file and left click print and the file will print to the printer. The code that I am using is below: import win32api filename = "testprint.txt" fileobj=open (filename, "w") fileobj.write ("This is a test") fileobj.close() win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) Any help would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing
Thanks for the prompt reply. This is exactly what I am looking for. However, I have tried the code on the page and I can't get it to work. import tempfile import win32api filename = tempfile.mktemp (".txt") open (filename, "w").write ("This is a test") win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) I am using the Pythoncard code editor and I get the following error: Traceback (most recent call last): File "c:\python24\jhc.py", line12, in ? 0 pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file specified .') I have played about with it and saved it in various places but I can't get it to work. Any suggestions? Do I need to import other modules? Do I need to use Pythonwin? Thanks, John. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Danny Yoo Sent: 24 December 2005 19:33 To: John Corry Cc: Tutor Subject: Re: [Tutor] Printing > I have downloaded win32, win32com, Preppy and PIL. I have had a go at > using them but can't get them to work. At the moment I can't even print > the text file. > > Is there a good helpguide/FAQ page which deals with printing text files > or is there simple code which prints a text file? Hi John, Let's see... ok, found it! Tim Golden has written a small introduction to printing: http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html His recommendation is to use the ShellExecute function in win32api to send off documents to your printer. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing
Hi + Season's Greetings! I have put together a program that queries and modifies a Gadfly database. I have captured my output. I now want to print it to paper. I have written the output to a text file. I have searched the tutor mailing list and used the mailing list advice to get my data into nice looking columns + tables. I am using Python 2.4, Glade 2, pygtk2.8.0 + wxWidgets2.6.1. I have downloaded win32, win32com, Preppy and PIL. I have had a go at using them but can't get them to work. At the moment I can't even print the text file. Is there a good helpguide/FAQ page which deals with printing text files or is there simple code which prints a text file? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor