/b-gtk/fix-viz

To get this branch, use:
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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
19
import Gtk.gdk
0.1.11 by Dan Loda
Remember window's maximized state.
20
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
21
from bzrlib import config
675 by Jelmer Vernooij
use system configobj if bzrlib doesn't ship with one.
22
try:
23
    import bzrlib.util.configobj.configobj as configobj
24
except ImportError:
25
    import configobj
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
26
27
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
28
def gannotate_config_filename():
29
    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,
30
31
32
class GAnnotateConfig(configobj.ConfigObj):
33
    """gannotate configuration wrangler.
34
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.
38
    """
39
40
    def __init__(self, window):
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
41
        configobj.ConfigObj.__init__(self, gannotate_config_filename())
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
42
        self.window = window
43
        self.pane = window.pane
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
44
45
        if 'window' not in self:
46
            # Set default values, configobj expects strings here
47
            self.initial_comment = ["gannotate plugin configuration"]
48
            self['window'] = {}
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'
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
55
0.1.11 by Dan Loda
Remember window's maximized state.
56
        self.apply()
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
57
        self._connect_signals()
58
59
    def apply(self):
60
        """Apply properties and such from gannotate.conf, or
0.1.14 by Dan Loda
Remember custom spans across sessions.
61
        gannotate_configspec defaults."""
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
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'))
0.1.11 by Dan Loda
Remember window's maximized state.
66
634 by Vincent Ladeuil
Fix bug #373157 by properly setting the default values.
67
        if self['window'].as_bool('maximized'):
0.1.11 by Dan Loda
Remember window's maximized state.
68
            self.window.maximize()
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
69
70
    def _connect_signals(self):
71
        self.window.connect("destroy", self._write)
72
        self.window.connect("configure-event", self._save_window_props)
0.1.11 by Dan Loda
Remember window's maximized state.
73
        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,
74
        self.pane.connect("notify", self._save_pane_props)
75
0.1.11 by Dan Loda
Remember window's maximized state.
76
    def _save_window_props(self, w, e, *args):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
77
        if e.window.get_state() & Gdk.WINDOW_STATE_MAXIMIZED:
0.1.11 by Dan Loda
Remember window's maximized state.
78
            maximized = True
79
        else:
80
            self["window"]["width"], self["window"]["height"] = w.get_size()
81
            self["window"]["x"], self["window"]["y"] = w.get_position()
82
            maximized = False
83
        self["window"]["maximized"] = maximized
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
84
        return False
85
0.1.11 by Dan Loda
Remember window's maximized state.
86
    def _save_pane_props(self, w, gparam):
87
        if gparam.name == "position":
88
            self["window"]["pane_position"] = w.get_position()
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
89
90
        return False
91
92
    def _write(self, *args):
732 by Jelmer Vernooij
Ensure directory exists before writing configuration.
93
        config.ensure_config_dir_exists()
0.1.8 by Dan Loda
Remember window state. This introduces the gannotate.conf configuration file,
94
        self.write()
95
        return False
96