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