wx.TextCtrl goes ape.

Ok, so I’ve been experimenting alot, and playing with code.

I thought it would be a good idea to have a “sample” TextCtrl

that would have some “Sample Text” in it, and the user

could pick the bg color, fg color, and font and the

TextCtrl would update.

If I set the color before the TextCtrl is created everything is

peachy.

But it I try and SetBackgroundColor, the TextCtrl line

with text changes, the background turns purple, the text

turns black, and the read of the lines in TextCtrl turn black

no matter what color I choose.

The foreground color doesn’t seem to change at all.

Show(False) / setcolor / Show(True) doesn’t work.

Refresh() doesn’t work either. Update()

I realize I need to re-draw the TextCtrl (I think.)

It has be to possible the Csel dialog changes the color

of the butten that triggers it. The ticker demo you can change

the colors / fonts and what not dynamically.

Just thought it would be neat to do.

Thanks,

Steve

Sample code, please.

Is it possible the TextCtrl is selecting the entire text, so what
you're seeing is plain highlighting?

Josh

···

--
Josh English
Joshua.R.English@gmail.com
http://joshenglish.livejournal.com

Steve Freedenburg wrote:

Ok, so I've been experimenting alot, and playing with code.
I thought it would be a good idea to have a "sample" TextCtrl
that would have some "Sample Text" in it, and the user
could pick the bg color, fg color, and font and the
TextCtrl would update.
If I set the color before the TextCtrl is created everything is
peachy.

How do you set the colors if the TextCtrl hasn't been created yet? Or do you set it on the parent?

But it I try and SetBackgroundColor, the TextCtrl line
with text changes, the background turns purple, the text
turns black, and the read of the lines in TextCtrl turn black
no matter what color I choose.
The foreground color doesn't seem to change at all.
Show(False) / setcolor / Show(True) doesn't work.
Refresh() doesn't work either. Update()

Please make a small runnable sample that shows what you are trying to do.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Josh, I'm not sure... but the code below emulates my result. I'm pretty
sure the code is "wrong" to do what I'm trying to do. I'm trying to set
colors in real time, so "show" the user what his color choices / font would
look like.

Robin, I'm going to try real hard to sound like I know what I'm doing.
But I don't actually set any colors initially. The standard black text
on white background, with the system font is what I use as the "generic"
settings.

<CODE>
import wx

class TCFrame(wx.Frame):
        def __init__(self, parent, id, title):
            Frame = wx.Frame.__init__(self, parent, id, title)

            TCPanel = wx.Panel(self, wx.ID_ANY)
            self.TC = wx.TextCtrl(TCPanel, style=wx.TE_MULTILINE)
            BGTC = wx.Button(TCPanel, wx.ID_ANY, 'Background Color')
            Box = wx.BoxSizer(wx.VERTICAL)
            Box.Add(self.TC, 4, wx.EXPAND)
            Box.Add(BGTC, 1, wx.EXPAND)
            TCPanel.SetSizer(Box)

            self.Bind(wx.EVT_BUTTON, self.BGEvent, BGTC)

        def BGEvent(self, event):
            dlg = wx.ColourDialog(self)
            if dlg.ShowModal() == wx.ID_OK:
                BGColorData = dlg.GetColourData()
                BGColor = str(BGColorData.GetColour().Get())

            self.TC.SetBackgroundColour(BGColor)
            self.TC.WriteText('Sample Text')
            dlg.Destroy()
            event.Skip()

            class TCApp(wx.App):
    def OnInit(self):
        Frame = TCFrame(None, -1, 'TC Example')
        Frame.Show(True)
        return True

App = TCApp()
App.MainLoop()

</CODE>

···

----- Original Message ----- From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Monday, 04 August, 2008 14:35
Subject: Re: [wxpython-users] wx.TextCtrl goes ape.

Steve Freedenburg wrote:

Ok, so I've been experimenting alot, and playing with code.
I thought it would be a good idea to have a "sample" TextCtrl
that would have some "Sample Text" in it, and the user
could pick the bg color, fg color, and font and the
TextCtrl would update.
If I set the color before the TextCtrl is created everything is
peachy.

How do you set the colors if the TextCtrl hasn't been created yet? Or do you set it on the parent?

But it I try and SetBackgroundColor, the TextCtrl line
with text changes, the background turns purple, the text
turns black, and the read of the lines in TextCtrl turn black
no matter what color I choose.
The foreground color doesn't seem to change at all.
Show(False) / setcolor / Show(True) doesn't work.
Refresh() doesn't work either. Update()

Please make a small runnable sample that shows what you are trying to do.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Something strange going on with the wx.ColourDialog.

change

BGColor = str(BGColorData.GetColour().Get())

to

BGColor = BGColorData.GetColour()

and it works on my machine.

You may also want to check out wx.lib.colourselect for this problem,
or teh built in function wxGetColourFromUser

···

On Mon, Aug 4, 2008 at 7:40 PM, Steve Freedenburg <stevefreedenburg@charter.net> wrote:

--
Josh English
Joshua.R.English@gmail.com
http://joshenglish.livejournal.com

I had to play with this, because I might be able to use it in one of
my own programs. In fact, I use something very similar in my program

class TCFrame(wx.Frame):
      def __init__(self, parent, id, title):
            Frame = wx.Frame.__init__(self, parent, id, title)

            TCPanel = wx.Panel(self, wx.ID_ANY)
            self.TC = wx.TextCtrl(TCPanel, style=wx.TE_MULTILINE)
            BGTC = wx.Button(TCPanel, wx.ID_ANY, 'Background Color',
name="SetBackgroundColour")
            FGTC = wx.Button(TCPanel, wx.ID_ANY, 'Foreground Color',
name="SetForegroundColour")
            Box = wx.BoxSizer(wx.VERTICAL)
            Box.Add(self.TC, 4, wx.EXPAND)
            Box.Add(FGTC, 1, wx.EXPAND)
            Box.Add(BGTC, 1, wx.EXPAND)
            TCPanel.SetSizer(Box)

            self.Bind(wx.EVT_BUTTON, self.ColorEvent, BGTC)
            self.Bind(wx.EVT_BUTTON, self.ColorEvent, FGTC)

      def ColorEvent(self,evt):
            func = evt.GetEventObject().Name
            col = wx.GetColourFromUser()
            if col.IsOk:
                  f = getattr(self.TC,func)
                  f(col)
                  self.TC.Refresh()

It's probably too unconventional, using method names as button names,
but what the hey, it's a start.

···

--
Josh English
Joshua.R.English@gmail.com
http://joshenglish.livejournal.com