Changeset 51

Show
Ignore:
Timestamp:
02/08/04 18:26:34 (5 years ago)
Author:
ug
Message:

Finished implementation of encoding support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 05/devel/kombilo.py

    r50 r51  
    25692569    """ The main class of Kombilo. """ 
    25702570 
    2571     def process(self, dbpath, datap, messages, encoding=''): 
     2571    def process(self, dbpath, datap, messages): 
    25722572        """ Process the database dbpath, i.e. translate the SGF files into the 
    25732573        .db files that the pattern search function uses. 
     
    25932593        else: 
    25942594            filelist = glob.glob(os.path.join(dbpath,'*')) 
     2595 
     2596        encoding = self.encodingVar.get() 
    25952597             
    25962598        filelist.sort() 
     
    52925294        if not namelist: return 
    52935295         
    5294         self.gamelist.DBlist.append({'name': datap, 'sgfpath':dbpath, 'encoding': ''
     5296        self.gamelist.DBlist.append({'name': datap, 'sgfpath':dbpath, 'encoding': self.encodingVar.get()
    52955297                                     'current':array('L'), 'results':[], 'numNewGames':0, 
    52965298                                     'data':[], 'disabled': 0}) 
     
    53725374         
    53735375            self.gamelist.DBlist[i:i] = [{'name':datap, 'sgfpath':dbpath, 'current':array('L'), 
    5374                                           'results':[], 'numNewGames':0, 
     5376                                          'encoding': self.encodingVar.get(), 'results':[], 'numNewGames':0, 
    53755377                                          'data':[], 'disabled': 0}] 
    53765378         
     
    54655467    def browseDatabases(self): 
    54665468        initdir = self.options.whereToStoreDatabases.get() or os.curdir 
    5467         filename = str(askdirectory(initialdir = initdir)) 
     5469        filename = askdirectory(initialdir = initdir) 
     5470        if filename: filename = str(filename) 
    54685471        self.options.whereToStoreDatabases.set(filename) 
    54695472         
     
    55305533 
    55315534        self.filenamesVar = StringVar() 
    5532         filenamesMenu = Pmw.OptionMenu(f3, labelpos='w', label_text='Files:', menubutton_textvariable = self.filenamesVar, 
     5535        filenamesMenu = Pmw.OptionMenu(f3, labelpos='w', label_text='Files:', 
     5536                                       menubutton_textvariable = self.filenamesVar, 
    55335537                                       items = ['*.sgf', '*.sgf, *.mgt', 'All files'], initialitem = 0) 
    5534         filenamesMenu.grid(row=1, column=0, columnspan=2, sticky=W) 
     5538        filenamesMenu.grid(row=1, column=0, sticky=W) 
     5539 
     5540        self.encodingVar = StringVar() 
     5541        if cjkcodecs_available: 
     5542            enclist = ['utf-8', 'gb2312', 'gbk', 'gb18030', 'hz', 
     5543                       'big5', 'cp950', 'cp932',  'shift-jis', 'shift-jisx0213', 
     5544                       'euc-jp', 'euc-jisx0213', 'iso-2022-jp', 'iso-2022-jp-1', 
     5545                       'iso-2022-jp-2', 'iso-2022-jp-3', 'iso-2022-jp-ext', 
     5546                       'cp949', 'euc-kr', 'johab', 'iso-2022-kr'] 
     5547        else: 
     5548            enclist = ['utf-8'] 
     5549        encodingMenu = Pmw.OptionMenu(f3, labelpos='w', label_text='Encoding:', 
     5550                                      menubutton_textvariable = self.encodingVar, 
     5551                                      items = enclist, initialitem = 0) 
     5552        encodingMenu.grid(row=1, column=1, sticky=W) 
    55355553 
    55365554        recursionButton = Checkbutton(f3, text = "Recursively add subdir's", highlightthickness=0, 
     
    55405558        whereDatabasesButton = Checkbutton(f3, text = 'Store databases separately from SGF files', highlightthickness=0, 
    55415559                                           command = self.toggleWhereDatabases, variable = self.options.storeDatabasesSeparately) 
    5542         whereDatabasesButton.grid(row=3, column=0, sticky=W) 
     5560        whereDatabasesButton.grid(row=3, column=0, columnspan=2, sticky=W) 
    55435561 
    55445562        self.whereDatabasesEntry = Entry(f3, textvariable = self.options.whereToStoreDatabases) 
    5545         self.whereDatabasesEntry.grid(row=4, column=0, sticky=NSEW) 
     5563        self.whereDatabasesEntry.grid(row=4, column=0, columnspan=2, sticky=NSEW) 
    55465564        if not self.options.storeDatabasesSeparately.get(): self.whereDatabasesEntry.config(state=DISABLED) 
    55475565 
    55485566        browseButton = Button(f3, text ='Browse', command = self.browseDatabases) 
    5549         browseButton.grid(row=4, column=1
     5567        browseButton.grid(row=4, column=2
    55505568 
    55515569        self.processMessages = Message(f4) 
     
    57475765            for db in self.gamelist.DBlist: 
    57485766                if db['disabled']: 
    5749                     f.write('dD|%'+ db['sgfpath'] + '|%' + db['name'][0] + '|%' + db['name'][1] +'\n') 
     5767                    f.write('dD|%'+ db['sgfpath'] + '|%' + db['name'][0] +\ 
     5768                            '|%' + db['name'][1] + '|%' + db['encoding'] + '\n') 
    57505769                else: 
    5751                     f.write('d|%' + db['sgfpath'] + '|%' + db['name'][0] + '|%' + db['name'][1] +'\n') 
     5770                    f.write('d|%' + db['sgfpath'] + '|%' + db['name'][0] +\ 
     5771                            '|%' + db['name'][1] + '|%' + db['encoding']  +'\n') 
    57525772            f.close() 
    57535773        except IOError: 
     
    62596279                            self.sgfpath = line[1] 
    62606280                        elif line and line[0] == 'd': 
     6281                            if len(line)==4: 
     6282                                enc = 'utf-8' 
     6283                            else: 
     6284                                enc = line[4] 
    62616285                            self.gamelist.DBlist.append({'sgfpath':line[1], 'name':(line[2], line[3]), 'data':[], 
    6262                                                          'encoding': '', 'results':[], 'current':array('L'), 
     6286                                                         'encoding': enc, 'results':[], 'current':array('L'), 
    62636287                                                         'numNewGames':0, 'disabled': 0}) 
    62646288                     
    62656289                        elif line and line[0] == 'dD': 
     6290                            if len(line)==3: 
     6291                                enc = 'utf-8' 
     6292                            else: 
     6293                                enc = line[4] 
    62666294                            self.gamelist.DBlist.append({'sgfpath':line[1], 'name':(line[2], line[3]), 'data':[], 
    6267                                                          'encoding': '', 'results':[], 'current':array('L'), 
     6295                                                         'encoding': enc, 'results':[], 'current':array('L'), 
    62686296                                                         'numNewGames':0, 'disabled': 1}) 
    62696297