Package mathbench :: Package lab :: Module advisor
[hide private]

Source Code for Module mathbench.lab.advisor

  1  #!/usr/bin/python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  """ 
  5  The interface to chose the user's prefereed options. 
  6  """ 
  7   
  8   
  9  import sys 
 10  import os 
 11  import logging 
 12   
 13                   
 14  import wx 
 15  import wx.py.dispatcher as dispatcher 
 16   
 17  from mathbench.ext.pluginmanagement_widgets import PluginsConfigPanel 
 18  from mathbench.basement import plugin_manager as pman 
 19   
 20  # global variable for when we only want to test the display (see 
 21  # __main__ at the end of the file.) 
 22  ADVISOR_TEST_ONLY=False 
 23   
24 -class OptionsFrame(wx.Frame):
25
26 - def __init__(self,parent,config,id=-1,title="Options",size=wx.Size(-1,-1)):
27 """ 28 create a frame instance 29 """ 30 wx.Frame.__init__(self,parent=parent,id=id,title=title,size=size) 31 self.config = config 32 sizer = wx.BoxSizer(wx.VERTICAL) 33 nb = self.createNotebook() 34 sizer.Add(nb,proportion=1,flag=wx.EXPAND) 35 self.SetSizer(sizer) 36 self.SetIcon(wx.ArtProvider().GetIcon(wx.ART_HELP_SETTINGS)) 37 self.Fit() 38 self.Show() 39 self.Bind(wx.EVT_CLOSE,self.OnClose)
40
41 - def createNotebook(self):
42 """ 43 Create a notebook with all options 44 """ 45 nb = wx.Notebook(self, -1) 46 # Create general option panel 47 panel = OptionsPanel(nb,self.config) 48 nb.AddPage(panel,"General") 49 # Create 50 pm = pman.LabPluginManager.get() 51 plugpan = PluginsConfigPanel(nb, pm=pm, use_versions=False) 52 nb.AddPage(plugpan,"Plugins") 53 return nb
54 55
56 - def OnClose(self,event):
57 """ 58 When the frame must close 59 """ 60 if ADVISOR_TEST_ONLY: 61 logging.info("Configuration saved at closing") 62 dispatcher.send(signal="OptionsClosed",sender=self) 63 return event.Skip() 64 self.config.save() 65 dispatcher.send(signal="OptionsClosed",sender=self) 66 event.Skip()
67
68 -class OptionsPanel(wx.Panel):
69 """ 70 Makes it possible to set the options 71 """ 72
73 - def __init__(self,parent,config):
74 """ 75 create the panel instance 76 """ 77 wx.Panel.__init__(self,parent) 78 self.config = config 79 self.parent= parent 80 81 if ADVISOR_TEST_ONLY: 82 sizer = wx.BoxSizer(wx.VERTICAL) 83 # dummy text 84 sectiontitle1 = wx.StaticText(self,id=-1,label="Bla!") 85 sectiontitle1.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) 86 sectiontitle1.SetSize(sectiontitle1.GetBestSize()) 87 sizer.Add(sectiontitle1) 88 self.SetSizer(sizer) 89 return self.Fit() 90 91 # content design 92 sizer = wx.BoxSizer(wx.VERTICAL) 93 94 95 # completion section 96 sectiontitle1 = wx.StaticText(self,id=-1,label="Auto Completion") 97 sectiontitle1.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) 98 sectiontitle1.SetSize(sectiontitle1.GetBestSize()) 99 # -- the options 100 cb1_1 = wx.CheckBox(self,-1,"Show Auto Completion") 101 if self.config.get("Auto Completion","Show_Auto_Completion") == "1": 102 cb1_1.SetValue(True) 103 else: 104 cb1_1.SetValue(False) 105 106 cb1_2 = wx.CheckBox(self,-1,"Include Magic Attributes") 107 if self.config.get("Auto Completion","Include_Magic_Attributes") == "1": 108 cb1_2.SetValue(True) 109 else: 110 cb1_2.SetValue(False) 111 112 cb1_3 = wx.CheckBox(self,-1,"Include Single Underscores") 113 if self.config.get("Auto Completion","Include_Single_Underscores") == "1": 114 cb1_3.SetValue(True) 115 else: 116 cb1_3.SetValue(False) 117 118 cb1_4 = wx.CheckBox(self,-1,"Include Double Underscores") 119 if self.config.get("Auto Completion","Include_Double_Underscores") == "1": 120 cb1_4.SetValue(True) 121 else: 122 cb1_4.SetValue(False) 123 124 125 # call tip section 126 sectiontitle2 = wx.StaticText(self,id=-1,label="Call Tips") 127 sectiontitle2.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) 128 sectiontitle2.SetSize(sectiontitle2.GetBestSize()) 129 # -- the options 130 cb2_1 = wx.CheckBox(self,-1,"Show Call Tips") 131 if self.config.get("Call Tips","Show_Call_Tips") == "1": 132 cb2_1.SetValue(True) 133 else: 134 cb2_1.SetValue(False) 135 136 cb2_2 = wx.CheckBox(self,-1,"Insert_Call_Tips") 137 if self.config.get("Call Tips","Insert_Call_Tips") == "1": 138 cb2_2.SetValue(True) 139 else: 140 cb2_2.SetValue(False) 141 142 143 # call tip section 144 sectiontitle3 = wx.StaticText(self,id=-1,label="View") 145 sectiontitle3.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) 146 sectiontitle3.SetSize(sectiontitle3.GetBestSize()) 147 # -- the options 148 cb3_1 = wx.CheckBox(self,-1,"Wrap Lines") 149 if self.config.get("View","Wrap_Lines") == "1": 150 cb3_1.SetValue(True) 151 else: 152 cb3_1.SetValue(False) 153 154 cb3_2 = wx.CheckBox(self,-1,"Show Line Numbers") 155 if self.config.get("View","Show_Line_Numbers") == "1": 156 cb3_2.SetValue(True) 157 else: 158 cb3_2.SetValue(False) 159 160 161 sizer.AddMany([sectiontitle1, 162 cb1_1, 163 cb1_2, 164 cb1_3, 165 cb1_4, 166 (20,20), 167 sectiontitle2, 168 cb2_1, 169 cb2_2, 170 (20,20), 171 sectiontitle3, 172 cb3_1, 173 cb3_2]) 174 self.SetSizer(sizer) 175 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb1_1) 176 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb1_2) 177 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb1_3) 178 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb1_4) 179 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb2_1) 180 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb2_2) 181 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb3_1) 182 self.Bind(wx.EVT_CHECKBOX, self.OnCheckbox,cb3_2) 183 self.Fit()
184 185 186
187 - def OnCheckbox(self,event):
188 """ 189 When the user ticks/unticks a checkbox 190 """ 191 cb = event.GetEventObject() 192 state_str = "0" 193 if event.IsChecked(): 194 state_str="1" 195 # now set the right options 196 if cb.GetLabel()=="Show Auto Completion": 197 self.config.set("Auto Completion","Show_Auto_Completion",state_str) 198 elif cb.GetLabel()=="Include Magic Attributes": 199 self.config.set("Auto Completion","Include_Magic_Attributes",state_str) 200 elif cb.GetLabel()=="Include Single Underscores": 201 self.config.set("Auto Completion","Include_Single_Underscores",state_str) 202 elif cb.GetLabel()=="Include Double Underscores": 203 self.config.set("Auto Completion","Include_Double_Underscores",state_str) 204 elif cb.GetLabel()=="Show Call Tips": 205 self.config.set("Call Tips","Show_Call_Tips",state_str) 206 elif cb.GetLabel()=="Insert Call Tips": 207 self.config.set("Call Tips","Insert_Call_Tips",state_str) 208 elif cb.GetLabel()=="Wrap Lines": 209 self.config.set("View","Wrap_Lines",state_str) 210 elif cb.GetLabel()=="Show Line Numbers": 211 self.config.set("View","Show_Line_Numbers",state_str) 212 else: 213 return 214 dispatcher.send(signal='OptionsChanged', sender=self.parent.GetParent())
215 216 217 if __name__=="__main__": 218 219 sys.path.append(os.path.expanduser("~/src/mathbench/mathbenchdir/trunk")) 220 ADVISOR_TEST_ONLY=True 221 222 import ConfigParser 223 224 logging.basicConfig(level=logging.DEBUG) 225 226 from mathbench.basement import plugin_manager as pman 227 228 PLUGINS_DIR= os.path.expanduser("~/src/mathbench/mathbenchdir/trunk/plugins") 229 import ConfigParser 230 # create the plugin manager 231 pm = pman.LabPluginManager.get() 232 conf = ConfigParser.ConfigParser() 233 pm.setConfigParser(conf, lambda : True) 234 pm.setCategoriesFilter({"Default":pman.IPlugin}) 235 pm.setPluginPlaces([PLUGINS_DIR]) 236 pm.setPluginInfoExtension("mathplug") 237 # load the plugins 238 pm.collectPlugins() 239 240 app = wx.PySimpleApp() 241 242 f = OptionsFrame(None,conf) 243 f.Show() 244 245 app.MainLoop() 246