TextCtrl steals selection from other applications in linux window manager

Hi,

I recently upgraded my Linux python environment from Python 2.4.3 (#3, Aug
1 2006, 10:29:54) to ActivePython 2.7.1.3. My python applications that have
been stable for many years seem to be working OK except for one major
annoyance.

When I have text selected in a different application(Konsole for example)
the TextCtrl in my python application removes the selection when the
TextCtrl is updated with a new value(SetValue).

I have reproduced the problem with the example in the following tutorial, so
I am confident that the problem is not with my python application code.
When I pass the mouse over this application the selection in other
non-python applications goes away.

http://www.java2s.com/Tutorial/Python/0380__wxPython/Addtextcontroltoframe.htm

Is this normal behavior for this release?

Basically, I cannot edit, copy or past in other applications while my python
applications are running because of this.

I am using K Desktop Environment. Release 3.3.1-11.el4 Red Hat with UNIX
system behavior.

Any help on this would be appreciated.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/TextCtrl-steals-selection-from-other-applications-in-linux-window-manager-tp3378745p3378745.html
Sent from the wxPython-users mailing list archive at Nabble.com.

SetValue does change the selection in the widget (even if it is only setting both the beginning and end of the selection to the end of the new value) so it is feasible that it should also update *the* system Selection. So, since in X-Windows there can only be one Selection at a time the other app looses it at that time. I don't think that wxWidgets explicitly does anything that would cause this, so it is probably new behavior in the GTK text widget.

It may be annoying but I'm not sure if it can be considered a bug since it is the native widget that is doing it... If the values in your textctrls are only updated programatically then you can work around this issue by using a different widget, such as wx.StaticText.

···

On 2/9/11 7:23 PM, WxWeeb wrote:

Hi,

I recently upgraded my Linux python environment from Python 2.4.3 (#3, Aug
1 2006, 10:29:54) to ActivePython 2.7.1.3. My python applications that have
been stable for many years seem to be working OK except for one major
annoyance.

When I have text selected in a different application(Konsole for example)
the TextCtrl in my python application removes the selection when the
TextCtrl is updated with a new value(SetValue).

--
Robin Dunn
Software Craftsman

Hi Robin,

The values in my TextCtrl are updated programmatically, but occasionally updating from the GUI is needed. I thought about the StaticText workaround that you suggested, but the background color does not work for some reason. I am using python to view the real time state of registers in an FPGA and I am using background color to indicate the register is changing or has changed. I have a very nice suite of python apps centered around the ability to use other development tools concurrently while the python apps are up.

I did some more experimentation with the TextCtrl widget and found that when I use style=wx.TE_MULTILINE, the problem goes away. This looks like a workaround that I can use, but the inconsistency of behavior between multi-line vs. single-line may be evidence that there is a bug somewhere.

This line has the problem:
self.text_control = wx.TextCtrl( toplevel_panel,-1,"0", size=(100,-1), style=wx.ALIGN_RIGHT|wx.TE_PROCESS_ENTER )

This line is the workaround that does not have the problem:
self.text_control = wx.TextCtrl( toplevel_panel,-1,"0", size=(100,20), style=wx.ALIGN_RIGHT|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE )

Thanks

···

-----Original Message-----
From: wxpython-users@googlegroups.com [mailto:wxpython-users@googlegroups.com] On Behalf Of Robin Dunn
Sent: Friday, February 11, 2011 12:34 PM
To: wxpython-users@googlegroups.com
Subject: Re: [wxPython-users] TextCtrl steals selection from other applications in linux window manager

On 2/9/11 7:23 PM, WxWeeb wrote:

Hi,

I recently upgraded my Linux python environment from Python 2.4.3 (#3,
Aug
1 2006, 10:29:54) to ActivePython 2.7.1.3. My python applications
that have been stable for many years seem to be working OK except for
one major annoyance.

When I have text selected in a different application(Konsole for
example) the TextCtrl in my python application removes the selection
when the TextCtrl is updated with a new value(SetValue).

SetValue does change the selection in the widget (even if it is only setting both the beginning and end of the selection to the end of the new value) so it is feasible that it should also update *the* system Selection. So, since in X-Windows there can only be one Selection at a time the other app looses it at that time. I don't think that wxWidgets explicitly does anything that would cause this, so it is probably new behavior in the GTK text widget.

It may be annoying but I'm not sure if it can be considered a bug since it is the native widget that is doing it... If the values in your textctrls are only updated programatically then you can work around this issue by using a different widget, such as wx.StaticText.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi,

In Feb 2011, I posted this issue I'm having with upgrading from Python 2.4.3
to ActivePython 2.7.1.3. The workaround that I discovered turned out not to
be a workaround, it just masked to underlying problem that I am having.
Since then, I have done some more experimentation and now I have additional
clues.

With 2.7, when I start this application from the unix command line, it
works fine.

python TextCtrlApp.py

When I start this application from the python console command line, I get
the undesired behavior that I describe in the original post.

execfile("TextCtrlApp.py")

I don't have this problem with Python 2.4.

My entire environment for using python is centered around launching GUIs
from ipython, so using the method of launching GUIs from the unix prompt is
not a solution.

Is there another way to launch the application from within the python
console that would resolve this issue?

···

---------------------------------

Here is the code for TextCtrlApp.py:

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
        panel = wx.Panel(self, -1)
        panel.Bind(wx.EVT_MOTION, self.OnMove)
        wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
        self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10))
    def OnMove(self, event):
        pos = event.GetPosition()
        self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))

app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()

------------------------------

Here is the content of the original post:

I recently upgraded my Linux python environment from Python 2.4.3 (#3, Aug 1
2006, 10:29:54) to ActivePython 2.7.1.3. My python applications that have
been stable for many years seem to be working OK except for one major
annoyance.

When I have text selected in a different application(Konsole for example)
the TextCtrl in my python application removes the selection when the
TextCtrl is updated with a new value(SetValue).

I have reproduced the problem with the example in the following tutorial, so
I am confident that the problem is not with my python application code.

When I pass the mouse over this application, the selection in other
non-python applications goes away.

Is this normal behavior for this release?

Basically, I cannot edit, copy or past in other applications while my python
applications are running because of this.

I am using K Desktop Environment. Release 3.3.1-11.el4 Red Hat with UNIX
system behavior.

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/TextCtrl-steals-selection-from-other-applications-in-linux-window-manager-tp3378745p4921577.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I would probably write a function that launches the script in a new process and use that instead of execfile. For example:

     import subprocess
     def execfile_new_process(script, *args):
         cmd = [sys.executable, '-u', script] + args
         return subprocess.call(cmd)

···

On 10/20/11 7:11 AM, WxWeeb wrote:

Hi,

In Feb 2011, I posted this issue I'm having with upgrading from Python 2.4.3
to ActivePython 2.7.1.3. The workaround that I discovered turned out not to
be a workaround, it just masked to underlying problem that I am having.
Since then, I have done some more experimentation and now I have additional
clues.

With 2.7, when I start this application from the unix command line, it
works fine.

python TextCtrlApp.py

When I start this application from the python console command line, I get
the undesired behavior that I describe in the original post.

execfile("TextCtrlApp.py")

I don't have this problem with Python 2.4.

My entire environment for using python is centered around launching GUIs
from ipython, so using the method of launching GUIs from the unix prompt is
not a solution.

Is there another way to launch the application from within the python
console that would resolve this issue?

--
Robin Dunn
Software Craftsman

Hi Robin,

I was able to get the script to run using your suggestion, but I still have the same issue. Now I know a better way to launch a script from the python shell and I will use this going forward.

While investigating further, I realized that my previous post is based on false information, so I would like to delete the post to avoid further confusion on my ongoing issue described in the original post.

In fact, when I run the TextCtrlApp.py script from the linux command prompt using python 2.7.1.3, I get the undesired behavior. Consequently, the direction this was going will not resolve the issue for me.

When I was testing earlier this week, I was using the wrong python version, and arrived at the wrong conclusion.

Do you think I should start another thread with a better example of my original issue? Or, should I delete yesterday's post and stay on this thread?

Just start a new thread.

···

On 10/21/11 2:48 PM, Weeber, William B (Bill) wrote:

Hi Robin,

I was able to get the script to run using your suggestion, but I still have the same issue. Now I know a better way to launch a script from the python shell and I will use this going forward.

While investigating further, I realized that my previous post is based on false information, so I would like to delete the post to avoid further confusion on my ongoing issue described in the original post.

In fact, when I run the TextCtrlApp.py script from the linux command prompt using python 2.7.1.3, I get the undesired behavior. Consequently, the direction this was going will not resolve the issue for me.

When I was testing earlier this week, I was using the wrong python version, and arrived at the wrong conclusion.

Do you think I should start another thread with a better example of my original issue? Or, should I delete yesterday's post and stay on this thread?

--
Robin Dunn
Software Craftsman