/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-05-19 16:56:46 UTC
  • mfrom: (0.1.25 gannotate)
  • Revision ID: jelmer@samba.org-20060519165646-0d867938fdbc9097
Merge in Dan Loda's gannotate plugin and put it in annotate/

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
 
 
24
 
 
25
 
def gannotate_config_filename():
26
 
    return os.path.join(config.config_dir(), "gannotate.conf")
 
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)",
 
30
    "maximized = boolean(default=False)",
 
31
    "x = integer(default=0)",
 
32
    "y = integer(default=0)",
 
33
    "pane_position = integer(default=325)",
 
34
    "[spans]",
 
35
    "max_custom_spans = integer(default=4)",
 
36
    "custom_spans = float_list()"
 
37
)
 
38
 
 
39
gannotate_config_filename = os.path.join(config_dir(), "gannotate.conf")
27
40
 
28
41
 
29
42
class GAnnotateConfig(configobj.ConfigObj):
35
48
    """
36
49
 
37
50
    def __init__(self, window):
38
 
        configobj.ConfigObj.__init__(self, gannotate_config_filename())
 
51
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
 
52
                                     configspec=gannotate_configspec)
39
53
        self.window = window
40
54
        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'
 
55
        self.span_selector = window.span_selector
 
56
        
 
57
        self.initial_comment = ["gannotate plugin configuration"]
 
58
        self.validate(Validator())
52
59
 
53
60
        self.apply()
54
61
        self._connect_signals()
56
63
    def apply(self):
57
64
        """Apply properties and such from gannotate.conf, or
58
65
        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'))
 
66
        self.pane.set_position(self["window"]["pane_position"])
 
67
        self.window.set_default_size(self["window"]["width"],
 
68
                                     self["window"]["height"])
 
69
        self.window.move(self["window"]["x"], self["window"]["y"])
63
70
 
64
 
        if self['window'].as_bool('maximized'):
 
71
        if self["window"]["maximized"]:
65
72
            self.window.maximize()
66
73
 
 
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
 
67
85
    def _connect_signals(self):
68
86
        self.window.connect("destroy", self._write)
69
87
        self.window.connect("configure-event", self._save_window_props)
70
88
        self.window.connect("window-state-event", self._save_window_props)
71
89
        self.pane.connect("notify", self._save_pane_props)
 
90
        self.span_selector.connect("custom-span-added",
 
91
                                   self._save_custom_spans)
72
92
 
73
93
    def _save_window_props(self, w, e, *args):
74
94
        if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED:
77
97
            self["window"]["width"], self["window"]["height"] = w.get_size()
78
98
            self["window"]["x"], self["window"]["y"] = w.get_position()
79
99
            maximized = False
 
100
 
80
101
        self["window"]["maximized"] = maximized
 
102
        
81
103
        return False
82
104
 
83
105
    def _save_pane_props(self, w, gparam):
86
108
 
87
109
        return False
88
110
 
 
111
    def _save_custom_spans(self, w, *args):
 
112
        self["spans"]["custom_spans"] = w.custom_spans
 
113
 
 
114
        return False
 
115
 
89
116
    def _write(self, *args):
90
117
        self.write()
91
118