~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/prefdlg.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
"""
17
17
 
18
18
__author__ = "Cody Precord <cprecord@editra.org>"
19
 
__svnid__ = "$Id: prefdlg.py 63591 2010-03-01 00:12:30Z CJP $"
20
 
__revision__ = "$Revision: 63591 $"
 
19
__svnid__ = "$Id: prefdlg.py 67857 2011-06-05 00:16:24Z CJP $"
 
20
__revision__ = "$Revision: 67857 $"
21
21
 
22
22
#----------------------------------------------------------------------------#
23
 
# Dependancies
 
23
# Dependencies
24
24
import wx
25
25
import wx.lib.mixins.listctrl as listmix
26
26
import locale
39
39
import util
40
40
import syntax.syntax as syntax
41
41
import ed_msg
 
42
import ed_txt
42
43
import eclib
43
44
import extern.stcspellcheck as stcspellcheck
44
45
 
73
74
#----------------------------------------------------------------------------#
74
75
 
75
76
class PreferencesPanelBase(object):
 
77
    """Base mixin class for preference panels"""
76
78
    def __init__(self):
77
 
        object.__init__(self)
 
79
        super(PreferencesPanelBase, self).__init__()
78
80
 
79
81
        # Attributes
80
82
        self._layout_done = False
102
104
        @param id_: The id of this window
103
105
 
104
106
        """
105
 
        wx.Frame.__init__(self, parent, id_,
106
 
                          _("Preferences - Editra"), style=style)
 
107
        super(PreferencesDialog, self).__init__(parent, id_,
 
108
                                                _("Preferences - Editra"),
 
109
                                                style=style)
107
110
        util.SetWindowIcon(self)
108
111
 
109
112
        # Extra Styles
155
158
class PrefTools(eclib.SegmentBook):
156
159
    """Main sections of the configuration pages
157
160
    @note: implements the top level book control for the prefdlg
158
 
    @todo: when using BK_BUTTONBAR style so that the icons have text
159
 
           under them the icons get scaled to larger size on the Mac
160
 
           causing them to look poor.
161
161
 
162
162
    """
163
163
    GENERAL_PG = 0
170
170
        """Initializes the main book control of the preferences dialog
171
171
        @summary: Creates the top level notebook control for the prefdlg
172
172
                  a toolbar is used for changing pages.
173
 
        @todo: There is some nasty dithering/icon rescaling happening on
174
 
               osx. need to se why this is.
175
 
        @note: Look into wxtoolbook source and see why images cant be changed
176
 
               after they have been set. Because of this when the theme is
177
 
               changed the toolbook icons cannont be updated instantly.
178
173
 
179
174
        """
180
 
        eclib.SegmentBook.__init__(self, parent, wx.ID_ANY,
181
 
                                       style=eclib.SEGBOOK_STYLE_LABELS|\
182
 
                                             eclib.SEGBOOK_STYLE_NO_DIVIDERS)
 
175
        super(PrefTools, self).__init__(parent, wx.ID_ANY,
 
176
                                        style=eclib.SEGBOOK_STYLE_LABELS|\
 
177
                                              eclib.SEGBOOK_STYLE_NO_DIVIDERS)
183
178
 
184
179
        # Attributes
185
180
        self._imglst = list()
199
194
        # Event Handlers
200
195
        self.Bind(eclib.EVT_SB_PAGE_CHANGED, self.OnPageChanged)
201
196
        self.Bind(eclib.EVT_SB_PAGE_CHANGING, self.OnPageChanging)
 
197
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)
202
198
 
203
199
        # Message Handlers
204
200
        ed_msg.Subscribe(self.OnThemeChange, ed_msg.EDMSG_THEME_CHANGED)
205
201
 
206
 
    def __del__(self):
207
 
        ed_msg.Unsubscribe(self.OnThemeChange)
 
202
    def OnDestroy(self, evt):
 
203
        if evt.GetId() == self.GetId():
 
204
            ed_msg.Unsubscribe(self.OnThemeChange)
 
205
        evt.Skip()
208
206
 
209
207
    def __InitImgList(self):
210
208
        """Setup the image list for the SegmentBook"""
370
368
class GeneralStartupPanel(wx.Panel):
371
369
    """General Startup Settings"""
372
370
    def __init__(self, parent):
373
 
        wx.Panel.__init__(self, parent)
 
371
        super(GeneralStartupPanel, self).__init__(parent)
374
372
 
375
373
        # Attributes
376
374
 
445
443
#-----------------------------------------------------------------------------#
446
444
 
447
445
class GeneralFilePanel(wx.Panel):
 
446
    """Configuration panel for general file settings"""
448
447
    def __init__(self, parent):
449
 
        wx.Panel.__init__(self, parent)
 
448
        super(GeneralFilePanel, self).__init__(parent)
450
449
 
451
450
        # Attributes
452
451
        
481
480
        # Encoding options
482
481
        d_encoding = Profile_Get('ENCODING',
483
482
                                 'str',
484
 
                                 default=locale.getpreferredencoding())
 
483
                                 default=ed_txt.DEFAULT_ENCODING)
485
484
        if d_encoding is None:
486
485
            d_encoding = 'utf-8'
487
486
            Profile_Set('ENCODING', d_encoding)
637
636
        sprefs = Profile_Get('SPELLCHECK', default=dict())
638
637
        cpath = sprefs.get('epath', u'')
639
638
        if path != cpath:
640
 
            ok = stcspellcheck.STCSpellCheck.reloadEnchant(path)
 
639
            try:
 
640
                ok = stcspellcheck.STCSpellCheck.reloadEnchant(path)
 
641
            except OSError:
 
642
                ok = False
 
643
 
641
644
            if ok:
642
645
                # Reload was successful
643
646
                sprefs['epath'] = path
702
705
        @param parent: Parent window of this panel
703
706
 
704
707
        """
705
 
        wx.Panel.__init__(self, parent)
 
708
        super(DocGenPanel, self).__init__(parent)
706
709
 
707
710
        # Layout
708
711
        self._DoLayout()
770
773
        ww_cb = wx.CheckBox(self, ed_glob.ID_WORD_WRAP, _("Word Wrap"))
771
774
        ww_cb.SetValue(Profile_Get('WRAP'))
772
775
        ww_cb.SetToolTipString(_("Turn off for better performance"))
 
776
        vs_cb = wx.CheckBox(self, ed_glob.ID_PREF_VIRT_SPACE,
 
777
                            _("View Virtual Space After Last Line"))
 
778
        vs_cb.SetValue(Profile_Get('VIEWVERTSPACE', default=False))
 
779
        vs_cb.SetToolTipString(_("Adds extra scrolling room after last line"))
773
780
 
774
781
        # Font Options
775
782
        fnt = Profile_Get('FONT1', 'font', wx.Font(10, wx.FONTFAMILY_MODERN,
785
792
                                  "regions when syntax highlighting is in use"))
786
793
 
787
794
        # Layout
788
 
        sizer = wx.FlexGridSizer(19, 2, 5, 5)
 
795
        sizer = wx.FlexGridSizer(20, 2, 5, 5)
789
796
        sizer.AddGrowableCol(1, 1)
790
797
        sizer.AddMany([((10, 10), 0), ((10, 10), 0),
791
798
                       (wx.StaticText(self, label=_("Format") + u": "),
802
809
                       ((5, 5), 0), (sln_cb, 0),
803
810
                       ((5, 5), 0), (sws_cb, 0),
804
811
                       ((5, 5), 0), (ww_cb, 0),
 
812
                       ((5, 5), 0), (vs_cb, 0),
805
813
                       ((10, 10), 0), ((10, 10), 0),
806
814
                       (wx.StaticText(self, label=_("Primary Font") + u": "),
807
815
                        0, wx.ALIGN_CENTER_VERTICAL),
844
852
        """
845
853
        # XXX Why when running on windows this and other imports randomly
846
854
        #     become None. I have been unable to reproduce this behavior myself
847
 
        #     but have recieved enough error reports about it to beleive it.
 
855
        #     but have received enough error reports about it to believe it.
848
856
        #     If they were actually NoneTypes the dialog would not be able to
849
857
        #     be shown so this is very strange!!
850
858
        global ed_glob
857
865
                    ed_glob.ID_PREF_AALIAS, ed_glob.ID_SHOW_EOL,
858
866
                    ed_glob.ID_SHOW_LN, ed_glob.ID_SHOW_WS,
859
867
                    ed_glob.ID_WORD_WRAP, ed_glob.ID_PREF_AALIAS,
860
 
                    ed_glob.ID_PREF_INDENTW, ed_glob.ID_PREF_AUTOTRIM ]:
 
868
                    ed_glob.ID_PREF_INDENTW, ed_glob.ID_PREF_AUTOTRIM,
 
869
                    ed_glob.ID_PREF_VIRT_SPACE ]:
861
870
 
862
871
            e_value = evt.GetEventObject().GetValue()
863
872
            if e_id == ed_glob.ID_EOL_MODE:
865
874
 
866
875
            Profile_Set(ed_glob.ID_2_PROF[e_id], e_value)
867
876
 
868
 
            # Do updates for everything but text encoding
 
877
            # Do updates for everything but autotrim whitespace
869
878
            if e_id not in (ed_glob.ID_PREF_AUTOTRIM, ):
870
879
                wx.CallLater(25, DoUpdates)
871
880
        else:
884
893
        @param parent: Parent window of this panel
885
894
 
886
895
        """
887
 
        wx.Panel.__init__(self, parent)
 
896
        super(DocCodePanel, self).__init__(parent)
888
897
 
889
898
        # Layout
890
899
        self._DoLayout()
921
930
        edge_cb = wx.CheckBox(self, ed_glob.ID_SHOW_EDGE, _("Edge Guide"))
922
931
        edge_cb.SetValue(Profile_Get('SHOW_EDGE'))
923
932
        edge_sp = wx.SpinCtrl(self, ed_glob.ID_PREF_EDGE,
924
 
                              Profile_Get('EDGE', 'str'), min=0, max=120)
 
933
                              Profile_Get('EDGE', 'str'), min=0, max=160)
925
934
        edge_sp.SetToolTipString(_("Guide Column"))
926
935
        edge_col = wx.BoxSizer(wx.HORIZONTAL)
927
936
        edge_col.AddMany([(edge_cb, 0, wx.ALIGN_CENTER_VERTICAL),
1051
1060
        @param parent: parent window of this panel
1052
1061
 
1053
1062
        """
1054
 
        wx.Panel.__init__(self, parent)
 
1063
        super(DocSyntaxPanel, self).__init__(parent)
1055
1064
 
1056
1065
        # Attributes
1057
1066
        self._elist = ExtListCtrl(self)
1076
1085
        # Syntax Settings
1077
1086
        syn_cb = wx.CheckBox(self, ed_glob.ID_SYNTAX, _("Syntax Highlighting"))
1078
1087
        syn_cb.SetValue(Profile_Get('SYNTAX'))
 
1088
        ss_lst = util.GetResourceFiles(u'styles', get_all=True)
 
1089
        ss_lst = [sheet for sheet in ss_lst if not sheet.startswith('.')]
1079
1090
        syntheme = ExChoice(self, ed_glob.ID_PREF_SYNTHEME,
1080
 
                            choices=util.GetResourceFiles(u'styles',
1081
 
                                                          get_all=True),
 
1091
                            choices=sorted(ss_lst),
1082
1092
                            default=Profile_Get('SYNTHEME', 'str'))
1083
1093
        line = wx.StaticLine(self, size=(-1, 2))
1084
1094
        lsizer = wx.BoxSizer(wx.VERTICAL)
1355
1365
class NetConfigPage(wx.Panel):
1356
1366
    """Configuration page for network and proxy settings"""
1357
1367
    def __init__(self, parent):
1358
 
        wx.Panel.__init__(self, parent)
 
1368
        super(NetConfigPage, self).__init__(parent)
1359
1369
 
1360
1370
        # Layout
1361
1371
        self._DoLayout()
1484
1494
        @param parent: Parent window of this panel
1485
1495
 
1486
1496
        """
1487
 
        wx.Panel.__init__(self, parent)
 
1497
        super(UpdatePage, self).__init__(parent)
1488
1498
 
1489
1499
        # Layout
1490
1500
        self._DoLayout()
1508
1518
        upd_box = wx.StaticBox(self, label=_("Latest Version"))
1509
1519
        upd_bsz = wx.StaticBoxSizer(upd_box, wx.HORIZONTAL)
1510
1520
        upd_bsz.SetMinSize(wx.Size(150, 40))
1511
 
        upd_bsz.Add(wx.StaticText(self, ID_UPDATE_MSG, _(e_update.GetStatus())),
 
1521
        upd_bsz.Add(wx.StaticText(self, ID_UPDATE_MSG, _("Status Unknown")),
1512
1522
                    0, wx.ALIGN_CENTER_HORIZONTAL)
1513
1523
        upd_bsz.Layout()
1514
1524
 
1549
1559
        if e_id == ID_CHECK_UPDATE:
1550
1560
            util.Log("[prefdlg][evt] Update Page: Check Update Clicked")
1551
1561
            e_obj.Disable()
 
1562
            self.FindWindowById(ID_UPDATE_MSG).SetLabel(_("Checking..."))
1552
1563
            prog_bar = self.FindWindowById(ed_glob.ID_PREF_UPDATE_BAR)
1553
1564
            # Note this function returns right away but its result is
1554
1565
            # handled on a separate thread. This window is then notified
1582
1593
        nbevt = wx.NotebookEvent(wx.wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED,
1583
1594
                                 0, curr_pg, curr_pg)
1584
1595
        wx.PostEvent(self.GetParent(), nbevt)
 
1596
        gauge = self.FindWindowById(ed_glob.ID_PREF_UPDATE_BAR)
 
1597
        if gauge:
 
1598
            gauge.Stop()
 
1599
            gauge.SetValue(100)
1585
1600
        self.Refresh()
1586
1601
 
1587
1602
#-----------------------------------------------------------------------------#
1599
1614
        @param parent: Parent window of this panel
1600
1615
 
1601
1616
        """
1602
 
        wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
 
1617
        super(AdvancedPanel, self).__init__(parent, style=wx.BORDER_SUNKEN)
1603
1618
 
1604
1619
        # Layout
1605
1620
        self._layout_done = False
1636
1651
KEYS = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1637
1652
        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1638
1653
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '+', '/', ',',
1639
 
        '.', '[', ']', '{', '}', ':', 'Left', 'Right', 'Down', 'Up', 'Home',
1640
 
        'End', 'Enter', 'Tab']
1641
 
KEYS.extend(["F" + str(x) for x in range(1, 13)])
 
1654
        '.', '[', ']', '{', '}', '>', '<', ':', '|', 'Left', 'Right', 'Down',
 
1655
        'Up', 'Home', 'End', 'Enter', 'Tab', 'Space', '"', "'"]
 
1656
KEYS.extend(["F" + str(x) for x in range(1, 13)]) # Add function keys
1642
1657
 
1643
1658
if wx.Platform == '__WXMSW__':
1644
1659
    KEYS.remove('Tab')
1654
1669
    """Keybinding configration options"""
1655
1670
    def __init__(self, parent):
1656
1671
        """Create the panel"""
1657
 
        wx.Panel.__init__(self, parent)
 
1672
        super(KeyBindingPanel, self).__init__(parent)
1658
1673
 
1659
1674
        # Attributes
 
1675
        self._dirty = False
1660
1676
        self.menub = wx.GetApp().GetActiveWindow().GetMenuBar()
1661
1677
        self.binder = self.menub.GetKeyBinder()
1662
1678
        self.menumap = dict()
1676
1692
        self.Bind(wx.EVT_BUTTON, self.OnButton)
1677
1693
        self.Bind(wx.EVT_CHOICE, self.OnChoice)
1678
1694
        self.Bind(wx.EVT_LISTBOX, self.OnListBox)
 
1695
        self.Bind(wx.EVT_UPDATE_UI,
 
1696
                  lambda evt: evt.Enable(self.Dirty),
 
1697
                  id=wx.ID_APPLY)
1679
1698
 
1680
1699
    def _DoLayout(self):
1681
1700
        """Layout the controls"""
1845
1864
 
1846
1865
        self._UpdateBinding()
1847
1866
 
 
1867
    #---- Properties ----#
 
1868
 
 
1869
    Dirty = property(lambda self: self._dirty,
 
1870
                     lambda self, bDirty: setattr(self, '_dirty', bDirty))
 
1871
 
1848
1872
    def ClearKeyView(self):
1849
1873
        """Clear all selections in the keybinding controls"""
1850
1874
        self.FindWindowById(ID_MOD1).SetStringSelection('')
1979
2003
                mod2.SetItems(tmods)
1980
2004
                mod2.SetStringSelection('')
1981
2005
            self._UpdateBinding()
 
2006
            self.Dirty = True
1982
2007
        elif e_id in [ID_MOD2, ID_KEYS]:
1983
2008
            self._UpdateBinding()
 
2009
            self.Dirty = True
1984
2010
        else:
1985
2011
            evt.Skip()
1986
2012
 
2118
2144
        if len(choices) and isinstance(choices[0], int):
2119
2145
            choices = [ unicode(choice) for choice in choices ]
2120
2146
 
2121
 
        wx.Choice.__init__(self, parent, cid, choices=choices)
 
2147
        super(ExChoice, self).__init__(parent, cid, choices=choices)
2122
2148
 
2123
2149
        if default != None and isinstance(default, basestring):
2124
2150
            self.SetStringSelection(default)