Changeset 94
- Timestamp:
- Wed Aug 10 12:16:43 2005
- Files:
-
- trunk/transolution/xliffeditor/gtk_main.py (modified) (diff)
- trunk/transolution/xliffeditor/settings.py (modified) (diff)
- trunk/transolution/xliffeditor/gtk_clipboard.py (modified) (diff)
- trunk/transolution/xliffeditor/gtk_utils.py (modified) (diff)
- trunk/transolution/xliffeditor/webdict.py (added)
- trunk/transolution/xliffeditor/glade/xliffeditor.glade (modified) (diff)
- trunk/transolution/fullconfigobj.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/transolution/xliffeditor/gtk_main.py
r91 r94 34 34 35 35 from general import Observer,Notifier 36 from gtk_utils import askOk,messageDialog,aboutDialog,cb_get_active_text,entryDialog,create_tag_table,fileChooserDialog 36 from gtk_utils import askOk,messageDialog,aboutDialog,cb_get_active_text,entryDialog,create_tag_table,fileChooserDialog,dropDownDialog 36 36 from general import EditorException 37 37 … … 530 530 self.tm_settings = TmSettings(address) 531 531 532 from webdict import WebDict 533 self.webdict = WebDict(settings.webdicts[settings.webdict.active]) 534 532 535 def onQuit(self,*args): 533 536 if self.notebook.get_n_pages() > 0: … … 788 791 self._updateGui() 789 792 793 def onWebLookupConfig(self,*args): 794 print "WebLookup Config" 795 try: 796 drop_down_values = ['%s'%(key) for key,val in settings.webdicts.items()] 797 drop_down_values.sort() 798 except IOError,e: 799 drop_down_values = None 800 msg = _('Select the web dictionary (for Web lookup) to use.') 801 result_webdict = dropDownDialog(self.window,_('Set web url to use for web lookups' ), 802 msg, _('Web post url'), 803 drop_down_values, 804 default_val=settings.webdict.active, 805 default_response=gtk.RESPONSE_OK) 806 if result_webdict: 807 # use the first part of the result string as it can have language description e.g. "AF-ZA (South Africa)" 808 settings.webdict.active = result_webdict.split()[0] 809 url = settings.webdicts[settings.webdict.active] 810 self.webdict.setUrl(settings.webdicts[settings.webdict.active]) 811 812 813 def onWebLookup(self,*args): 814 print "WebLookup" 815 from gtk_clipboard import clipboard 816 text = clipboard.getText() 817 self.webdict.lookup(text) 818 print " ",text 819 820 790 821 def onHelp(self,*args): 791 822 'Open help in a web browser' -
trunk/transolution/xliffeditor/settings.py
r17 r94 81 81 #------------------------------- 82 82 83 import types 84 c =ConfigParser.ConfigParser 85 mapping = {types.BooleanType:c.getboolean,types.StringType:c.get} 83 # This is the config spec 84 cspec = '''version = string 85 [tm] 86 address = string 87 automatic_lookup = option('False','True') 88 89 [fonts] 90 document_font = string 91 editor_font = string 92 93 [webdict] 94 active = string 95 96 [webdicts] 97 ''' 98 99 default_conf = u'''version= 0.4b4 100 [tm] 101 address = 'http://localhost:6315' 102 automatic_lookup = False 103 104 [fonts] 105 document_font = "" 106 editor_font = "" 107 108 [webdict] 109 ; current active webdict 110 active = "leo_en-de_url" 111 112 [webdicts] 113 ; this is post urls to use, replace the search term with a %s 114 leo_en-de_url = "http://dict.leo.org/?searchLoc=-1&searchLocRelinked=-1&lp=ende&lp=ende&lang=en&searchLoc=1&searchLocRelinked=1&search=%s" 115 leo_de-en_url ="http://dict.leo.org/?searchLoc=1&searchLocRelinked=1&lp=ende&lp=ende&lang=en&searchLoc=-1&searchLocRelinked=1&search=%s" 116 google_en-de = "http://translate.google.com/translate_t?text=%s&ie=UTF-8&oe=UTF-8&langpair=en%%7Cde&hl=en&ie=UTF-8&oe=UTF-8" 117 google_de-en = "http://translate.google.com/translate_t?text=%s&ie=UTF-8&oe=UTF-8&langpair=de%%7Cen&hl=en&ie=UTF-8&oe=UTF-8" 118 ''' 119 120 from transolution.path_mod import path 121 86 122 class ConfigError(Exception):pass 123 def getConfigFile(): 124 dir_root = get_config_dir() 125 if dir_root is None and os.name == 'nt': 126 tmp_dir_root = os.path.split(sys.executable)[0] 127 if os.access(tmp_dir_root, os.R_OK|os.W_OK): 128 dir_root = tmp_dir_root 87 129 88 class Settings(ConfigParser.ConfigParser): 89 # put setting classes here class == section, class properties == values 90 class tm: 91 address = str('http://localhost:6315') 92 automatic_lookup = bool(False) 93 94 class fonts: 95 document_font = str() 96 editor_font = str() 130 if dir_root is None: 131 raise ConfigError('Cant get configuration root dir') 132 133 configfile = os.path.join(dir_root, '.xliffeditor') 134 return path(configfile) 135 136 from transolution.fullconfigobj import ConfigObj,Validator 137 from StringIO import StringIO 97 138 98 def __init__(self):99 ConfigParser.ConfigParser.__init__(self)100 139 101 dir_root = get_config_dir() 102 if dir_root is None and os.name == 'nt': 103 tmp_dir_root = os.path.split(sys.executable)[0] 104 if os.access(tmp_dir_root, os.R_OK|os.W_OK): 105 dir_root = tmp_dir_root 106 107 if dir_root is None: 108 raise ConfigError('Cant get configuration root dir') 109 110 self.configfile = os.path.join(dir_root, '.xliffeditor') 111 112 ## try: self.readfp(open('defaults.ini')) 113 ## except IOError,e: 114 ## pass 115 116 print "Config file:", self.configfile 117 try: 118 self.read([self.configfile,]) 119 except MissingSectionHeaderError: 120 pass 121 except ParsingError: 122 pass 123 else: 124 self.load() 125 126 def load(self): 127 'automatically try to get all class(section) properties(options) from settings file' 128 for section,t in self.__class__.__dict__.items(): 129 if not (type(t) is types.ClassType): 130 continue 131 for option,val in t.__dict__.items(): 132 if option.startswith('_'): continue 133 try: self.__class__.__dict__[section].__dict__[option] = mapping[type(val)](self, section, option) 134 except (NoSectionError,NoOptionError),e: 135 pass 140 class Settings(ConfigObj): 141 # put setting classes here class == section, class properties == values 142 def __init__(self): 143 configfile = getConfigFile() 144 print "Config file:", configfile 145 146 # If there is no config file create one 147 if not configfile.isfile(): 148 print "creating configfile" 149 configfile.write_text(default_conf,encoding='utf-8') 150 151 ConfigObj.__init__(self, configfile, configspec=StringIO(cspec)) 152 if self.validate(val = Validator()) is not True: 153 print "The following config file settings (section,setting) had illegal values:%s"%(self.validate(val = Validator()),) 154 self._str2bool() 155 156 def _str2bool(self): 157 "convert string setting value to boolean" 158 if self.tm.automatic_lookup is None: 159 self.tm.automatic_lookup = 'False' 160 self.tm.automatic_lookup = self.istrue('automatic_lookup','tm') 161 162 def _bool2str(self): 163 "convert boolean setting to string" 164 self.tm.automatic_lookup = str(self.tm.automatic_lookup) 136 165 137 166 def save(self): 138 'automatically save all class(section) properties(options) that is not a type object to settings file'139 for section,t in self.__class__.__dict__.items():140 if not (type(t) is types.ClassType):141 continue142 for option,val in t.__dict__.items():143 if option.startswith('_'): continue144 if not self.has_section(section):145 self.add_section(section)146 self.set(section, option,val)147 148 167 # save to file 149 self.write(file(self.configfile,'w')) 168 self._bool2str() 169 self.write() 170 self._str2bool() 150 171 151 settings = Settings()172 settings = Settings() -
trunk/transolution/xliffeditor/gtk_clipboard.py
r6 r94 38 38 return text,nodelist 39 39 40 def getText(self): 41 """ 42 get data from clipboard as text. 43 """ 44 text = _gtk_clipboard.wait_for_text() 45 return text.decode('utf-8') 46 40 47 41 48 try: -
trunk/transolution/xliffeditor/gtk_utils.py
r88 r94 234 234 local_entry1 = combobox.child 235 235 table.attach(combobox, 1, 2, 0, 1) 236 print local_entry1237 236 238 237 local_entry1.set_activates_default(True) … … 255 254 return res 256 255 256 def dropDownDialog(parent,title,msg,lable,drop_down_values,default_val=None,default_response=gtk.RESPONSE_OK,): 257 ''' 258 Create a dropdown dialog. 259 @drop_down_values = list of text values to fill a combobox dropdown with. 260 @Returns = string entered or None if Cancel was pressed. 261 ''' 262 263 dialog = gtk.Dialog(title, parent, 0, 264 (gtk.STOCK_OK, gtk.RESPONSE_OK, 265 gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) 266 267 dialog.set_default_response(default_response) 268 269 hbox = gtk.HBox(False, 8) 270 hbox.set_border_width(8) 271 dialog.vbox.pack_start(hbox, False, False, 0) 272 273 stock = gtk.image_new_from_stock( 274 gtk.STOCK_DIALOG_QUESTION, 275 gtk.ICON_SIZE_DIALOG) 276 hbox.pack_start(stock, False, False, 0) 277 vbox = gtk.VBox(False, 8) 278 hbox.pack_start(vbox, True, True, 0) 279 vbox.pack_start(gtk.Label(msg), True, True, 0) 280 281 282 table = gtk.Table(2, 1) 283 table.set_row_spacings(4) 284 table.set_col_spacings(4) 285 vbox.pack_start(table, True, True, 0) 286 287 label = gtk.Label(lable) 288 label.set_use_underline(True) 289 table.attach(label, 0, 1, 0, 1) 290 291 # Create a combobox entry 292 combobox = gtk.combo_box_new_text() 293 for v in drop_down_values: 294 combobox.append_text(v) 295 table.attach(combobox, 1, 2, 0, 1) 296 297 if default_val: 298 for row in combobox.get_model(): 299 if row[0] == default_val: 300 combobox.set_active(row.path[0]) 301 break 302 303 dialog.show_all() 304 305 response = dialog.run() 306 307 if response == gtk.RESPONSE_OK: 308 model = combobox.get_model() 309 active = combobox.get_active() 310 if active < 0: 311 return None 312 res = model[active][0] 313 else: 314 res = None 315 dialog.destroy() 316 317 return res 318 257 319 def messageDialog(parent,msg,dlg_type=gtk.MESSAGE_INFO): 258 320 dialog = gtk.MessageDialog(parent, -
trunk/transolution/xliffeditor/glade/xliffeditor.glade
r82 r94 495 495 496 496 <child internal-child="image"> 497 <widget class="GtkImage" id="image 77">497 <widget class="GtkImage" id="image82"> 497 497 <property name="visible">True</property> 498 498 <property name="stock">gtk-media-forward</property> … … 517 517 518 518 <child internal-child="image"> 519 <widget class="GtkImage" id="image 78">519 <widget class="GtkImage" id="image83"> 519 519 <property name="visible">True</property> 520 520 <property name="stock">gtk-go-back</property> … … 877 877 878 878 <child> 879 <widget class="GtkMenuItem" id="tools1"> 880 <property name="visible">True</property> 881 <property name="label" translatable="yes">Tools</property> 882 <property name="use_underline">True</property> 883 <signal name="activate" handler="on_tools1_activate" last_modification_time="Wed, 10 Aug 2005 14:04:39 GMT"/> 884 885 <child> 886 <widget class="GtkMenu" id="tools1_menu"> 887 888 <child> 889 <widget class="GtkMenuItem" id="web_lookup1"> 890 <property name="visible">True</property> 891 <property name="tooltip" translatable="yes">Lookup current clipboard content in an online web dictionary using the webbrowser.</property> 892 <property name="label" translatable="yes">Web Lookup</property> 893 <property name="use_underline">True</property> 894 895 <child> 896 <widget class="GtkMenu" id="web_lookup1_menu"> 897 898 <child> 899 <widget class="GtkMenuItem" id="configure1"> 900 <property name="visible">True</property> 901 <property name="tooltip" translatable="yes">Configure the web site to use for lookup.</property> 902 <property name="label" translatable="yes">Configure</property> 903 <property name="use_underline">True</property> 904 <signal name="activate" handler="onWebLookupConfig" last_modification_time="Wed, 10 Aug 2005 14:08:49 GMT"/> 905 </widget> 906 </child> 907 908 <child> 909 <widget class="GtkMenuItem" id="lookup1"> 910 <property name="visible">True</property> 911 <property name="tooltip" translatable="yes">Lookup current clipboard content in online dictionary.</property> 912 <property name="label" translatable="yes">Lookup</property> 913 <property name="use_underline">True</property> 914 <signal name="activate" handler="onWebLookup" last_modification_time="Wed, 10 Aug 2005 14:04:39 GMT"/> 915 <accelerator key="space" modifiers="GDK_CONTROL_MASK" signal="activate"/> 916 </widget> 917 </child> 918 </widget> 919 </child> 920 </widget> 921 </child> 922 </widget> 923 </child> 924 </widget> 925 </child> 926 927 <child> 879 928 <widget class="GtkMenuItem" id="menuitem7"> 880 929 <property name="visible">True</property>
