Re: Dynamically change font size of a TextArea

Lawrence Abbott <[email protected]> Tue, 21 Jun 2011 22:45:50 +0800
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
try
font =3D self.components.TextArea1.GetFont()

instead of
font =3D self.components.TextArea1.font

also you will need to ensure the slider output values are legitimate font s=
izes
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):
> =A0File "C:\Python25\lib\site-packages\PythonCard\widget.py", line 408, in
> _dispatch
> handler(background, aWxEvent)
> =A0File
> "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):
> =A0=A0=A0 def=A0 on_Slider1_mouseUp(self, event):
> =A0=A0=A0 =A0=A0=A0 sliderValue =3D self.components.Slider1.value
> =A0=A0=A0 =A0=A0=A0 print sliderValue
> =A0=A0=A0 =A0=A0=A0 font =3D self.components.TextArea1.font
> =A0=A0=A0 =A0=A0=A0 font.SetPointSize(sliderValue)
> =A0=A0=A0 =A0=A0=A0 self.components.TextArea1.SetFont(font)
> =A0=A0=A0 =A0=A0=A0 print self.components.TextArea1.font
>
> app =3D 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
>
> =A0 =A0 =A0 =A0 font =3D self.components.TextArea1.GetFont()
> =A0 =A0 =A0 =A0 font.SetPointSize(16)
> =A0 =A0 =A0 =A0 self.components.TextArea1.SetFont(font)
>
> Cheers,
> Lawrie
>
> On Tue, Jun 21, 2011 at 12:26 PM, Lawrence Abbott <[email protected]> wrot=
e:
>> Hi,
>>
>> self.components.TextArea1.font_size =3D 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 =3D16
>>
>> font1 =3D self.components.TextArea1.GetFont()
>> font2 =3D 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 =3D 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.=A0 It keeps sliding =
back
>>> and forth even after the mouse is released and no longer over the
>>> slider.=A0 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.=A0 It's a class.=A0 Try font._size
>>>
>>> On 6/17/2011 1:23 PM, hwg wrote:
>>>
>>> from PythonCard import model
>>> class MainWindow(model.Background):
>>> =A0=A0 def=A0 on_Slider1_mouseUp(self, event):
>>> =A0=A0=A0=A0=A0=A0 sliderValue =3D self.components.Slider1.value
>>> =A0=A0=A0=A0=A0=A0=A0self.components.TextArea1.font['size'] =3D sliderV=
alue
>>>
>>> app =3D 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
>
>

---------------------------------------------------------------------------=
---
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