1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
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.
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.
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
19
from bzrlib.config import config_dir
20
import bzrlib.util.configobj.configobj as configobj
21
from bzrlib.util.configobj.validate import Validator
24
gannotate_configspec = (
26
"width = integer(default=750)",
27
"height = integer(default=550)",
28
"x = integer(default=0)",
29
"y = integer(default=0)",
30
"pane_position = integer(default=325)"
33
gannotate_config_filename = os.path.join(config_dir(), "gannotate.conf")
36
class GAnnotateConfig(configobj.ConfigObj):
37
"""gannotate configuration wrangler.
39
Staying as far out of the way as possible, hanging about catching events
40
and saving only what's necessary. Writes gannotate.conf when the gannotate
41
window is destroyed. Initializes saved properties when instantiated.
44
def __init__(self, window):
45
configobj.ConfigObj.__init__(self, gannotate_config_filename,
46
configspec=gannotate_configspec)
48
self.pane = window.pane
50
self.initial_comment = ["gannotate plugin configuration"]
51
self.validate(Validator())
53
self._connect_signals()
57
"""Apply properties and such from gannotate.conf, or
58
gannotate_config_spec defaults."""
59
self.window.resize(self["window"]["width"], self["window"]["height"])
60
self.window.move(self["window"]["x"], self["window"]["y"])
61
self.pane.set_position(self["window"]["pane_position"])
63
def _connect_signals(self):
64
self.window.connect("destroy", self._write)
65
self.window.connect("delete-event", self._save_window_props)
66
self.window.connect("configure-event", self._save_window_props)
67
self.pane.connect("delete-event", self._save_pane_props)
68
self.pane.connect("notify", self._save_pane_props)
70
def _save_window_props(self, w, *args):
71
self["window"]["width"], self["window"]["height"] = w.get_size()
72
self["window"]["x"], self["window"]["y"] = w.get_position()
76
def _save_pane_props(self, w, *args):
77
self["window"]["pane_position"] = w.get_position()
81
def _write(self, *args):