/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

  • Committer: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

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
 
import gtk.gdk
20
 
 
21
 
from bzrlib.config import config_dir
22
 
import bzrlib.util.configobj.configobj as configobj
23
 
 
24
 
 
25
 
gannotate_configspec = (
26
 
    "[window]",
27
 
    "width = integer(default=750)",
28
 
    "height = integer(default=550)",
29
 
    "maximized = boolean(default=False)",
30
 
    "x = integer(default=0)",
31
 
    "y = integer(default=0)",
32
 
    "pane_position = integer(default=325)",
33
 
    "[spans]",
34
 
    "max_custom_spans = integer(default=4)",
35
 
    "custom_spans = float_list()"
36
 
)
37
 
 
38
 
gannotate_config_filename = os.path.join(config_dir(), "gannotate.conf")
39
 
 
40
 
 
41
 
class GAnnotateConfig(configobj.ConfigObj):
42
 
    """gannotate configuration wrangler.
43
 
 
44
 
    Staying as far out of the way as possible, hanging about catching events
45
 
    and saving only what's necessary. Writes gannotate.conf when the gannotate
46
 
    window is destroyed. Initializes saved properties when instantiated.
47
 
    """
48
 
 
49
 
    def __init__(self, window):
50
 
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
51
 
                                     configspec=gannotate_configspec)
52
 
        self.window = window
53
 
        self.pane = window.pane
54
 
        
55
 
        self.initial_comment = ["gannotate plugin configuration"]
56
 
        self['window']['width'] = 750
57
 
        self['window']['height'] = 550
58
 
        self['window']['maximized'] = False
59
 
        self['window']['x'] = 0
60
 
        self['window']['y'] = 0
61
 
        self['window']['pane_position'] = 325
62
 
        self['spans']['max_custom_spans'] = 4
63
 
        self['spans']['custom_spans'] = []
64
 
 
65
 
        self.apply()
66
 
        self._connect_signals()
67
 
 
68
 
    def apply(self):
69
 
        """Apply properties and such from gannotate.conf, or
70
 
        gannotate_configspec defaults."""
71
 
        self.pane.set_position(self["window"]["pane_position"])
72
 
        self.window.set_default_size(self["window"]["width"],
73
 
                                     self["window"]["height"])
74
 
        self.window.move(self["window"]["x"], self["window"]["y"])
75
 
 
76
 
        if self["window"]["maximized"]:
77
 
            self.window.maximize()
78
 
 
79
 
        # XXX Don't know how to set an empty list as default in
80
 
        # gannotate_configspec.
81
 
    def _connect_signals(self):
82
 
        self.window.connect("destroy", self._write)
83
 
        self.window.connect("configure-event", self._save_window_props)
84
 
        self.window.connect("window-state-event", self._save_window_props)
85
 
        self.pane.connect("notify", self._save_pane_props)
86
 
 
87
 
    def _save_window_props(self, w, e, *args):
88
 
        if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED:
89
 
            maximized = True
90
 
        else:
91
 
            self["window"]["width"], self["window"]["height"] = w.get_size()
92
 
            self["window"]["x"], self["window"]["y"] = w.get_position()
93
 
            maximized = False
94
 
 
95
 
        self["window"]["maximized"] = maximized
96
 
        
97
 
        return False
98
 
 
99
 
    def _save_pane_props(self, w, gparam):
100
 
        if gparam.name == "position":
101
 
            self["window"]["pane_position"] = w.get_position()
102
 
 
103
 
        return False
104
 
 
105
 
    def _save_custom_spans(self, w, *args):
106
 
        self["spans"]["custom_spans"] = w.custom_spans
107
 
 
108
 
        return False
109
 
 
110
 
    def _write(self, *args):
111
 
        self.write()
112
 
 
113
 
        return False
114