I’m having trouble getting this working under windows. GetInsertionPoint always returns zero for me. Can someone else verify? Is there some way to work around this? All I’m trying to do is insert some text wherever the cursor is, when the user clicks a button that is elsewhere on the dialog.
To try the example code, just run it, and click around in the combobox to set the cursor wherever you want it. Then click the button to see what GetInsertionPoint returns.
The example code works on OSX and Linux, but just not windows.
Oops, I left a little cruft in the getinsertionpoint_bug.py file; remove the “import win32gui_struct” from the top if you want to run it.
···
On Wednesday, December 19, 2012 9:43:51 AM UTC-5, dhyams wrote:
I’m having trouble getting this working under windows. GetInsertionPoint always returns zero for me. Can someone else verify? Is there some way to work around this? All I’m trying to do is insert some text wherever the cursor is, when the user clicks a button that is elsewhere on the dialog.
To try the example code, just run it, and click around in the combobox to set the cursor wherever you want it. Then click the button to see what GetInsertionPoint returns.
The example code works on OSX and Linux, but just not windows.
I didn’t know about that…but by coincidence I had tried it. The problem there is that if I manually set the focus to the combobox, all of the contents are then automatically selected. Which means that the insertion point is right back at zero again. This can be tested in my demo code by putting
self.combobox.SetFocus() as the first line in the OnButton() handler. Perhaps there’s still something that I’m not seeing though…
def OnCombo(self, evt):
print "The insertion point of the combobox control is ",self.combobox.GetInsertionPoint()
With this I get a non zero value.
Werner
···
On 19/12/2012 16:33, Daniel Hyams wrote:
I didn't know about that...but by coincidence I had tried it. The problem there is that if I manually set the focus to the combobox, *all* of the contents are then automatically selected. Which means that the insertion point is right back at zero again. This can be tested in my demo code by putting
self.combobox.SetFocus() as the first line in the OnButton() handler. Perhaps there's still something that I'm not seeing though...
I’m trying to insert text, at the insertion point, in response to the user clicking a button somewhere else…exactly like the example.
The application is a calculator-like thing, where you click a button “exp” or something, and it inserts “exp()” in the combobox text field, and also sets the insertion point to in between the parens. If the user clicks “exp” then" cos", I want the text in the display to be exp(cos()), which means that I need to know where to insert text; can’t just tack it onto the end.
I didn’t know about that…but by coincidence I had tried it. The problem there is that if I manually set the focus to the combobox, all of the contents are then automatically selected. Which means that the insertion point is right back at zero again. This can be tested in my demo code by putting
self.combobox.SetFocus() as the first line in the OnButton() handler. Perhaps there’s still something that I’m not seeing though…
What are you actually trying to accomplish?
self.Bind(wx.EVT_TEXT, self.OnComboText)
def OnCombo(self, evt):
print "The insertion point of the combobox control is ",self.combobox.GetInsertionPoint()
I gave up on this one…I ended up building a combo control from wx.combo.ComboCtrl. I hate that the lacking of a working detail forced me into that, just from a software engineering point of view…the root of the problem is definitely not wxPython/wxWidgets though…it’s a nonworking Windows API.
I tried Windows API’s directly (using win32api.SendMessage) to get the selection from the combo box, to no avail. And I know that I was using SendMessage correctly, because other messages that I tried worked just fine. I even used CB_GETCOMBOBOXINFO message to successfully get a handle to the underlying text control in the combobox, but still a win32api.SendMessage to that still did not return the correct results.
So if a direct Windows API refuses to report correct, there’s nothing that wx can do about that.
So anyway. There is a viable workaround (wx.combo.ComboCtrl). The only thing that it doesn’t have that I was it did, is a drop shadow behind the drop-down list when that’s displayed. I tried the magic CS_DROPSHADOW incantation, but that didn’t work so I dropped it.
···
On Wed, Dec 19, 2012 at 10:54 AM, Daniel Hyams dhyams@gmail.com wrote:
I’m trying to insert text, at the insertion point, in response to the user clicking a button somewhere else…exactly like the example.
The application is a calculator-like thing, where you click a button “exp” or something, and it inserts “exp()” in the combobox text field, and also sets the insertion point to in between the parens. If the user clicks “exp” then" cos", I want the text in the display to be exp(cos()), which means that I need to know where to insert text; can’t just tack it onto the end.
I didn’t know about that…but by coincidence I had tried it. The problem there is that if I manually set the focus to the combobox, all of the contents are then automatically selected. Which means that the insertion point is right back at zero again. This can be tested in my demo code by putting
self.combobox.SetFocus() as the first line in the OnButton() handler. Perhaps there’s still something that I’m not seeing though…
What are you actually trying to accomplish?
self.Bind(wx.EVT_TEXT, self.OnComboText)
def OnCombo(self, evt):
print "The insertion point of the combobox control is ",self.combobox.GetInsertionPoint()
Oh, and forgot to mention that I even fake-typed into the combobox using SendMessage of WM_CHAR straight to the underlying edit control. Still didn’t work…the characters ended up at position 0 instead of the insertion point. Tried WM_KEYUP/WM_KEYDOWN too. Basically nothing works…it’s almost like MS is resetting the insertion point back to 0 whenever the focus is lost.
···
On Wed, Dec 19, 2012 at 6:44 PM, Daniel Hyams dhyams@gmail.com wrote:
I gave up on this one…I ended up building a combo control from wx.combo.ComboCtrl. I hate that the lacking of a working detail forced me into that, just from a software engineering point of view…the root of the problem is definitely not wxPython/wxWidgets though…it’s a nonworking Windows API.
I tried Windows API’s directly (using win32api.SendMessage) to get the selection from the combo box, to no avail. And I know that I was using SendMessage correctly, because other messages that I tried worked just fine. I even used CB_GETCOMBOBOXINFO message to successfully get a handle to the underlying text control in the combobox, but still a win32api.SendMessage to that still did not return the correct results.
So if a direct Windows API refuses to report correct, there’s nothing that wx can do about that.
So anyway. There is a viable workaround (wx.combo.ComboCtrl). The only thing that it doesn’t have that I was it did, is a drop shadow behind the drop-down list when that’s displayed. I tried the magic CS_DROPSHADOW incantation, but that didn’t work so I dropped it.
On Wed, Dec 19, 2012 at 10:54 AM, Daniel Hyams dhyams@gmail.com wrote:
I’m trying to insert text, at the insertion point, in response to the user clicking a button somewhere else…exactly like the example.
The application is a calculator-like thing, where you click a button “exp” or something, and it inserts “exp()” in the combobox text field, and also sets the insertion point to in between the parens. If the user clicks “exp” then" cos", I want the text in the display to be exp(cos()), which means that I need to know where to insert text; can’t just tack it onto the end.
I didn’t know about that…but by coincidence I had tried it. The problem there is that if I manually set the focus to the combobox, all of the contents are then automatically selected. Which means that the insertion point is right back at zero again. This can be tested in my demo code by putting
self.combobox.SetFocus() as the first line in the OnButton() handler. Perhaps there’s still something that I’m not seeing though…
What are you actually trying to accomplish?
self.Bind(wx.EVT_TEXT, self.OnComboText)
def OnCombo(self, evt):
print "The insertion point of the combobox control is ",self.combobox.GetInsertionPoint()