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 $"
22
22
#----------------------------------------------------------------------------#
25
25
import wx.lib.mixins.listctrl as listmix
73
74
#----------------------------------------------------------------------------#
75
76
class PreferencesPanelBase(object):
77
"""Base mixin class for preference panels"""
76
78
def __init__(self):
79
super(PreferencesPanelBase, self).__init__()
80
82
self._layout_done = False
102
104
@param id_: The id of this window
105
wx.Frame.__init__(self, parent, id_,
106
_("Preferences - Editra"), style=style)
107
super(PreferencesDialog, self).__init__(parent, id_,
108
_("Preferences - Editra"),
107
110
util.SetWindowIcon(self)
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.
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.
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)
185
180
self._imglst = list()
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)
203
199
# Message Handlers
204
200
ed_msg.Subscribe(self.OnThemeChange, ed_msg.EDMSG_THEME_CHANGED)
207
ed_msg.Unsubscribe(self.OnThemeChange)
202
def OnDestroy(self, evt):
203
if evt.GetId() == self.GetId():
204
ed_msg.Unsubscribe(self.OnThemeChange)
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)
445
443
#-----------------------------------------------------------------------------#
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)
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)
640
ok = stcspellcheck.STCSpellCheck.reloadEnchant(path)
642
645
# Reload was successful
643
646
sprefs['epath'] = path
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"))
775
782
fnt = Profile_Get('FONT1', 'font', wx.Font(10, wx.FONTFAMILY_MODERN,
785
792
"regions when syntax highlighting is in use"))
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),
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!!
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 ]:
862
871
e_value = evt.GetEventObject().GetValue()
863
872
if e_id == ed_glob.ID_EOL_MODE:
866
875
Profile_Set(ed_glob.ID_2_PROF[e_id], e_value)
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)
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),
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',
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)
1361
1371
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()
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)
1587
1602
#-----------------------------------------------------------------------------#
1599
1614
@param parent: Parent window of this panel
1602
wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
1617
super(AdvancedPanel, self).__init__(parent, style=wx.BORDER_SUNKEN)
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
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)
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),
1680
1699
def _DoLayout(self):
1681
1700
"""Layout the controls"""
1846
1865
self._UpdateBinding()
1867
#---- Properties ----#
1869
Dirty = property(lambda self: self._dirty,
1870
lambda self, bDirty: setattr(self, '_dirty', bDirty))
1848
1872
def ClearKeyView(self):
1849
1873
"""Clear all selections in the keybinding controls"""
1850
1874
self.FindWindowById(ID_MOD1).SetStringSelection('')
2118
2144
if len(choices) and isinstance(choices[0], int):
2119
2145
choices = [ unicode(choice) for choice in choices ]
2121
wx.Choice.__init__(self, parent, cid, choices=choices)
2147
super(ExChoice, self).__init__(parent, cid, choices=choices)
2123
2149
if default != None and isinstance(default, basestring):
2124
2150
self.SetStringSelection(default)