- Timestamp:
- 09/23/06 18:47:13 (2 years ago)
- Files:
-
- trunk/lib/config.py (modified) (2 diffs)
- trunk/lib/gui/mainwin.py (modified) (2 diffs)
- trunk/lib/gui/pluginwin.py (modified) (9 diffs)
- trunk/lib/gui/prefswin.py (modified) (2 diffs)
- trunk/lib/meta.py (modified) (3 diffs)
- trunk/opendict.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/config.py
r1 r3 31 31 32 32 33 class ActiveDictConfig(object): 34 """Config file manager for activated dictionaries. Operates with 35 names of dictionaries only.""" 36 37 def __init__(self): 38 self.filePath = os.path.join(info.LOCAL_HOME, "active.conf") 39 40 # If config file does not exist (this is the first time), 41 # set special attribute init=True to notify that 42 if not os.path.exists(self.filePath): 43 self.init = True 44 else: 45 self.init = False 46 47 self.dicts = [] 48 49 50 def load(self): 51 """Load list of active dictionaries.""" 52 53 try: 54 for line in open(self.filePath): 55 name = line.strip() 56 name = unicode(name, 'UTF-8') 57 self.dicts.append(name) 58 except IOError, e: 59 pass 60 61 62 def save(self): 63 """Save list of active dictionaries.""" 64 65 fd = open(self.filePath, 'w') 66 for d in self.dicts: 67 name = d.encode('UTF-8') 68 print >> fd, name 69 fd.close() 70 71 72 def enabled(self, name): 73 """Return True if this dictionary is enabled.""" 74 75 if name in self.dicts: 76 return True 77 78 return False 79 80 81 def add(self, name): 82 """Add new dictionary to the list.""" 83 84 if type(name) == str: 85 name = unicode(name, 'UTF-8') 86 87 if not name in self.dicts: 88 self.dicts.append(name) 89 90 91 def remove(self, name): 92 """Remove dictionary from the list.""" 93 94 if type(name) == str: 95 name = unicode(name, 'UTF-8') 96 97 if name in self.dicts: 98 self.dicts.remove(name) 99 100 101 33 102 class Configuration: 34 103 """This class is used for reading and writing config file. … … 37 106 def __init__(self): 38 107 """Initialize default values""" 108 109 self.activedict = ActiveDictConfig() 110 self.activedict.load() 39 111 40 112 self.filePath = os.path.join(info.LOCAL_HOME, "opendict.xml") trunk/lib/gui/mainwin.py
r1 r3 265 265 self.menuDict = wxMenu() 266 266 267 dict Names = []267 dicts = [] 268 268 for dictionary in self.app.dictionaries.values(): 269 dictNames.append(dictionary.getName()) 270 dictNames.sort() 271 272 for name in dictNames: 269 dicts.append([dictionary.getName(), dictionary.getActive()]) 270 dicts.sort() 271 272 for name, active in dicts: 273 #if not self.app.config.activedict.enabled(name): 274 # continue 275 if not active: 276 continue 277 273 278 encoded = enc.toWX(name) 274 279 … … 1049 1054 EVT_MENU(self, unid, self.onDefault) 1050 1055 1051 self.menuDict.InsertItem(self.menuDict.GetMenuItemCount()-2, item) 1056 #self.menuDict.InsertItem(self.menuDict.GetMenuItemCount()-2, item) 1057 self.menuDict.InsertItem(0, item) 1058 1059 1060 def removeDictionary(self, name): 1061 """Remove dictionary from the menu""" 1062 1063 item = self.menuDict.FindItem(name) 1064 if item: 1065 self.menuDict.Delete(item) 1052 1066 1053 1067 trunk/lib/gui/pluginwin.py
r1 r3 1 1 2 2 # OpenDict 3 # Copyright (c) 2003-200 5Martynas Jocius <mjoc@akl.lt>3 # Copyright (c) 2003-2006 Martynas Jocius <mjoc@akl.lt> 4 4 # 5 5 # This program is free software; you can redistribute it and/or modify … … 123 123 # 124 124 idDictList = wx.NewId() 125 self.installedList = DictListCtrl(panelInstalled, idDictList,125 self.installedList = wx.CheckListBox(panelInstalled, idDictList, 126 126 style=wx.LC_REPORT 127 127 | wx.LC_SINGLE_SEL 128 128 | wx.SUNKEN_BORDER) 129 self.Bind(wx.EVT_CHECKLISTBOX, self.onDictionaryChecked, 130 self.installedList) 131 self.Bind(wx.EVT_LISTBOX, self.onInstalledSelected, 132 self.installedList) 129 133 vboxInstalled.Add(self.installedList, 1, wxALL | wxEXPAND, 1) 130 134 … … 155 159 # Make columns 156 160 # 157 self.installedList.InsertColumn(0, _("Name"))161 #self.installedList.InsertColumn(0, _("Name")) 158 162 159 163 dictNames = self.installedDictionaries.keys() … … 162 166 self.setInstalledDicts(dictNames) 163 167 164 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onInstalledSelected,165 self.installedList)168 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onInstalledSelected, 169 # self.installedList) 166 170 167 171 self.Bind(wx.EVT_BUTTON, self.onRemove, self.buttonRemove) … … 181 185 182 186 # 183 # Installed list187 # List of available dictionaries 184 188 # 185 189 idAvailList = wx.NewId() … … 306 310 307 311 return panelInfo 312 313 314 def onDictionaryChecked(self, event, *args): 315 index = event.GetSelection() 316 label = self.installedList.GetString(index) 317 if self.installedList.IsChecked(index): 318 self._addDictToMenu(label) 319 d = self.app.dictionaries.get(label) 320 d.setActive() 321 else: 322 self._removeDictFromMenu(label) 323 d = self.app.dictionaries.get(label) 324 d.setActive(active=False) 325 self.installedList.SetSelection(index) 326 327 328 def _removeDictFromMenu(self, name): 329 self.app.config.activedict.remove(name) 330 self.app.config.activedict.save() 331 self.app.window.removeDictionary(name) 332 333 334 def _addDictToMenu(self, name): 335 dict = None 336 for k, v in self.app.dictionaries.items(): 337 if k == name: 338 dict = v 339 if dict: 340 self.app.config.activedict.add(name) 341 self.app.config.activedict.save() 342 self.app.window.addDictionary(dict) 308 343 309 344 … … 334 369 """Called when list item is selected""" 335 370 336 self.currentInstalledItemSelection = event. m_itemIndex371 self.currentInstalledItemSelection = event.GetSelection() 337 372 self.buttonRemove.Enable(1) 338 373 … … 343 378 """Show information about selected dictionary""" 344 379 345 dictName = self.installedList.Get ItemText(\380 dictName = self.installedList.GetString(\ 346 381 self.currentInstalledItemSelection) 347 382 … … 441 476 def setInstalledDicts(self, dictNames): 442 477 """Clear the list of installed dictionaries and set new items""" 443 444 self.installedList.DeleteAllItems() 478 479 for i in range(self.installedList.GetCount()): 480 self.installedList.Delete(i) 445 481 446 482 dictNames.sort() 447 483 dictNames.reverse() 448 484 i = 0 485 449 486 for dictionary in dictNames: 450 index = self.installedList.InsertStringItem(0, dictionary) 451 self.installedList.SetItemData(index, index+1) 452 453 454 if dictNames: 455 self.installedList.SetColumnWidth(0, wx.LIST_AUTOSIZE) 456 else: 457 self.installedList.SetColumnWidth(0, 200) 487 index = self.installedList.Insert(dictionary, i) 488 if self.app.dictionaries[dictionary].getActive(): 489 self.installedList.Check(i) 490 i += 1 458 491 459 492 trunk/lib/gui/prefswin.py
r1 r3 1 1 # 2 2 # OpenDict 3 # Copyright (c) 2003-200 5Martynas Jocius <mjoc@akl.lt>3 # Copyright (c) 2003-2006 Martynas Jocius <mjoc@akl.lt> 4 4 # 5 5 # This program is free software; you can redistribute it and/or modify … … 48 48 0, wxALIGN_CENTER_VERTICAL) 49 49 50 dictNames = self.app.dictionaries.keys() 50 dictNames = [] 51 for name, d in self.app.dictionaries.items(): 52 print name, d.getActive() 53 if d.getActive(): 54 dictNames.append(name) 51 55 dictNames.sort() 52 56 dictNames.insert(0, "") trunk/lib/meta.py
r1 r3 1 1 # 2 2 # OpenDict 3 # Copyright (c) 2005 Martynas Jocius <mjoc@akl.lt>3 # Copyright (c) 2005-2006 Martynas Jocius <mjoc@akl.lt> 4 4 # 5 5 # This program is free software; you can redistribute it and/or modify … … 76 76 class Dictionary: 77 77 """Dictionary interface""" 78 79 active = True 78 80 79 81 … … 154 156 155 157 return None 158 159 160 def getActive(self): 161 return self.active 162 163 164 def setActive(self, active=True): 165 self.active = active 156 166 157 167 trunk/opendict.py
r1 r3 162 162 163 163 164 for d in self.dictionaries.values(): 165 if not self.config.activedict.init: 166 if not self.config.activedict.enabled(d.getName()): 167 d.setActive(active=False) 168 else: 169 # Fill up with names if not initialized yet 170 self.config.activedict.add(d.getName()) 171 172 164 173 windowPos = (int(self.config.get('windowPosX')), 165 174 int(self.config.get('windowPosY')))
