Ignore:
Timestamp:
10/10/09 21:45:49 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket #2: Patch by Kaydeth. Updated the rest of the classes in the scripts directory to correct some obvious discrepancies with our coding standard. Still need to go through the common and objects sub directories. comment[s:trac, t:2]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/filebrowser.py

    r303 r313  
    2424    """ 
    2525    FileBrowser displays directory and file listings from the vfs. 
    26     The fileSelected parameter is a callback invoked when a file selection has been made; its 
    27     signature must be fileSelected(path,filename). If selectdir is set, fileSelected's 
    28     filename parameter should be optional. 
    29     The savefile option provides a box for supplying a new filename that doesn't exist yet. 
    30     The selectdir option allows directories to be selected as well as files. 
     26    The file_selected parameter is a callback invoked when a file selection 
     27    has been made; its signature must be file_selected(path,filename). If 
     28    select_dir is set, file_selected's filename parameter should be optional. 
     29    The save_file option provides a box for supplying a new filename that 
     30    doesn't exist yet. The select_dir option allows directories to be 
     31    selected as well as files. 
    3132    """ 
    32     def __init__(self, engine, fileSelected, savefile=False, selectdir=False, extensions=('.dat',), guixmlpath="gui/filebrowser.xml"): 
     33    def __init__(self, engine, file_selected, save_file=False, \ 
     34                 select_dir=False, extensions=('.dat',), \ 
     35                 gui_xml_path="gui/filebrowser.xml"): 
    3336        self.engine = engine 
    34         self.fileSelected = fileSelected 
     37        self.file_selected = file_selected 
    3538 
    3639        self._widget = None 
    37         self.savefile = savefile 
    38         self.selectdir = selectdir 
     40        self.save_file = save_file 
     41        self.select_dir = select_dir 
    3942         
    40         self.guixmlpath = guixmlpath 
     43        self.gui_xml_path = gui_xml_path 
    4144 
    4245        self.extensions = extensions 
     
    5053            self._widget.show() 
    5154            return 
    52         self._widget = pychan.loadXML(self.guixmlpath) 
     55        self._widget = pychan.loadXML(self.gui_xml_path) 
    5356        self._widget.mapEvents({ 
    5457            'dirList'       : self._setDirectory, 
     
    5760        }) 
    5861        self._setDirectory() 
    59         if self.savefile: 
     62        if self.save_file: 
    6063            self._file_entry = widgets.TextField(name='saveField', text=u'')     
    61             self._widget.findChild(name="fileColumn").addChild(self._file_entry) 
     64            self._widget.findChild(name="fileColumn").\ 
     65                addChild(self._file_entry) 
    6266        self._widget.show() 
    6367 
     
    7882            if fs_encoding is None: fs_encoding = "ascii" 
    7983         
    80             newList = [] 
     84            new_list = [] 
    8185            for i in list: 
    82                 try: newList.append(unicode(i, fs_encoding)) 
     86                try: 
     87                    new_list.append(unicode(i, fs_encoding)) 
    8388                except: 
    84                     newList.append(unicode(i, fs_encoding, 'replace')) 
     89                    new_list.append(unicode(i, fs_encoding, 'replace')) 
    8590                    print "WARNING: Could not decode item:", i 
    86             return newList 
     91            return new_list 
    8792             
    8893         
     
    9196        self.file_list = [] 
    9297         
    93         dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path)) 
    94         file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path)) 
     98        dir_list = ('..',) + filter(lambda d: not d.startswith('.'), \ 
     99                                    self.engine.getVFS().\ 
     100                                    listDirectories(self.path)) 
     101        file_list = filter(lambda f: f.split('.')[-1] in self.extensions, \ 
     102                           self.engine.getVFS().listFiles(self.path)) 
    95103                 
    96104        self.dir_list = decodeList(dir_list) 
     
    107115        data = self._widget.collectData('saveField') 
    108116 
    109         if self.savefile: 
     117        if self.save_file: 
    110118            if data: 
    111119                if (data.split('.')[1] == 'dat'): 
    112                     self.fileSelected(self.path, u2s(self._widget.collectData('saveField'))) 
     120                    self.file_selected(self.path, \ 
     121                                u2s(self._widget.collectData('saveField'))) 
    113122                else: 
    114123                    self._warningMessage() 
     
    117126 
    118127        if selection >= 0 and selection < len(self.file_list): 
    119             self.fileSelected(self.path, u2s(self.file_list[selection])) 
     128            self.file_selected(self.path, u2s(self.file_list[selection])) 
    120129            return 
    121130         
    122         if self.selectdir: 
    123             self.fileSelected(self.path) 
     131        if self.select_dir: 
     132            self.file_selected(self.path) 
    124133            return 
    125134 
Note: See TracChangeset for help on using the changeset viewer.