/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/frontend/gtk/__init__.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-08-09 17:43:44 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060809174344-61ca8dac23ebe7cb
Main window preferences (size, position) are stored.

2006-08-09  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * olive/frontend/gtk/__init__.py: simplified preference handling
    * olive/frontend/gtk/handler.py: window preferences are stored on quit

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        # Connect the signals to the handlers
89
89
        self.toplevel.signal_autoconnect(dic)
90
90
        
 
91
        # Apply window size and position
 
92
        width = self.pref.get_preference('window_width', 'int')
 
93
        height = self.pref.get_preference('window_height', 'int')
 
94
        self.window.resize(width, height)
 
95
        x = self.pref.get_preference('window_x', 'int')
 
96
        y = self.pref.get_preference('window_y', 'int')
 
97
        self.window.move(x, y)
 
98
        # Apply paned position
 
99
        pos = self.pref.get_preference('paned_position', 'int')
 
100
        self.comm.hpaned_main.set_position(pos)
 
101
        
91
102
        # Load default data into the panels
92
103
        self.treeview_left = self.toplevel.get_widget('treeview_left')
93
104
        self.treeview_right = self.toplevel.get_widget('treeview_right')
140
151
        
141
152
        # Fill the appropriate lists
142
153
        path = self.comm.get_path()
143
 
        dotted_files = self.pref.get_dotted_files()
 
154
        dotted_files = self.pref.get_preference('dotted_files')
144
155
        for item in os.listdir(path):
145
156
            if not dotted_files and item[0] == '.':
146
157
                continue
196
207
        
197
208
        # Get the main window
198
209
        self.window_main = self.toplevel.get_widget('window_main')
 
210
        # Get the HPaned
 
211
        self.hpaned_main = self.toplevel.get_widget('hpaned_main')
199
212
        # Get the TreeViews
200
213
        self.treeview_left = self.toplevel.get_widget('treeview_left')
201
214
        self.treeview_right = self.toplevel.get_widget('treeview_right')
283
296
        files = []
284
297
        
285
298
        # Fill the appropriate lists
286
 
        dotted_files = self.pref.get_dotted_files()
 
299
        dotted_files = self.pref.get_preference('dotted_files')
287
300
        for item in os.listdir(path):
288
301
            if not dotted_files and item[0] == '.':
289
302
                continue
320
333
    def __init__(self):
321
334
        """ Initialize the Preferences class. """
322
335
        # Some default options
323
 
        self.defaults = { 'strict_commit': False,
324
 
                          'dotted_files' : False }
 
336
        self.defaults = { 'strict_commit' : False,
 
337
                          'dotted_files'  : False,
 
338
                          'window_width'  : 700,
 
339
                          'window_height' : 400,
 
340
                          'window_x'      : 40,
 
341
                          'window_y'      : 40,
 
342
                          'paned_position': 200 }
325
343
        
326
344
        # Create a config parser object
327
345
        self.config = ConfigParser.RawConfigParser()
365
383
            self.config.write(fp)
366
384
            fp.close()
367
385
 
368
 
    def get_strict_commit(self):
369
 
        """ Get strict commit preference. """
370
 
        if self.config.has_option('preferences', 'strict_commit'):
371
 
            return self.config.getboolean('preferences', 'strict_commit')
372
 
        else:
373
 
            return self._get_default('strict_commit')
374
 
 
375
 
    def set_strict_commit(self, value):
376
 
        """ Set strict commit preference. """
377
 
        if self.config.has_section('preferences'):
378
 
            self.config.set('preferences', 'strict_commit', value)
379
 
        else:
380
 
            self.config.add_section('preferences')
381
 
            self.config.set('preferences', 'strict_commit', value)
382
 
 
383
 
    def get_dotted_files(self):
384
 
        """ Get dotted files preference. """
385
 
        if self.config.has_option('preferences', 'dotted_files'):
386
 
            return self.config.getboolean('preferences', 'dotted_files')
387
 
        else:
388
 
            return self._get_default('dotted_files')
389
 
 
390
 
    def set_dotted_files(self, value):
391
 
        """ Set dotted files preference. """
392
 
        if self.config.has_section('preferences'):
393
 
            self.config.set('preferences', 'dotted_files', value)
394
 
        else:
395
 
            self.config.add_section('preferences')
396
 
            self.config.set('preferences', 'dotted_files', value)
397
 
 
 
386
    def get_preference(self, option, kind='str'):
 
387
        """ Get the value of the given option.
 
388
        
 
389
        :param kind: str/bool/int/float. default: str
 
390
        """
 
391
        if self.config.has_option('preferences', option):
 
392
            if kind == 'bool':
 
393
                return self.config.getboolean('preferences', option)
 
394
            elif kind == 'int':
 
395
                return self.config.getint('preferences', option)
 
396
            elif kind == 'float':
 
397
                return self.config.getfloat('preferences', option)
 
398
            else:
 
399
                return self.config.get('preferences', option)
 
400
        else:
 
401
            try:
 
402
                return self._get_default(option)
 
403
            except KeyError:
 
404
                return None
 
405
    
 
406
    def set_preference(self, option, value):
 
407
        """ Set the value of the given option. """
 
408
        if self.config.has_section('preferences'):
 
409
            self.config.set('preferences', option, value)
 
410
        else:
 
411
            self.config.add_section('preferences')
 
412
            self.config.set('preferences', option, value)
 
413
    
398
414
    def get_bookmarks(self):
399
415
        """ Return the list of bookmarks. """
400
416
        bookmarks = self.config.sections()