/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-08 14:44:53 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-20060808144453-f7ac8684b15bf34f
Implemented OlivePreferences; some wording fixes.

2006-08-08  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
    * olive/frontend/gtk/__init__.py: implemented OlivePreferences - this class
      is responsible for loading/saving user preferences
    * olive/frontend/gtk/handler.py: save preferences before quit
    * olive.glade: some wordings fixed (thanks to David Allouche)

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
        self.window = self.toplevel.get_widget('window_main')
52
52
        self.window.show_all()
53
53
        
54
 
        self.comm = OliveCommunicator(self.toplevel)
 
54
        self.pref = OlivePreferences()
 
55
        self.comm = OliveCommunicator(self.toplevel, self.pref)
55
56
        handler = OliveHandler(self.gladefile, self.comm)
56
57
        
57
58
        # Dictionary for signal_autoconnect
58
59
        dic = { "on_window_main_destroy": gtk.main_quit,
59
 
                "on_quit_activate": gtk.main_quit,
 
60
                "on_window_main_delete_event": handler.on_window_main_delete_event,
 
61
                "on_quit_activate": handler.on_window_main_delete_event,
60
62
                "on_about_activate": handler.on_about_activate,
61
63
                "on_menuitem_add_files_activate": handler.on_menuitem_add_files_activate,
62
64
                "on_menuitem_remove_file_activate": handler.on_menuitem_remove_file_activate,
106
108
        
107
109
        # Fill the appropriate lists
108
110
        path = self.comm.get_path()
 
111
        dotted_files = self.pref.get_dotted_files()
109
112
        for item in os.listdir(path):
 
113
            if not dotted_files and item[0] == '.':
 
114
                continue
110
115
            if os.path.isdir(path + '/' + item):
111
116
                dirs.append(item)
112
117
            else:
145
150
class OliveCommunicator:
146
151
    """ This class is responsible for the communication between the different
147
152
    modules. """
148
 
    def __init__(self, toplevel):
 
153
    def __init__(self, toplevel, pref):
149
154
        # Get glade main component
150
155
        self.toplevel = toplevel
 
156
        # Preferences object
 
157
        self.pref = pref
151
158
        # Default path
152
159
        self._path = os.getcwd()
153
160
        
155
162
        self.statusbar = self.toplevel.get_widget('statusbar')
156
163
        self.context_id = self.statusbar.get_context_id('olive')
157
164
        
 
165
        # Get the main window
 
166
        self.window_main = self.toplevel.get_widget('window_main')
158
167
        # Get the TreeViews
159
168
        self.treeview_left = self.toplevel.get_widget('treeview_left')
160
169
        self.treeview_right = self.toplevel.get_widget('treeview_right')
202
211
        files = []
203
212
        
204
213
        # Fill the appropriate lists
 
214
        dotted_files = self.pref.get_dotted_files()
205
215
        for item in os.listdir(path):
 
216
            if not dotted_files and item[0] == '.':
 
217
                continue
206
218
            if os.path.isdir(path + '/' + item):
207
219
                dirs.append(item)
208
220
            else:
228
240
            widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
229
241
        else:
230
242
            widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
231
 
        
 
243
 
232
244
        gtk.main_iteration(0)
 
245
 
 
246
class OlivePreferences:
 
247
    """ A class which handles Olive's preferences. """
 
248
    def __init__(self):
 
249
        """ Initialize the Preferences class. """
 
250
        import ConfigParser
 
251
        
 
252
        # Some default options
 
253
        self.defaults = { 'strict_commit': False,
 
254
                          'dotted_files' : False }
 
255
        
 
256
        # Create a config parser object
 
257
        self.config = ConfigParser.RawConfigParser()
 
258
        
 
259
        # Load the configuration
 
260
        if sys.platform == 'win32':
 
261
            # Windows - no dotted files
 
262
            self.config.read([os.path.expanduser('~/olive.conf')])
 
263
        else:
 
264
            self.config.read([os.path.expanduser('~/.olive.conf')])
 
265
        
 
266
    def _get_default(self, option):
 
267
        """ Get the default option for a preference. """
 
268
        try:
 
269
            ret = self.defaults[option]
 
270
        except KeyError:
 
271
            return None
 
272
        else:
 
273
            return ret
 
274
 
 
275
    def refresh(self):
 
276
        """ Refresh the configuration. """
 
277
        # First write out the changes
 
278
        self.write()
 
279
        # Then load the configuration again
 
280
        if sys.platform == 'win32':
 
281
            # Windows - no dotted files
 
282
            self.config.read([os.path.expanduser('~/olive.conf')])
 
283
        else:
 
284
            self.config.read([os.path.expanduser('~/.olive.conf')])
 
285
 
 
286
    def write(self):
 
287
        """ Write the configuration to the appropriate files. """
 
288
        if sys.platform == 'win32':
 
289
            # Windows - no dotted files
 
290
            fp = open(os.path.expanduser('~/olive.conf'), 'w')
 
291
            self.config.write(fp)
 
292
            fp.close()
 
293
        else:
 
294
            fp = open(os.path.expanduser('~/.olive.conf'), 'w')
 
295
            self.config.write(fp)
 
296
            fp.close()
 
297
 
 
298
    def get_strict_commit(self):
 
299
        """ Get strict commit preference. """
 
300
        if self.config.has_option('preferences', 'strict_commit'):
 
301
            return self.config.getboolean('preferences', 'strict_commit')
 
302
        else:
 
303
            return self._get_default('strict_commit')
 
304
 
 
305
    def set_strict_commit(self, value):
 
306
        """ Set strict commit preference. """
 
307
        if self.config.has_section('preferences'):
 
308
            self.config.set('preferences', 'strict_commit', value)
 
309
        else:
 
310
            self.config.add_section('preferences')
 
311
            self.config.set('preferences', 'strict_commit', value)
 
312
 
 
313
    def get_dotted_files(self):
 
314
        """ Get dotted files preference. """
 
315
        if self.config.has_option('preferences', 'dotted_files'):
 
316
            return self.config.getboolean('preferences', 'dotted_files')
 
317
        else:
 
318
            return self._get_default('dotted_files')
 
319
 
 
320
    def set_dotted_files(self, value):
 
321
        """ Set dotted files preference. """
 
322
        if self.config.has_section('preferences'):
 
323
            self.config.set('preferences', 'dotted_files', value)
 
324
        else:
 
325
            self.config.add_section('preferences')
 
326
            self.config.set('preferences', 'dotted_files', value)
 
327
 
 
328
    def get_bookmarks(self):
 
329
        """ Return the list of bookmarks. """
 
330
        bookmarks = self.config.sections()
 
331
        if self.config.has_section('preferences'):
 
332
            bookmarks.remove('preferences')
 
333
        return bookmarks
 
334
 
 
335
    def add_bookmark(self, path):
 
336
        """ Add bookmark. """
 
337
        try:
 
338
            self.config.add_section(path)
 
339
        except DuplicateSectionError:
 
340
            return False
 
341
        else:
 
342
            return True
 
343
 
 
344
    def del_bookmark(self, path):
 
345
        """ Remove bookmark. """
 
346
        return self.config.remove_section(path)