From: Kevin A. <al...@se...> - 2004-04-07 16:05:24
|
self in your event handlers refers to your background. self.components is a dictionary of all the components on your background. It has some extra code that allows you to access each component using "dot" notation (e.g. self.components.fldBob) or normal dictionary notation, self.components["fldBob"]. setFocus() is a method of each component, so you just call it. For example, if the field you want to want to change the focus to is called fldBob then self.components.fldBob.setFocus() should do the trick. In addition, you'll probably want to call setSelection after calling setFocus to select all the text in the field. If you want to save some typing you can create a local reference to the component before you call the methods. def on_somebutton_mouseClick(self, event): input = self.components.fldBob # your validation check code here # validation failed so do the focus/selection change input.setFocus() input.setSelection(-1, -1) If you use the findfiles tool, you should be able to search/grep the PythonCard samples and tools for examples of most of the common actions like this. Note that the (-1, -1) convenience values above were added to to the underlying SetSelection method long after PythonCard had started, so some samples still go to the trouble of calculating the number of characters in a field. http://pythoncard.sourceforge.net/findfiles.html ka On Apr 7, 2004, at 6:13 AM, Schollnick, Benjamin wrote: > Okay, > > I have fixed one problem, but I am still attempting to figure out > how to use SetFocus... And failing... > > I have multiple controls in this PythonCard application, and want > to manually change the focus from one control to another.... > > The problem, for me, is that SetFocus (from wxPython) seems to > need to be called from the "control" that you wish to change to. For > example, > textcntrl.SetFocus (), appears to change the focus to the textcntrl. > (This > was > grepped from the demo directory.) > > But with PythonCard we appear to be operating from the events, not > the controls. > > How would I access a control directly in Pythoncard to call the > SetFocus? > > I found the SetFocus command in the "self" object, but have not > found any > documentation that covers it.... > > Does anyone have a small code fragment example? Or a small test app > example > that you could post? Because I fear that I am missing something real > obvious... > > - Benjamin |