Re: Dynamically change font size of a TextArea

John Henry <[email protected]> Tue, 21 Jun 2011 09:46:02 -0700
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============1504719608406999785==
Content-Type: multipart/alternative;
	boundary="------------010507090101090303070905"

This is a multi-part message in MIME format.
--------------010507090101090303070905
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

You need to post the rsrc file as well.  Then others can try running the 
code on their side.

On 6/21/2011 7:23 AM, hwg 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 <http://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] <mailto:[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]
>     <mailto:[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] <mailto:[email protected]>"
>     <[email protected] <mailto:[email protected]>>
>     >> To: hwg <[email protected] <mailto:[email protected]>>
>     >> Cc: "[email protected]
>     <mailto:[email protected]>"
>     >> <[email protected]
>     <mailto:[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]
>     <mailto:[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


--------------010507090101090303070905
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <tt>You need to post the rsrc file as well.&nbsp; Then others can try
      running the code on their side.</tt><br>
    <br>
    On 6/21/2011 7:23 AM, hwg wrote:
    <blockquote cite="mid:[email protected]"
      type="cite">
      <div style="color: rgb(0, 0, 0); background-color: rgb(255, 255,
        255); font-family: Courier
        New,courier,monaco,monospace,sans-serif; font-size: 10pt;">
        <div>I tried both of the methods below:</div>
        <div><br>
        </div>
        <div>I get the following error:</div>
        <div style="font-family: Courier
          New,courier,monaco,monospace,sans-serif;"><br>
        </div>
        <div><span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">Traceback (most
            recent call last):</span><br style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;File
            "C:\Python25\lib\site-packages\PythonCard\widget.py", line
            408, in _dispatch</span><br style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">handler(background,
            aWxEvent)</span><br style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;File
            "C:\Users\wsande\Documents\Warren\PythonScripts\PC_slider_text\pc_slider_text.py",
            line 11, in on_Slider1_mouseUp</span><br style="font-family:
            Courier New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">font.SetPointSize(sliderValue)</span><br
            style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">AttributeError:
            'Font' object has no attribute 'SetPointSize'</span><br>
        </div>
        <div><br>
        </div>
        <div>Here's the complete code:</div>
        <div><br>
        </div>
        <div style="font-family: Courier
          New,courier,monaco,monospace,sans-serif;"># <a
            moz-do-not-send="true" target="_blank"
            href="http://pc_slider_text.py/"><span class="yshortcuts"
              id="lw_1308666021_0">pc_slider_text.py</span></a><br>
          # try to change the size of text font in a test box using a
          slider<br>
          <br>
        </div>
        <div><span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">from wx import *</span><br
            style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">from PythonCard
            import model</span><br style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">class
            MainWindow(model.Background):</span><br style="font-family:
            Courier New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; def&nbsp;
            on_Slider1_mouseUp(self, event):</span><br
            style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
            sliderValue = self.components.Slider1.value</span><br
            style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print
            sliderValue</span><br style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; font =
            self.components.TextArea1.font</span><br style="font-family:
            Courier New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
            font.SetPointSize(sliderValue)</span><br style="font-family:
            Courier New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
            self.components.TextArea1.SetFont(font)</span><br
            style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print
            self.components.TextArea1.font</span><br style="font-family:
            Courier New,courier,monaco,monospace,sans-serif;">
          <span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;"></span></div>
        <div><span style="font-family: Courier
            New,courier,monaco,monospace,sans-serif;"><br>
          </span></div>
        <span style="font-family: Courier
          New,courier,monaco,monospace,sans-serif;">a</span><span
          style="font-family: Courier
          New,courier,monaco,monospace,sans-serif;">pp =
          model.Application(MainWindow)</span><br style="font-family:
          Courier New,courier,monaco,monospace,sans-serif;">
        <span style="font-family: Courier
          New,courier,monaco,monospace,sans-serif;">app.MainLoop()</span>
        <div><br>
          <blockquote style="border-left: 2px solid rgb(16, 16, 255);
            margin-left: 5px; padding-left: 5px;">
            <div style="font-family: Courier
              New,courier,monaco,monospace,sans-serif; font-size: 10pt;">
              <div style="font-family: times new roman,new
                york,times,serif; font-size: 12pt;"><font size="2"
                  face="Arial">
                  <hr size="1"><b><span style="font-weight: bold;">From:</span></b>
                  Lawrence Abbott <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a><br>
                  <b><span style="font-weight: bold;">To:</span></b> hwg
                  <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a><br>
                  <b><span style="font-weight: bold;">Sent:</span></b>
                  Monday, June 20, 2011 10:37 PM<br>
                  <b><span style="font-weight: bold;">Subject:</span></b>
                  Re: [Pythoncard-users] Dynamically change font size of
                  a TextArea<br>
                </font><br>
                A slightly cleaner way<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; font = self.components.TextArea1.GetFont()<br>
                &nbsp; &nbsp; &nbsp; &nbsp; font.SetPointSize(16)<br>
                &nbsp; &nbsp; &nbsp; &nbsp; self.components.TextArea1.SetFont(font)<br>
                <br>
                Cheers,<br>
                Lawrie<br>
                <br>
                On Tue, Jun 21, 2011 at 12:26 PM, Lawrence Abbott &lt;<a
                  moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>&gt;
                wrote:<br>
                &gt; Hi,<br>
                &gt;<br>
                &gt; self.components.TextArea1.font_size = sliderValue<br>
                &gt;<br>
                &gt; doesnt work for me<br>
                &gt;<br>
                &gt; print self.components.TextArea1.font.size<br>
                &gt;<br>
                &gt; gives a dictionary of font attributes, but I can't
                get them to update either<br>
                &gt;<br>
                &gt; import wx<br>
                &gt;<br>
                &gt; font_size =16<br>
                &gt;<br>
                &gt; font1 = self.components.TextArea1.GetFont()<br>
                &gt; font2 = wx.Font(font_size, font1.Family,
                font1.Style, font1.Weight)<br>
                &gt; self.components.TextArea1.SetFont( font2 )<br>
                &gt;<br>
                &gt; seems to work<br>
                &gt;<br>
                &gt; HTH,<br>
                &gt; Lawrie<br>
                &gt;<br>
                &gt; On Mon, Jun 20, 2011 at 2:27 AM, hwg &lt;<a
                  moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>&gt;
                wrote:<br>
                &gt;&gt; I tried:<br>
                &gt;&gt;<br>
                &gt;&gt; self.components.TextArea1.font_size =
                sliderValue<br>
                &gt;&gt; It doesn't throw an exception, but it doesn't
                change the font size, either.<br>
                &gt;&gt; Also, oddly, the slider never seems to lose
                focus.&nbsp; It keeps sliding back<br>
                &gt;&gt; and forth even after the mouse is released and
                no longer over the slider.&nbsp; I<br>
                &gt;&gt; can't get focus on the TextArea.<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt; - hwg<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt; ________________________________<br>
                &gt;&gt; From: "<a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>"
                &lt;<a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>&gt;<br>
                &gt;&gt; To: hwg &lt;<a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>&gt;<br>
                &gt;&gt; Cc: "<a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>"<br>
                &gt;&gt; &lt;<a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a>&gt;<br>
                &gt;&gt; Sent: Saturday, June 18, 2011 11:45 PM<br>
                &gt;&gt; Subject: Re: [Pythoncard-users] Dynamically
                change font size of a TextArea<br>
                &gt;&gt;<br>
                &gt;&gt; font is not a dictionary.&nbsp; It's a class.&nbsp; Try
                font._size<br>
                &gt;&gt;<br>
                &gt;&gt; On 6/17/2011 1:23 PM, hwg wrote:<br>
                &gt;&gt;<br>
                &gt;&gt; from PythonCard import model<br>
                &gt;&gt; class MainWindow(model.Background):<br>
                &gt;&gt; &nbsp;&nbsp; def&nbsp; on_Slider1_mouseUp(self, event):<br>
                &gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sliderValue =
                self.components.Slider1.value<br>
                &gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.components.TextArea1.font['size'] =
                sliderValue<br>
                &gt;&gt;<br>
                &gt;&gt; app = model.Application(MainWindow)<br>
                &gt;&gt; app.MainLoop()<br>
                &gt;&gt;<br>
                &gt;&gt; --<br>
                &gt;&gt; Kim Cheung<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt;
------------------------------------------------------------------------------<br>
                &gt;&gt; EditLive Enterprise is the world's most
                technically advanced content<br>
                &gt;&gt; authoring tool. Experience the power of Track
                Changes, Inline Image<br>
                &gt;&gt; Editing and ensure content is compliant with
                Accessibility Checking.<br>
                &gt;&gt; <a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/ephox-dev2dev">http://p.sf.net/sfu/ephox-dev2dev</a><br>
                &gt;&gt; _______________________________________________<br>
                &gt;&gt; Pythoncard-users mailing list<br>
                &gt;&gt; <a moz-do-not-send="true"
                  ymailto="mailto:[email protected]"
                  href="mailto:[email protected]">[email protected]</a><br>
                &gt;&gt; <a moz-do-not-send="true"
                  href="https://lists.sourceforge.net/lists/listinfo/pythoncard-users"
                  target="_blank">https://lists.sourceforge.net/lists/listinfo/pythoncard-users</a><br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;<br>
                <br>
                <br>
              </div>
            </div>
          </blockquote>
        </div>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
------------------------------------------------------------------------------
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.
<a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/ephox-dev2dev">http://p.sf.net/sfu/ephox-dev2dev</a></pre>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Pythoncard-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/pythoncard-users">https://lists.sourceforge.net/lists/listinfo/pythoncard-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>

--------------010507090101090303070905--


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

--===============1504719608406999785==--