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

  • Committer: Dan Loda
  • Date: 2005-10-30 05:49:31 UTC
  • mto: (0.1.25 gannotate)
  • mto: This revision was merged to the branch mainline in revision 49.
  • Revision ID: danloda@gmail.com-20051030054931-134d5e106f0ccfa0
Remember window state. This introduces the gannotate.conf configuration file,
written to the bazaar configuration directory

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 bzrlib.config import config_dir
 
20
import bzrlib.util.configobj.configobj as configobj
 
21
from bzrlib.util.configobj.validate import Validator
 
22
 
 
23
 
 
24
gannotate_configspec = (
 
25
    "[window]",
 
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)"
 
31
)
 
32
 
 
33
gannotate_config_filename = os.path.join(config_dir(), "gannotate.conf")
 
34
 
 
35
 
 
36
class GAnnotateConfig(configobj.ConfigObj):
 
37
    """gannotate configuration wrangler.
 
38
 
 
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.
 
42
    """
 
43
 
 
44
    def __init__(self, window):
 
45
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
 
46
                                     configspec=gannotate_configspec)
 
47
        self.window = window
 
48
        self.pane = window.pane
 
49
        
 
50
        self.initial_comment = ["gannotate plugin configuration"]
 
51
        self.validate(Validator())
 
52
 
 
53
        self._connect_signals()
 
54
        self.apply()
 
55
 
 
56
    def apply(self):
 
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"])
 
62
 
 
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)
 
69
 
 
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()
 
73
        
 
74
        return False
 
75
 
 
76
    def _save_pane_props(self, w, *args):
 
77
        self["window"]["pane_position"] = w.get_position()
 
78
 
 
79
        return False
 
80
 
 
81
    def _write(self, *args):
 
82
        self.write()
 
83
 
 
84
        return False
 
85