/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: Jelmer Vernooij
  • Date: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import gtk.gdk
20
20
 
21
 
from bzrlib import config
 
21
from bzrlib.config import config_dir
22
22
import bzrlib.util.configobj.configobj as configobj
23
23
 
24
24
 
25
 
def gannotate_config_filename():
26
 
    return os.path.join(config.config_dir(), "gannotate.conf")
 
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")
27
39
 
28
40
 
29
41
class GAnnotateConfig(configobj.ConfigObj):
35
47
    """
36
48
 
37
49
    def __init__(self, window):
38
 
        configobj.ConfigObj.__init__(self, gannotate_config_filename())
 
50
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
 
51
                                     configspec=gannotate_configspec)
39
52
        self.window = window
40
53
        self.pane = window.pane
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'
 
54
        self.span_selector = window.span_selector
 
55
        
 
56
        self.initial_comment = ["gannotate plugin configuration"]
 
57
        self['window']['width'] = 750
 
58
        self['window']['height'] = 550
 
59
        self['window']['maximized'] = False
 
60
        self['window']['x'] = 0
 
61
        self['window']['y'] = 0
 
62
        self['window']['pane_position'] = 325
 
63
        self['spans']['max_custom_spans'] = 4
 
64
        self['spans']['custom_spans'] = []
52
65
 
53
66
        self.apply()
54
67
        self._connect_signals()
56
69
    def apply(self):
57
70
        """Apply properties and such from gannotate.conf, or
58
71
        gannotate_configspec defaults."""
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'))
 
72
        self.pane.set_position(self["window"]["pane_position"])
 
73
        self.window.set_default_size(self["window"]["width"],
 
74
                                     self["window"]["height"])
 
75
        self.window.move(self["window"]["x"], self["window"]["y"])
63
76
 
64
 
        if self['window'].as_bool('maximized'):
 
77
        if self["window"]["maximized"]:
65
78
            self.window.maximize()
66
79
 
 
80
        self.span_selector.max_custom_spans =\
 
81
                self["spans"]["max_custom_spans"]
 
82
 
 
83
        # XXX Don't know how to set an empty list as default in
 
84
        # gannotate_configspec.
 
85
        try:
 
86
            for span in self["spans"]["custom_spans"]:
 
87
                self.span_selector.add_custom_span(span)
 
88
        except KeyError:
 
89
            pass
 
90
 
67
91
    def _connect_signals(self):
68
92
        self.window.connect("destroy", self._write)
69
93
        self.window.connect("configure-event", self._save_window_props)
70
94
        self.window.connect("window-state-event", self._save_window_props)
71
95
        self.pane.connect("notify", self._save_pane_props)
 
96
        self.span_selector.connect("custom-span-added",
 
97
                                   self._save_custom_spans)
72
98
 
73
99
    def _save_window_props(self, w, e, *args):
74
100
        if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED:
77
103
            self["window"]["width"], self["window"]["height"] = w.get_size()
78
104
            self["window"]["x"], self["window"]["y"] = w.get_position()
79
105
            maximized = False
 
106
 
80
107
        self["window"]["maximized"] = maximized
 
108
        
81
109
        return False
82
110
 
83
111
    def _save_pane_props(self, w, gparam):
86
114
 
87
115
        return False
88
116
 
 
117
    def _save_custom_spans(self, w, *args):
 
118
        self["spans"]["custom_spans"] = w.custom_spans
 
119
 
 
120
        return False
 
121
 
89
122
    def _write(self, *args):
90
123
        self.write()
91
124