One very good thing with Python is that most third party modules use
the same style of coding.
The project I'm leading is about to move from prototype to the real thing and I want the team to adopt a common Python coding style. Can someone point me to a "style guide" document or some good examples (the modules mentioned above)...
On a related note, are there any wxPython-specific coding styles / design patterns documented anywhere that I could borrow from?
BTW, your mail client is not wrapping your text (which is text/plain);
please see: http://www.imc.org/rfc2646.
Regards,
···
On Mon, May 20, 2002 at 07:38:43AM -0400, Garry Simmons wrote:
The project I'm leading is about to move from prototype to the real thing
and I want the team to adopt a common Python coding style. Can someone point
me to a "style guide" document or some good examples (the modules mentioned
above)...
On a related note, are there any wxPython-specific coding styles / design
patterns documented anywhere that I could borrow from?
I've got a bit of code that grabs keystrokes from a TextCtrl, and mimics
the behavior in another window. I use GetKeyCode() and then decide what
to do based on the character received. On Linux, it sees all the
keystrokes I've tried. On Windoze, it appears to ignore control
characters. Is it something I've done wrong, or is Windoze incapable of
doing what I want (as usual)? There's probably a better way than using
GetKeyCode() and I'm open to suggestion.
On the Windoze machine I have: Windows 95, Python 2.2.1 (#34) and
wxPython 2.3.2.1 (if the CHANGES file is up to date)
On the Linux box I have Red Hat 7.2 (kernel 2.4.9-31), Python 2.2.2-2,
and wxPython 2.3.2.1-1.
Thanx.
- --
Kevin Cole, RHCE, Linux Admin | E-mail: kjcole@gri.gallaudet.edu
Gallaudet Research Institute | WWW: http://gri.gallaudet.edu/~kjcole/
Hall Memorial Bldg S-419 | Voice: (202) 651-5135
Washington, D.C. 20002-3695 | FAX: (202) 651-5746
I've got a bit of code that grabs keystrokes from a TextCtrl, and mimics
the behavior in another window. I use GetKeyCode() and then decide what
to do based on the character received. On Linux, it sees all the
keystrokes I've tried. On Windoze, it appears to ignore control
characters.
Which events are you catching?
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
EVT_CHAR, which seems to be enough under Linux but not Windows. (I took
my code from the wxTextCtrl in the demo, and thought I extracted
everything I'd need, but may have missed something important.)
- --
Kevin Cole
···
On Mon, 20 May 2002, Robin Dunn wrote:
> I've got a bit of code that grabs keystrokes from a TextCtrl, and mimics
> the behavior in another window. I use GetKeyCode() and then decide what
> to do based on the character received. On Linux, it sees all the
> keystrokes I've tried. On Windoze, it appears to ignore control
> characters.
> > I've got a bit of code that grabs keystrokes from a TextCtrl, and
mimics
> > the behavior in another window. I use GetKeyCode() and then decide
what
> > to do based on the character received. On Linux, it sees all the
> > keystrokes I've tried. On Windoze, it appears to ignore control
> > characters.
>
> Which events are you catching?
EVT_CHAR, which seems to be enough under Linux but not Windows. (I took
my code from the wxTextCtrl in the demo, and thought I extracted
everything I'd need, but may have missed something important.)
Right. On MSW not every keystroke is turned into a EVT_CHAR event as some
of them will get "translated" to other message types. However you should
get an EVT_KEY_DOWN for every key on MSW, but the keycode you get won't
necessarily reflect the shift state, non-US keybords, etc.
If all you need is to keep two wxTextCtrls in sync then you could catch
EVT_TEXT and then just get all the text and etc. from one and dump it into
the other.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
This is bound to be a silly question but ... how do you capture keypress
events (using the EVT_CHAR macro for example)? I've been trying to get
this to work all day and can't understand what I'm missing. My test
script is as follows:
from wxPython.wx import *
App = wxPySimpleApp()
class myframe(wxFrame):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "Test Frame")
self.SetFocus()
self.Show(1)
if your write print "keypress!", then only thing that you obtain is the
string 'keypress' on your console.
You can intercept the key with:
key = event.KeyCode()
print key #prints the code of the key
.
.
.
event.skip()
I hope it help you.
Julio Jiménez
···
El Mar 21 May 2002 12:36, escribió:
This is bound to be a silly question but ... how do you capture keypress
events (using the EVT_CHAR macro for example)? I've been trying to get
this to work all day and can't understand what I'm missing. My test
script is as follows:
from wxPython.wx import *
App = wxPySimpleApp()
class myframe(wxFrame):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "Test Frame")
self.SetFocus()
self.Show(1)
This is bound to be a silly question but ... how do you capture keypress
events (using the EVT_CHAR macro for example)? I've been trying to get
this to work all day and can't understand what I'm missing. My test
script is as follows:
from wxPython.wx import *
App = wxPySimpleApp()
class myframe(wxFrame):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "Test Frame")
self.SetFocus()
self.Show(1)
Having *JUST* gone down this road myself, I think, for a change I can
actually SUPPLY an answer. Will wonders never cease?
Easy: In your OnChar routine, do something like:
kcode = event.GetKeyCode()
curse = self.U.GetLastPosition()
if kcode in range(32,127):
self.U.AppendText(chr(kcode))
(This is demonstated in the wxPython demo. See wxTextCtrl.)
However, if you've been reading recently, you may have seen me ask about
why this worked fine under Linux but doesn't get control keys under
Windows. Robin replied:
Right. On MSW not every keystroke is turned into a EVT_CHAR event as
some of them will get "translated" to other message types. However
you should get an EVT_KEY_DOWN for every key on MSW, but the keycode
you get won't necessarily reflect the shift state, non-US keybords,
etc.
If all you need is to keep two wxTextCtrls in sync then you could
catch EVT_TEXT and then just get all the text and etc. from one and
dump it into the other.
···
On 21 May 2002, bryan cole wrote:
This is bound to be a silly question but ... how do you capture keypress
events (using the EVT_CHAR macro for example)? I've been trying to get
this to work all day and can't understand what I'm missing. My test
script is as follows:
from wxPython.wx import *
App = wxPySimpleApp()
class myframe(wxFrame):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "Test Frame")
self.SetFocus()
self.Show(1)
Thanks everyone for the help. Julio's modifications to my example (to
add a wxPanel inside the wxFrame) worked.
Why does a wxPanel capture keypress / wxEVT_CHAR events but not a
wxFrame? Any logic behind this?
I saw the previous discussion of processing EVT_CHAR events on Windows
vs. Linux, however I have been unable to get either EVT_CHAR or
EVT_KEY_DOWN to work with a wxFrame on either wxGTK or wxMSW.
Thanks everyone for the help. Julio's modifications to my example (to
add a wxPanel inside the wxFrame) worked.
Why does a wxPanel capture keypress / wxEVT_CHAR events but not a
wxFrame? Any logic behind this?
I saw the previous discussion of processing EVT_CHAR events on Windows
vs. Linux, however I have been unable to get either EVT_CHAR or
EVT_KEY_DOWN to work with a wxFrame on either wxGTK or wxMSW.
A wxFrame, is only a square where you can add components, wxTextCtrl...
but it don't respond to key events like TAB key to change the focus from one control to other.
a wxPanel, is a container to objects that add capabilities to respond a lot of events (wxwindows documentation)
You can add more than one wxPanel to your wxFrame, and the controls inside its respond only into the wxPanel you are.
I think the best way to learn about it is to look at the links in wxPython main page...
I must be looking in the wrong place. Where, in the wxHTML docs can I
find info on the event-capabilities of wxPanel vs. wxFrame.
Bryan
···
There is a logic, and is in the wxwindows manual.
A wxFrame, is only a square where you can add components, wxTextCtrl...
but it don't respond to key events like TAB key to change the focus from
one control to other.
a wxPanel, is a container to objects that add capabilities to respond a
lot of events (wxwindows documentation)
You can add more than one wxPanel to your wxFrame, and the controls
inside its respond only into the wxPanel you are.
I think the best way to learn about it is to look at the links in
wxPython main page...
I must be looking in the wrong place. Where, in the wxHTML docs can I
find info on the event-capabilities of wxPanel vs. wxFrame.
Bryan
There is a logic, and is in the wxwindows manual.
A wxFrame, is only a square where you can add components, wxTextCtrl...
but it don't respond to key events like TAB key to change the focus from
one control to other.
a wxPanel, is a container to objects that add capabilities to respond a
lot of events (wxwindows documentation)
You can add more than one wxPanel to your wxFrame, and the controls
inside its respond only into the wxPanel you are.
I think the best way to learn about it is to look at the links in
wxPython main page... :)
Julio Jiménez
_______________________________________________
wxpython-users mailing list
Hello Bryan
I have then WxWindows 2.3 help Docs in HTML format, December 7th 2001…
(there is more recent)
If you look for wxFrame (Alphabetical class reference), you can notice that
there isn’t reference to events. Only that is derived from wxEvtHandler as
wxPanel is…
But if yoy look for wxPanel, you can red at the first paragraph…
wxPanel
A panel is a window on which controls are placed. It is usually placed
within a frame. It contains minimal extra functionality over and above its
parent class wxWindow; its main purpose is to be similar in appearance and
functionality to a dialog, but with the flexibility of having any window
as a parent.
Note: if not all characters are being intercepted by your OnKeyDown
or OnChar handler, it may be because you are using the wxTAB_TRAVERSAL style,
which grabs some keypresses for use by child controls.
it give you a tip. (… extra functionality… see the note… intercepted
by your OnKeyDown… or OnChar…)
I found this problem in my first program on wxPython… many wxTextControl
than don’t respond to TAB key…
It's been rewritten into an official document. See
PEP nr 8 is the Style Guide for Python Code, and it's
basically Guido's essay. It's worth taking a look at
the PEPs to understand how Python is evolving, particularly
the Meta-PEPs.