Re: Dynamically change font size of a TextArea

hwg <[email protected]> Tue, 21 Jun 2011 10:43:44 -0700 (PDT)
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
--0-429441989-1308678224=:55592
Content-Type: multipart/alternative; boundary="0-1412455963-1308678224=:55592"

--0-1412455963-1308678224=:55592
Content-Type: text/plain; charset=us-ascii

Lawrie,

That works.  Thanks!

I still have a weird issue where the Slider doesn't give up focus.  I start 
dragging it, and when I release it (mouseUp), the event handler fires and the 
font size changes.  But I can't enter the TextArea, and the slider still moves 
around as I move the mouse, even with no mouse buttons pressed.  I can't access 
the TextArea or the Menu, and I can't even close the PythonCard app window 
without going into the IDE and stopping the script from there.

Any idea what's causing this?

Complete code is attached.


Thanks,
hwg





________________________________
From: Lawrence Abbott <[email protected]>
To: hwg <[email protected]>
Cc: pythoncard-users <[email protected]>
Sent: Tue, June 21, 2011 7:45:50 AM
Subject: Re: [Pythoncard-users] Dynamically change font size of a TextArea

try
font = self.components.TextArea1.GetFont()

instead of
font = self.components.TextArea1.font

also you will need to ensure the slider output values are legitimate font sizes
also should be no need to import wx with SetPointSize method

Cheers,
Lawrie


On Tue, Jun 21, 2011 at 10:23 PM, hwg <[email protected]> wrote:
> I tried both of the methods below:
> I get the following error:
> Traceback (most recent call last):
>  File "C:\Python25\lib\site-packages\PythonCard\widget.py", line 408, in
> _dispatch
> handler(background, aWxEvent)
>  File
>"C:\Users\wsande\Documents\Warren\PythonScripts\PC_slider_text\pc_slider_text.py",
>,
> line 11, in on_Slider1_mouseUp
> font.SetPointSize(sliderValue)
> AttributeError: 'Font' object has no attribute 'SetPointSize'
>
> Here's the complete code:
> # pc_slider_text.py
> # try to change the size of text font in a test box using a slider
>
> from wx import *
> from PythonCard import model
> class MainWindow(model.Background):
>     def  on_Slider1_mouseUp(self, event):
>         sliderValue = self.components.Slider1.value
>         print sliderValue
>         font = self.components.TextArea1.font
>         font.SetPointSize(sliderValue)
>         self.components.TextArea1.SetFont(font)
>         print self.components.TextArea1.font
>
> app = model.Application(MainWindow)
> app.MainLoop()
>
> ________________________________
> From: Lawrence Abbott <[email protected]>
> To: hwg <[email protected]>
> Sent: Monday, June 20, 2011 10:37 PM
> Subject: Re: [Pythoncard-users] Dynamically change font size of a TextArea
>
> A slightly cleaner way
>
>         font = self.components.TextArea1.GetFont()
>         font.SetPointSize(16)
>         self.components.TextArea1.SetFont(font)
>
> Cheers,
> Lawrie
>
> On Tue, Jun 21, 2011 at 12:26 PM, Lawrence Abbott <[email protected]> wrote:
>> Hi,
>>
>> self.components.TextArea1.font_size = sliderValue
>>
>> doesnt work for me
>>
>> print self.components.TextArea1.font.size
>>
>> gives a dictionary of font attributes, but I can't get them to update
>> either
>>
>> import wx
>>
>> font_size =16
>>
>> font1 = self.components.TextArea1.GetFont()
>> font2 = wx.Font(font_size, font1.Family, font1.Style, font1.Weight)
>> self.components.TextArea1.SetFont( font2 )
>>
>> seems to work
>>
>> HTH,
>> Lawrie
>>
>> On Mon, Jun 20, 2011 at 2:27 AM, hwg <[email protected]> wrote:
>>> I tried:
>>>
>>> self.components.TextArea1.font_size = sliderValue
>>> It doesn't throw an exception, but it doesn't change the font size,
>>> either.
>>> Also, oddly, the slider never seems to lose focus.  It keeps sliding back
>>> and forth even after the mouse is released and no longer over the
>>> slider.  I
>>> can't get focus on the TextArea.
>>>
>>>
>>> - hwg
>>>
>>>
>>> ________________________________
>>> From: "[email protected]" <[email protected]>
>>> To: hwg <[email protected]>
>>> Cc: "[email protected]"
>>> <[email protected]>
>>> Sent: Saturday, June 18, 2011 11:45 PM
>>> Subject: Re: [Pythoncard-users] Dynamically change font size of a
>>> TextArea
>>>
>>> font is not a dictionary.  It's a class.  Try font._size
>>>
>>> On 6/17/2011 1:23 PM, hwg wrote:
>>>
>>> from PythonCard import model
>>> class MainWindow(model.Background):
>>>    def  on_Slider1_mouseUp(self, event):
>>>        sliderValue = self.components.Slider1.value
>>>        self.components.TextArea1.font['size'] = sliderValue
>>>
>>> app = model.Application(MainWindow)
>>> app.MainLoop()
>>>
>>> --
>>> Kim Cheung
>>>
>>>
>>>
>>> 
>------------------------------------------------------------------------------
>>> EditLive Enterprise is the world's most technically advanced content
>>> authoring tool. Experience the power of Track Changes, Inline Image
>>> Editing and ensure content is compliant with Accessibility Checking.
>>> http://p.sf.net/sfu/ephox-dev2dev
>>> _______________________________________________
>>> Pythoncard-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>>>
>>>
>>
>
>
>
> ------------------------------------------------------------------------------
> EditLive Enterprise is the world's most technically advanced content
> authoring tool. Experience the power of Track Changes, Inline Image
> Editing and ensure content is compliant with Accessibility Checking.
> http://p.sf.net/sfu/ephox-dev2dev
> _______________________________________________
> Pythoncard-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
>

--0-1412455963-1308678224=:55592
Content-Type: text/html; charset=us-ascii

<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:10pt"><div>Lawrie,<br><br>That works.&nbsp; Thanks!<br><br>I still have a weird issue where the Slider doesn't give up focus.&nbsp; I start dragging it, and when I release it (mouseUp), the event handler fires and the font size changes.&nbsp; But I can't enter the TextArea, and the slider still moves around as I move the mouse, even with no mouse buttons pressed.&nbsp; I can't access the TextArea or the Menu, and I can't even close the PythonCard app window without going into the IDE and stopping the script from there.<br><br>Any idea what's causing this?<br><br>Complete code is attached.<br><br><br>Thanks,<br>hwg<br><br></div><
 div style="font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><br><div style="font-family:arial, helvetica,
 sans-serif;font-size:10pt"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Lawrence Abbott &lt;[email protected]&gt;<br><b><span style="font-weight: bold;">To:</span></b> hwg &lt;[email protected]&gt;<br><b><span style="font-weight: bold;">Cc:</span></b> pythoncard-users &lt;[email protected]&gt;<br><b><span style="font-weight: bold;">Sent:</span></b> Tue, June 21, 2011 7:45:50 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Pythoncard-users] Dynamically change font size of a TextArea<br></font><br>
try<br>font = self.components.TextArea1.GetFont()<br><br>instead of<br>font = self.components.TextArea1.font<br><br>also you will need to ensure the slider output values are legitimate font sizes<br>also should be no need to import wx with SetPointSize method<br><br>Cheers,<br>Lawrie<br><br><br>On Tue, Jun 21, 2011 at 10:23 PM, hwg &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt; wrote:<br>&gt; I tried both of the methods below:<br>&gt; I get the following error:<br>&gt; Traceback (most recent call last):<br>&gt; &nbsp;File "C:\Python25\lib\site-packages\PythonCard\widget.py", line 408, in<br>&gt; _dispatch<br>&gt; handler(background, aWxEvent)<br>&gt; &nbsp;File<br>&gt; "C:\Users\wsande\Documents\Warren\PythonScripts\PC_slider_text\pc_slider
 _text.py",<br>&gt; line 11, in on_Slider1_mouseUp<br>&gt; font.SetPointSize(sliderValue)<br>&gt; AttributeError: 'Font' object has no attribute
 'SetPointSize'<br>&gt;<br>&gt; Here's the complete code:<br>&gt; # <a target="_blank" href="http://pc_slider_text.py">pc_slider_text.py</a><br>&gt; # try to change the size of text font in a test box using a slider<br>&gt;<br>&gt; from wx import *<br>&gt; from PythonCard import model<br>&gt; class MainWindow(model.Background):<br>&gt; &nbsp;&nbsp;&nbsp; def&nbsp; on_Slider1_mouseUp(self, event):<br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sliderValue = self.components.Slider1.value<br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print sliderValue<br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; font = self.components.TextArea1.font<br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; font.SetPointSize(sliderValue)<br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.components.TextArea1.SetFont(font)
 <br>&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print self.components.TextArea1.font<br>&gt;<br>&gt; app = model.Application(MainWindow)<br>&gt;
 app.MainLoop()<br>&gt;<br>&gt; ________________________________<br>&gt; From: Lawrence Abbott &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt;<br>&gt; To: hwg &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt;<br>&gt; Sent: Monday, June 20, 2011 10:37 PM<br>&gt; Subject: Re: [Pythoncard-users] Dynamically change font size of a TextArea<br>&gt;<br>&gt; A slightly cleaner way<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; font = self.components.TextArea1.GetFont()<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; font.SetPointSize(16)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; self.components.TextArea1.SetFont(font)<br>&gt;<br>&gt; Cheers,<br>&gt; Lawrie<br>&gt;<br>&gt; On Tue, Jun 21, 2011 at 12:26 PM, Lawrence Abbott &l
 t;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt; wrote:<br>&gt;&gt; Hi,<br>&gt;&gt;<br>&gt;&gt;
 self.components.TextArea1.font_size = sliderValue<br>&gt;&gt;<br>&gt;&gt; doesnt work for me<br>&gt;&gt;<br>&gt;&gt; print self.components.TextArea1.font.size<br>&gt;&gt;<br>&gt;&gt; gives a dictionary of font attributes, but I can't get them to update<br>&gt;&gt; either<br>&gt;&gt;<br>&gt;&gt; import wx<br>&gt;&gt;<br>&gt;&gt; font_size =16<br>&gt;&gt;<br>&gt;&gt; font1 = self.components.TextArea1.GetFont()<br>&gt;&gt; font2 = wx.Font(font_size, font1.Family, font1.Style, font1.Weight)<br>&gt;&gt; self.components.TextArea1.SetFont( font2 )<br>&gt;&gt;<br>&gt;&gt; seems to work<br>&gt;&gt;<br>&gt;&gt; HTH,<br>&gt;&gt; Lawrie<br>&gt;&gt;<br>&gt;&gt; On Mon, Jun 20, 2011 at 2:27 AM, hwg &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt; wrote:<b
 r>&gt;&gt;&gt; I tried:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; self.components.TextArea1.font_size = sliderValue<br>&gt;&gt;&gt; It doesn't throw an exception, but it doesn't
 change the font size,<br>&gt;&gt;&gt; either.<br>&gt;&gt;&gt; Also, oddly, the slider never seems to lose focus.&nbsp; It keeps sliding back<br>&gt;&gt;&gt; and forth even after the mouse is released and no longer over the<br>&gt;&gt;&gt; slider.&nbsp; I<br>&gt;&gt;&gt; can't get focus on the TextArea.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; - hwg<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; ________________________________<br>&gt;&gt;&gt; From: "<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>" &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt;<br>&gt;&gt;&gt; To: hwg &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt;<br>&gt;&gt;&gt; Cc: "<a
  ymailto="mailto:[email protected]"
 href="mailto:[email protected]">[email protected]</a>"<br>&gt;&gt;&gt; &lt;<a ymailto="mailto:[email protected]" href="mailto:[email protected]">[email protected]</a>&gt;<br>&gt;&gt;&gt; Sent: Saturday, June 18, 2011 11:45 PM<br>&gt;&gt;&gt; Subject: Re: [Pythoncard-users] Dynamically change font size of a<br>&gt;&gt;&gt; TextArea<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; font is not a dictionary.&nbsp; It's a class.&nbsp; Try font._size<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On 6/17/2011 1:23 PM, hwg wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; from PythonCard import model<br>&gt;&gt;&gt; class MainWindow(model.Background):<br>&gt;&gt;&gt; &nbsp;&nbsp; def&nbsp; on_Slider1_mouseUp(self, event):<br>&gt;&gt;&
 gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sliderValue = self.components.Slider1.value<br>&gt;&gt;&gt;
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.components.TextArea1.font['size'] = sliderValue<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; app = model.Application(MainWindow)<br>&gt;&gt;&gt; app.MainLoop()<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; --<br>&gt;&gt;&gt; Kim Cheung<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; ------------------------------------------------------------------------------<br>&gt;&gt;&gt; EditLive Enterprise is the world's most technically advanced content<br>&gt;&gt;&gt; authoring tool. Experience the power of Track Changes, Inline Image<br>&gt;&gt;&gt; Editing and ensure content is compliant with Accessibility Checking.<br><span>&gt;&gt;&gt; <a target="_blank" href="http://p.sf.net/sfu/ephox-dev2dev">http://p.sf.net/sfu/ephox-dev2dev</a></span><br>&gt;&gt;&gt; ___
 ____________________________________________<br>&gt;&gt;&gt; Pythoncard-users mailing list<br>&gt;&gt;&gt; <a ymailto="mailto:[email protected]"
 href="mailto:[email protected]">[email protected]</a><br>&gt;&gt;&gt; <a href="https://lists.sourceforge.net/lists/listinfo/pythoncard-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/pythoncard-users</a><br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------------<br>&gt; EditLive Enterprise is the world's most technically advanced content<br>&gt; authoring tool. Experience the power of Track Changes, Inline Image<br>&gt; Editing and ensure content is compliant with Accessibility Checking.<br>&gt; <a href="http://p.sf.net/sfu/ephox-dev2dev" target="_blank">http://p.sf.net/sfu/ephox-dev2dev</a><br>&gt; __________________________________
 _____________<br>&gt; Pythoncard-users mailing list<br>&gt; <a ymailto="mailto:[email protected]"
 href="mailto:[email protected]">[email protected]</a><br>&gt; <a href="https://lists.sourceforge.net/lists/listinfo/pythoncard-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/pythoncard-users</a><br>&gt;<br>&gt;<br></div></div>



</div></body></html>
--0-1412455963-1308678224=:55592--
--0-429441989-1308678224=:55592
Content-Type: application/octet-stream; name="pc_slider_text.py"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="pc_slider_text.py"

IyBwY19zbGlkZXJfdGV4dC5weQojIHRyeSB0byBjaGFuZ2UgdGhlIHNpemUg
b2YgdGV4dCBmb250IGluIGEgdGV4dCBib3ggdXNpbmcgYSBzbGlkZXIKCmZy
b20gd3ggaW1wb3J0ICoKZnJvbSBQeXRob25DYXJkIGltcG9ydCBtb2RlbApj
bGFzcyBNYWluV2luZG93KG1vZGVsLkJhY2tncm91bmQpOgoJZGVmICBvbl9T
bGlkZXIxX21vdXNlVXAoc2VsZiwgZXZlbnQpOgoJCXNsaWRlclZhbHVlID0g
c2VsZi5jb21wb25lbnRzLlNsaWRlcjEudmFsdWUKCQlmb250ID0gc2VsZi5j
b21wb25lbnRzLlRleHRBcmVhMS5HZXRGb250KCkKCQlmb250LlNldFBvaW50
U2l6ZShzbGlkZXJWYWx1ZSkKCQlzZWxmLmNvbXBvbmVudHMuVGV4dEFyZWEx
LlNldEZvbnQoZm9udCkKCQphcHAgPSBtb2RlbC5BcHBsaWNhdGlvbihNYWlu
V2luZG93KQphcHAuTWFpbkxvb3AoKQoKCgo=

--0-429441989-1308678224=:55592
Content-Type: application/octet-stream; name="pc_slider_text.rsrc.py"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="pc_slider_text.rsrc.py"

eydhcHBsaWNhdGlvbic6eyd0eXBlJzonQXBwbGljYXRpb24nLA0KICAgICAg
ICAgICduYW1lJzonVGVtcGxhdGUnLA0KICAgICdiYWNrZ3JvdW5kcyc6IFsN
CiAgICB7J3R5cGUnOidCYWNrZ3JvdW5kJywNCiAgICAgICAgICAnbmFtZSc6
J2JnVGVtcGxhdGUnLA0KICAgICAgICAgICd0aXRsZSc6J1N0YW5kYXJkIFRl
bXBsYXRlIHdpdGggRmlsZS0+RXhpdCBtZW51JywNCiAgICAgICAgICAnc2l6
ZSc6KDQwMCwgMzAwKSwNCiAgICAgICAgICAnc3R5bGUnOlsncmVzaXplYWJs
ZSddLA0KDQogICAgICAgICdtZW51YmFyJzogeyd0eXBlJzonTWVudUJhcics
DQogICAgICAgICAnbWVudXMnOiBbDQogICAgICAgICAgICAgeyd0eXBlJzon
TWVudScsDQogICAgICAgICAgICAgJ25hbWUnOidtZW51RmlsZScsDQogICAg
ICAgICAgICAgJ2xhYmVsJzonJkZpbGUnLA0KICAgICAgICAgICAgICdpdGVt
cyc6IFsNCiAgICAgICAgICAgICAgICAgIHsndHlwZSc6J01lbnVJdGVtJywN
CiAgICAgICAgICAgICAgICAgICAnbmFtZSc6J21lbnVGaWxlRXhpdCcsDQog
ICAgICAgICAgICAgICAgICAgJ2xhYmVsJzonRSZ4aXQnLA0KICAgICAgICAg
ICAgICAgICAgICdjb21tYW5kJzonZXhpdCcsDQogICAgICAgICAgICAgICAg
ICB9LA0KICAgICAgICAgICAgICBdDQogICAgICAgICAgICAgfSwNCiAgICAg
ICAgIF0NCiAgICAgfSwNCiAgICAgICAgICdjb21wb25lbnRzJzogWw0KDQp7
J3R5cGUnOidTbGlkZXInLCANCiAgICAnbmFtZSc6J1NsaWRlcjEnLCANCiAg
ICAncG9zaXRpb24nOig1OSwgMTczKSwgDQogICAgJ3NpemUnOig5OCwgMzEp
LCANCiAgICAnbGFiZWxzJzpGYWxzZSwgDQogICAgJ2xheW91dCc6J2hvcml6
b250YWwnLCANCiAgICAnbWF4Jzo1MCwgDQogICAgJ21pbic6NCwgDQogICAg
J3RpY2tGcmVxdWVuY3knOjAsIA0KICAgICd0aWNrcyc6RmFsc2UsIA0KICAg
ICd2YWx1ZSc6NCwgDQogICAgfSwNCg0Keyd0eXBlJzonVGV4dEFyZWEnLCAN
CiAgICAnbmFtZSc6J1RleHRBcmVhMScsIA0KICAgICdwb3NpdGlvbic6KDE5
LCAyMSksIA0KICAgICdzaXplJzooMjY1LCAxMTQpLCANCiAgICAndGV4dCc6
dSdUZXh0QXJlYTEnLCANCiAgICB9LA0KDQpdICMgZW5kIGNvbXBvbmVudHMN
Cn0gIyBlbmQgYmFja2dyb3VuZA0KXSAjIGVuZCBiYWNrZ3JvdW5kcw0KfSB9
DQo=

--0-429441989-1308678224=:55592
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
--0-429441989-1308678224=:55592
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Pythoncard-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pythoncard-users

--0-429441989-1308678224=:55592--