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 |
||
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
21 |
from bzrlib import config |
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
22 |
import bzrlib.util.configobj.configobj as configobj |
23 |
||
24 |
||
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
25 |
def gannotate_config_filename(): |
26 |
return os.path.join(config.config_dir(), "gannotate.conf") |
|
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
27 |
|
28 |
||
29 |
class GAnnotateConfig(configobj.ConfigObj): |
|
30 |
"""gannotate configuration wrangler. |
|
31 |
||
32 |
Staying as far out of the way as possible, hanging about catching events
|
|
33 |
and saving only what's necessary. Writes gannotate.conf when the gannotate
|
|
34 |
window is destroyed. Initializes saved properties when instantiated.
|
|
35 |
"""
|
|
36 |
||
37 |
def __init__(self, window): |
|
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
38 |
configobj.ConfigObj.__init__(self, gannotate_config_filename()) |
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
39 |
self.window = window |
40 |
self.pane = window.pane |
|
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
41 |
|
42 |
if 'window' not in self: |
|
43 |
# Set default values, configobj expects strings here
|
|
44 |
self.initial_comment = ["gannotate plugin configuration"] |
|
45 |
self['window'] = {} |
|
46 |
self['window']['width'] = '750' |
|
47 |
self['window']['height'] = '550' |
|
48 |
self['window']['maximized'] = 'False' |
|
49 |
self['window']['x'] = '0' |
|
50 |
self['window']['y'] = '0' |
|
51 |
self['window']['pane_position'] = '325' |
|
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
52 |
|
0.1.11
by Dan Loda
Remember window's maximized state. |
53 |
self.apply() |
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
54 |
self._connect_signals() |
55 |
||
56 |
def apply(self): |
|
57 |
"""Apply properties and such from gannotate.conf, or |
|
0.1.14
by Dan Loda
Remember custom spans across sessions. |
58 |
gannotate_configspec defaults."""
|
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
59 |
self.pane.set_position(self['window'].as_int('pane_position')) |
60 |
self.window.set_default_size(self['window'].as_int('width'), |
|
61 |
self['window'].as_int('height')) |
|
62 |
self.window.move(self['window'].as_int('x'), self['window'].as_int('y')) |
|
0.1.11
by Dan Loda
Remember window's maximized state. |
63 |
|
634
by Vincent Ladeuil
Fix bug #373157 by properly setting the default values. |
64 |
if self['window'].as_bool('maximized'): |
0.1.11
by Dan Loda
Remember window's maximized state. |
65 |
self.window.maximize() |
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
66 |
|
67 |
def _connect_signals(self): |
|
68 |
self.window.connect("destroy", self._write) |
|
69 |
self.window.connect("configure-event", self._save_window_props) |
|
0.1.11
by Dan Loda
Remember window's maximized state. |
70 |
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, |
71 |
self.pane.connect("notify", self._save_pane_props) |
72 |
||
0.1.11
by Dan Loda
Remember window's maximized state. |
73 |
def _save_window_props(self, w, e, *args): |
74 |
if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED: |
|
75 |
maximized = True |
|
76 |
else: |
|
77 |
self["window"]["width"], self["window"]["height"] = w.get_size() |
|
78 |
self["window"]["x"], self["window"]["y"] = w.get_position() |
|
79 |
maximized = False |
|
80 |
self["window"]["maximized"] = maximized |
|
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
81 |
return False |
82 |
||
0.1.11
by Dan Loda
Remember window's maximized state. |
83 |
def _save_pane_props(self, w, gparam): |
84 |
if gparam.name == "position": |
|
85 |
self["window"]["pane_position"] = w.get_position() |
|
0.1.8
by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file, |
86 |
|
87 |
return False |
|
88 |
||
89 |
def _write(self, *args): |
|
90 |
self.write() |
|
91 |
||
92 |
return False |
|
93 |