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
21
from bzrlib import config
23
import bzrlib.util.configobj.configobj as configobj
28
def gannotate_config_filename():
29
return os.path.join(config.config_dir(), "gannotate.conf")
32
class GAnnotateConfig(configobj.ConfigObj):
33
"""gannotate configuration wrangler.
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.
40
def __init__(self, window):
41
configobj.ConfigObj.__init__(self, gannotate_config_filename())
43
self.pane = window.pane
45
if 'window' not in self:
46
# Set default values, configobj expects strings here
47
self.initial_comment = ["gannotate plugin configuration"]
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'
57
self._connect_signals()
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(self['window'].as_int('x'), self['window'].as_int('y'))
67
if self['window'].as_bool('maximized'):
68
self.window.maximize()
70
def _connect_signals(self):
71
self.window.connect("destroy", self._write)
72
self.window.connect("configure-event", self._save_window_props)
73
self.window.connect("window-state-event", self._save_window_props)
74
self.pane.connect("notify", self._save_pane_props)
76
def _save_window_props(self, w, e, *args):
77
if e.window.get_state() & Gdk.WINDOW_STATE_MAXIMIZED:
80
self["window"]["width"], self["window"]["height"] = w.get_size()
81
self["window"]["x"], self["window"]["y"] = w.get_position()
83
self["window"]["maximized"] = maximized
86
def _save_pane_props(self, w, gparam):
87
if gparam.name == "position":
88
self["window"]["pane_position"] = w.get_position()
92
def _write(self, *args):
93
config.ensure_config_dir_exists()