Hello,

I'd like to set a custom style for a textctrl that includes custom tab positions.

The script below works on xp and displays custom tab positions for the textctrl, as coded.

However, the script fails to set custom tab positions on linux (fedora 5), though it does set custom text and background colours.

Does anyone know how to set custom tab positions for a textctrl on linux ?

#!/usr/bin/python

import wx


class DisFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        
        self.SetSize(wx.Size(600,400))
        self.SetTitle('Temperamental  TextCtrl  Tabs')
        
        # make a panel with a button / textctrl / listbox
        self.panel = wx.Panel(self)
        
        bs = wx.BoxSizer(wx.VERTICAL)
        
        self.button = wx.Button(self.panel, -1, 'Set Tab Positions ' +\
                'to  [ 100, 300, 390, 800 ]  and then Add Text')
        self.button.Bind(wx.EVT_BUTTON, self.ButtonClicked)
        bs.Add(self.button,0,wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND,30)
        
        bs.AddSpacer(wx.Size(10,10))
        
        self.editor = wx.TextCtrl(self.panel, style=wx.TE_MULTILINE|\
        wx.TE_PROCESS_TAB|wx.TE_RICH)
        bs.Add(self.editor,1,wx.EXPAND|wx.LEFT|wx.RIGHT,30)
        
        bs.AddSpacer(wx.Size(10,30))
        
        self.lb = wx.ListBox(self.panel, wx.NewId(), style=wx.LB_SINGLE)
        bs.Add(self.lb,2,wx.EXPAND|wx.BOTTOM|wx.LEFT|wx.RIGHT,30)
        
        self.panel.SetSizer(bs)
        
        
    def ButtonClicked(self, event):

        # change the default style of the textctrl,
        # set a few tab positions and then add
        # some text
        dastyle = wx.TextAttr()
        dastyle.SetTabs([100, 300, 390, 800])
        dastyle.SetBackgroundColour(wx.Colour(0,0,255))
        dastyle.SetTextColour(wx.Colour(255,255,255))
        self.editor.SetDefaultStyle(dastyle)
        
        # add text to the textctrl
        self.editor.Clear()
        self.editor.AppendText('\ttab1\ttab2\ttab3\ttab4')
        
        dastyle = wx.TextAttr()
        dastyle.SetBackgroundColour(wx.Colour(255,0,0))
        self.editor.SetDefaultStyle(dastyle)
        self.editor.AppendText('\n\n  custom tab positions ' +\
        'appear on xp - but not on linux (fc5)  ')
        
        # display textctrl tab positions
        dastyle = self.editor.GetDefaultStyle()
        self.lb.Clear()
        self.lb.Append('wx.TextCtrl.GetDefaultStyle().GetTabs()')
        self.lb.Append('')
        x = 1
        for posi in dastyle.GetTabs():
            self.lb.Append('    tab position ' + str(x) +\
            ' = ' + str(posi))
            x += 1

        event.Skip()




if __name__ == '__main__':
    app = wx.App()
    daframe = DisFrame(None)
    daframe.Show()
    app.MainLoop()

Thanks.


fedora 5 system:
wxPython Version: 2.6.3.2
wxPython Platform: wxGTK, unicode, gtk2, wx-assertions-off, SWIG-1.3.27
Python Version: 2.4.2.final

xp system:
wxPython Version: 2.7.1.3
wxPython Platform: wxMSW, unicode, wx-assertions-on, SWIG-1.3.29
Python Version: 2.4.3.final

_

Recommended Answers

All 5 Replies

Upgraded wxpython to 2.7.2.0 at the suggestion of Robin Dunn, and setting tab positions in a
textctrl on fc5 now works.

_

You are lucky getting a hold of Robin, the expert with wxPython. Did he ask you to buy his book on wxPython?

Hello Ene Uran,

No, he didn't ask me to buy his book. Robin regularly helps others on another forum, hence why I credited him with solving this problem. I posted Robin's solution on daniweb in the hope that it would help other programmers.

If I encounter another wxpython obstacle, I look forward to writing 'Solved as a result of expert advice provided by Ene Uran!'

All the best.

_

Hey thanks!
I enjoyed testing your nice code! I love to learn and really appreciate your problemsolving!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.