/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 annotate/config.py

Commit messages never contain config options

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import os
 
18
 
 
19
from gi.repository import Gdk
 
20
 
 
21
from bzrlib import config
 
22
try:
 
23
    import bzrlib.util.configobj.configobj as configobj
 
24
except ImportError:
 
25
    import configobj
 
26
 
 
27
 
 
28
def gannotate_config_filename():
 
29
    return os.path.join(config.config_dir(), "gannotate.conf")
 
30
 
 
31
 
 
32
class GAnnotateConfig(configobj.ConfigObj):
 
33
    """gannotate configuration wrangler.
 
34
 
 
35
    Staying as far out of the way as possible, hanging about catching events
 
36
    and saving only what's necessary. Writes gannotate.conf when the gannotate
 
37
    window is destroyed. Initializes saved properties when instantiated.
 
38
    """
 
39
 
 
40
    def __init__(self, window):
 
41
        super(GAnnotateConfig, self).__init__(gannotate_config_filename())
 
42
        self.window = window
 
43
        self.pane = window.pane
 
44
 
 
45
        if 'window' not in self:
 
46
            # Set default values, configobj expects strings here
 
47
            self.initial_comment = ["gannotate plugin configuration"]
 
48
            self['window'] = {}
 
49
            self['window']['width'] = '750'
 
50
            self['window']['height'] = '550'
 
51
            self['window']['maximized'] = 'False'
 
52
            self['window']['x'] = '0'
 
53
            self['window']['y'] = '0'
 
54
            self['window']['pane_position'] = '325'
 
55
 
 
56
        self.apply()
 
57
        self._connect_signals()
 
58
 
 
59
    def apply(self):
 
60
        """Apply properties and such from gannotate.conf, or
 
61
        gannotate_configspec defaults."""
 
62
        self.pane.set_position(self['window'].as_int('pane_position'))
 
63
        self.window.set_default_size(self['window'].as_int('width'),
 
64
                                     self['window'].as_int('height'))
 
65
        self.window.move(
 
66
            self['window'].as_int('x'), self['window'].as_int('y'))
 
67
 
 
68
        if self['window'].as_bool('maximized'):
 
69
            self.window.maximize()
 
70
 
 
71
    def _connect_signals(self):
 
72
        self.window.connect("destroy", self._write)
 
73
        self.window.connect("configure-event", self._save_window_props)
 
74
        self.window.connect("window-state-event", self._save_window_props)
 
75
 
 
76
    def _save_window_props(self, w, e, *args):
 
77
        if e.window.get_state() & Gdk.WindowState.MAXIMIZED:
 
78
            maximized = True
 
79
        else:
 
80
            self["window"]["width"], self["window"]["height"] = w.get_size()
 
81
            self["window"]["x"], self["window"]["y"] = w.get_position()
 
82
            maximized = False
 
83
        self["window"]["maximized"] = maximized
 
84
        return False
 
85
 
 
86
    def _save_pane_props(self):
 
87
        self["window"]["pane_position"] = self.pane.get_position()
 
88
 
 
89
    def _write(self, *args):
 
90
        self._save_pane_props()
 
91
        config.ensure_config_dir_exists()
 
92
        self.write()
 
93
        return False