Focus of an Item

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Focus of an Item

Fredrik Östlund
Hi,

is it possible to give a given Item of a View focus programatically? (E.g.
shifting the focus to a textbox when a button is clicked)

best regards

Fredrik Östlund

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus of an Item

bryce hendrix-2
Unfortunately, the only way I know of is by creating a Handler. In the
handler you can dig through the view until you find the control you want
to set focus to.

Bryce

[hidden email] wrote:

> Hi,
>
> is it possible to give a given Item of a View focus programatically? (E.g.
> shifting the focus to a textbox when a button is clicked)
>
> best regards
>
> Fredrik Östlund
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>  

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus of an Item

Fredrik Östlund
In reply to this post by Fredrik Östlund
Hi

Thanks for answering Bryce. I still can't figure out how to give focus to an
Item. Could you give me an example or a pointer on how to get started?

best regards

Fred


Message: 1
Date: Tue, 12 Jan 2010 20:09:53 +0100
From: <[hidden email]>
Subject: [Enthought-Dev] Focus of an Item
To: <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original

Hi,

is it possible to give a given Item of a View focus programatically? (E.g.
shifting the focus to a textbox when a button is clicked)

best regards

Fredrik ?stlund



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

Message: 2
Date: Tue, 12 Jan 2010 13:14:01 -0600
From: bryce hendrix <[hidden email]>
Subject: Re: [Enthought-Dev] Focus of an Item
To: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Unfortunately, the only way I know of is by creating a Handler. In the
handler you can dig through the view until you find the control you want
to set focus to.

Bryce

--------------------------------------------------
From: <[hidden email]>
Sent: Thursday, January 14, 2010 7:00 PM
To: <[hidden email]>
Subject: Enthought-Dev Digest, Vol 65, Issue 26

> Send Enthought-Dev mailing list submissions to
> [hidden email]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.enthought.com/mailman/listinfo/enthought-dev
> or, via email, send a message with subject or body 'help' to
> [hidden email]
>
> You can reach the person managing the list at
> [hidden email]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Enthought-Dev digest..."
>
>
> Today's Topics:
>
>   1. Re: chaco plot legend font (Peter Wang)
>   2. Re: chaco plot legend font (Peter Wang)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 14 Jan 2010 11:15:02 -0600
> From: Peter Wang <[hidden email]>
> Subject: Re: [Enthought-Dev] chaco plot legend font
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
> On Jan 14, 2010, at 2:41 AM, Boiteux, Benoit wrote:
>
>> Hi,
>> Can someone indicate me how to change the font color of the legend
>> text of a chaco plot?
>
> Unfortunately, it's currently a little complicated to do this.  Once
> you have created a legend, you can set the color on all of its cached
> labels:
>
> # call get_preferred_size() to force creation of the labels
> legend.get_preferred_size()
> # update all the labels
> for label in legend._cached_labels:
>   label.color = "red"
>
> I will also modify the legend class now to have a "text_color" trait,
> so if you are on the SVN trunk, then you can do an update once that's
> checked in.
>
> -Peter
>
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 14 Jan 2010 11:31:13 -0600
> From: Peter Wang <[hidden email]>
> Subject: Re: [Enthought-Dev] chaco plot legend font
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
> On Jan 14, 2010, at 11:15 AM, Peter Wang wrote:
>
>> I will also modify the legend class now to have a "text_color" trait,
>> so if you are on the SVN trunk, then you can do an update once that's
>> checked in.
>
> OK, I've committed a fix for this, revision r25121 in SVN.  I decided
> to just call the trait "color" instead of "text_color".
>
> It's worth noting, however, that if you need to tweak the color of a
> single label, you can still use the approach I indicated in the
> previous email.
>
> -Peter
>
>
>
> ------------------------------
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
> End of Enthought-Dev Digest, Vol 65, Issue 26
> *********************************************
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus of an Item

bryce hendrix-2
This finds the first instance of a wxTextCtrl and sets focus on it.

import wx

from enthought.traits.api import HasTraits, Button, Str
from enthought.traits.ui.api import View, Item, Handler

class FocusHandler(Handler):

     def object_focus_button_changed(self, info):
         for control in info.ui.control.GetChildren()[0].GetChildren():
             if isinstance(control, wx.TextCtrl):
                 control.SetFocus()
                 break

class FocusExample(HasTraits):
     focus_button = Button("change focus")
     text = Str()

     traits_view = View(Item('focus_button'),
                        Item('text'),
                        handler=FocusHandler())

FocusExample().configure_traits()



On 01/14/2010 02:49 PM, [hidden email] wrote:

> Hi
>
> Thanks for answering Bryce. I still can't figure out how to give focus to an
> Item. Could you give me an example or a pointer on how to get started?
>
> best regards
>
> Fred
>
>
> Message: 1
> Date: Tue, 12 Jan 2010 20:09:53 +0100
> From:<[hidden email]>
> Subject: [Enthought-Dev] Focus of an Item
> To:<[hidden email]>
> Message-ID:<[hidden email]>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> reply-type=original
>
> Hi,
>
> is it possible to give a given Item of a View focus programatically? (E.g.
> shifting the focus to a textbox when a button is clicked)
>
> best regards
>
> Fredrik ?stlund
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 12 Jan 2010 13:14:01 -0600
> From: bryce hendrix<[hidden email]>
> Subject: Re: [Enthought-Dev] Focus of an Item
> To: [hidden email]
> Message-ID:<[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Unfortunately, the only way I know of is by creating a Handler. In the
> handler you can dig through the view until you find the control you want
> to set focus to.
>
> Bryce
>
> --------------------------------------------------
> From:<[hidden email]>
> Sent: Thursday, January 14, 2010 7:00 PM
> To:<[hidden email]>
> Subject: Enthought-Dev Digest, Vol 65, Issue 26
>
>    
>> Send Enthought-Dev mailing list submissions to
>> [hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>> or, via email, send a message with subject or body 'help' to
>> [hidden email]
>>
>> You can reach the person managing the list at
>> [hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Enthought-Dev digest..."
>>
>>
>> Today's Topics:
>>
>>    1. Re: chaco plot legend font (Peter Wang)
>>    2. Re: chaco plot legend font (Peter Wang)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Thu, 14 Jan 2010 11:15:02 -0600
>> From: Peter Wang<[hidden email]>
>> Subject: Re: [Enthought-Dev] chaco plot legend font
>> To: [hidden email]
>> Message-ID:<[hidden email]>
>> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>>
>> On Jan 14, 2010, at 2:41 AM, Boiteux, Benoit wrote:
>>
>>      
>>> Hi,
>>> Can someone indicate me how to change the font color of the legend
>>> text of a chaco plot?
>>>        
>> Unfortunately, it's currently a little complicated to do this.  Once
>> you have created a legend, you can set the color on all of its cached
>> labels:
>>
>> # call get_preferred_size() to force creation of the labels
>> legend.get_preferred_size()
>> # update all the labels
>> for label in legend._cached_labels:
>>    label.color = "red"
>>
>> I will also modify the legend class now to have a "text_color" trait,
>> so if you are on the SVN trunk, then you can do an update once that's
>> checked in.
>>
>> -Peter
>>
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Thu, 14 Jan 2010 11:31:13 -0600
>> From: Peter Wang<[hidden email]>
>> Subject: Re: [Enthought-Dev] chaco plot legend font
>> To: [hidden email]
>> Message-ID:<[hidden email]>
>> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>>
>> On Jan 14, 2010, at 11:15 AM, Peter Wang wrote:
>>
>>      
>>> I will also modify the legend class now to have a "text_color" trait,
>>> so if you are on the SVN trunk, then you can do an update once that's
>>> checked in.
>>>        
>> OK, I've committed a fix for this, revision r25121 in SVN.  I decided
>> to just call the trait "color" instead of "text_color".
>>
>> It's worth noting, however, that if you need to tweak the color of a
>> single label, you can still use the approach I indicated in the
>> previous email.
>>
>> -Peter
>>
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
>> End of Enthought-Dev Digest, Vol 65, Issue 26
>> *********************************************
>>
>>      
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>    

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev