[FAQTS] Python Knowledge Base Update -- June 24th, 2000
Fiona Czuczman
fiona at sitegnome.com
Sat Jun 24 03:11:21 EDT 2000
More information about the Python-list mailing list
Sat Jun 24 03:11:21 EDT 2000
- Previous message (by thread): [FAQTS] Python Knowledge Base Update -- June 24th, 2000
- Next message (by thread): HTML Parser? Sample Code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello Python users, Below are the entries I've entered into http://python.faqts.com today. regards, Fiona ## New Entries ################################################# ------------------------------------------------------------- Has anyone created typemaps for SWIG for Microsoft __int64 to bind them to Python long ints? http://www.faqts.com/knowledge-base/view.phtml/aid/3961 ------------------------------------------------------------- Fiona Czuczman Mark Hammond Not specifically - but note that 1.5.2 and later has LONG_LONG support, meaning you just pass the __int64 directly to Python - eg: >From pywintypes: PyObject *PyLong_FromI64(__int64 ival) { return PyLong_FromLongLong(ival); } PyObject *PyLong_FromUI64(unsigned __int64 ival) { return PyLong_FromUnsignedLongLong(ival); } BOOL PyLong_AsI64(PyObject *val, __int64 *lval) { *lval = PyLong_AsLongLong(val); return *lval != -1 || !PyErr_Occurred(); } BOOL PyLong_AsUI64(PyObject *val, unsigned __int64 *lval) { *lval = PyLong_AsUnsignedLongLong(val); return *lval != (unsigned __int64)-1 || !PyErr_Occurred(); } Should be pretty easy to wrap with SWIG... ------------------------------------------------------------- Is it possible to configure emacs so that it automatically starts in python mode when opening a file *.py? http://www.faqts.com/knowledge-base/view.phtml/aid/3963 ------------------------------------------------------------- Fiona Czuczman Piet van Oostrum You do this in the standard emacs way: (setq auto-mode-alist (cons '("\\.pyw?$" . python-mode) auto-mode-alist)) or (add-to-list 'auto-mode-alist '("\\.pyw?$" . python-mode)) It is also useful (at least on Unix) to have (add-to-list 'interpreter-mode-alist '("python" . python-mode)) ------------------------------------------------------------- Is is possible to dynamically add methods to classes in Python? http://www.faqts.com/knowledge-base/view.phtml/aid/3964 ------------------------------------------------------------- Fiona Czuczman Ken Seehof, Remco Gerlich class some_class: pass instance = some_class() def some_method(self): print "Hello!" some_class.method = some_method instance.method() eg: >>> class C: ... pass ... >>> x = C() >>> def f(self, z): ... print self, z ... >>> C.f = f >>> x.f(12) <__main__.C instance at 190d450> 12 >>> ------------------------------------------------------------- Can anyone tell me how I would go about disabling a pmw combobox? http://www.faqts.com/knowledge-base/view.phtml/aid/3960 ------------------------------------------------------------- Fiona Czuczman Richard Chamberlain In the ToDo list for Pmw disabling is mentioned so hopefully we'll have a solution from the source before long. In the meantime... This is a bit of hack (in the derogatory sense of the word) but hey! So you basically want to import the myComboBox class and create an instance just as you would with Pmw. I've added a couple of methods - disable and enable suprisingly enough. Included below is some test code. It works in the same way as you mentioned, by unbinding the events, and rebinding them to enable it. Richard from Tkinter import * import Pmw root = Tk() root.title('Disabling ComboBox Hack') Pmw.initialise() class myComboBox(Pmw.ComboBox): def disable(self): # Rebind things to my empty handler self.component('arrowbutton').bind('<1>',self.handler) self.component('arrowbutton').bind('<3>',self.handler) self.component('arrowbutton').bind('<Shift- 3>',self.handler) self.component('entryfield_entry').configure (state='disabled',fg='grey') def enable(self): # bind the events back up to the original methods self.component('arrowbutton').bind('<1>',self._postList) self.component('arrowbutton').bind('<3>',self._next) self.component('arrowbutton').bind('<Shift-3>', self._previous) self.component('arrowbutton').configure(takefocus=1) self.component('entryfield_entry').configure (state='normal',fg='black') def handler(self,event): # so it doesn't propagate the event return('break') # Now test it comboentries = ("Pmw Should", "have a nicer way", "to disable", "a combo box") theEnabler = Button(root, text='Enabled',padx=20, pady=10) theEnabler.pack(expand=1, fill=BOTH, padx=8, pady=8) combobox = myComboBox(root, label_text='Disabling Combobox:', labelpos='wn', listbox_width=24, dropdown=1, scrolledlist_items=comboentries) combobox.pack(fill=BOTH, expand=1, padx=8, pady=8) combobox.selectitem(comboentries[0]) def disable(event): if theEnabler['text']=='Enabled': combobox.disable() theEnabler.configure(text='Disabled') else: combobox.enable() theEnabler.configure(text='Enabled') theEnabler.bind('<Button-1>',disable) root.mainloop() ## Edited Entries ############################################## ------------------------------------------------------------- I'm new to Python, where should I start? Can you give me an overview of the Python Documentation? Do I need books to learn Python? http://www.faqts.com/knowledge-base/view.phtml/aid/1356 ------------------------------------------------------------- Nathan Wallace, Fiona Czuczman Tom Funk,Simon Brunning,Dparsavand, Phil Austin The handbook is part of the on-line documentation available at the Python web site and with the Python installation -- and it's free. You may not need to go to a bookstore if you peruse the following page: http://www.python.org/doc/ The tutorial is quite complete: http://www.python.org/doc/current/tut/tut.html If you work through the tutorial, it should carry you pretty far along in your quest. I found it to be *quite* useful. The Library Reference discusses the modules that ship with Python. http://www.python.org/doc/current/lib/lib.html The Language Reference is a bit more abstract, and *much* more dry. However, it does completely describe the core Python language constructs, grammar and syntax. It's often referred to as material for "Language Lawyers." http://www.python.org/doc/current/ref/ref.html I like the Module Index: http://www.python.org/doc/current/modindex.html It allows you to jump straight to the module of your choice. If you're using Win32 (as I do), then you may find the MS HTML Help version to be useful (it's my favorite). If you use Win32, you might want to check out: http://www.orgmf.com.ar/condor/pytstuff.html Best of all, these very complete works of non-fiction are FREE.... gotta love that! I own five Python books, but I still find myself referring back to the Python documentation regularly. --- As one newbie to another, I can recommend <http://www.idi.ntnu.no/~mlh/python/programming.html> for an introduction to programming, and <http://www.idi.ntnu.no/~mlh/python/instant.html> for a bit more on Python. After that, you might want to look at <http://starship.python.net/crew/amk/grimoire/html/> for a 'cookbook' of useful techniques. If none of these take your fancy, there are other links at the python site - <http://www.python.org/doc/Intros.html>. If you have any questions look at the FAQs - <http://www.python.org/doc/FAQ.html> If you follow http://www.pythonlabs.com/ to http://www.vex.net/parnassus/ and then choose the Info/Books/Tutorials link then Tutorials, you will get quite a few alternatives. Also, have a look at: http://www.networkcomputing.com/unixworld/tutorial/005/005.html http://yhslug.tux.org/obp/thinkCS/thinkCSpy The current numpy tutorial (supercedes the one that's cited on Parassus): http://numpy.sourceforge.net/ Richard P. Muller's python short course: http://www.wag.caltech.edu/home/rpm/python_course/ Konrad Hinsen's Python for Science tutorial http://starship.python.net/crew/hinsen/
- Previous message (by thread): [FAQTS] Python Knowledge Base Update -- June 24th, 2000
- Next message (by thread): HTML Parser? Sample Code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list