/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: Curtis Hovey
  • Date: 2011-09-05 03:44:26 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110905034426-p98pxnay9rmzkr99
Fix the initializer for many classes.
Replace Gtk.Dialog.vbox with .get_content_area().

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
 
19
 
import gtk.gdk
20
 
 
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)",
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")
 
19
from gi.repository import Gdk
 
20
 
 
21
from bzrlib import config
 
22
try:
 
23
    import bzrlib.util.configobj.configobj as configobj
 
24
except ImportError:
 
25
    import configobj
 
26
 
 
27
 
 
28
def gannotate_config_filename():
 
29
    return os.path.join(config.config_dir(), "gannotate.conf")
40
30
 
41
31
 
42
32
class GAnnotateConfig(configobj.ConfigObj):
48
38
    """
49
39
 
50
40
    def __init__(self, window):
51
 
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
52
 
                                     configspec=gannotate_configspec)
 
41
        super(GAnnotateConfig, self).__init__(gannotate_config_filename())
53
42
        self.window = window
54
43
        self.pane = window.pane
55
 
        self.span_selector = window.span_selector
56
 
        
57
 
        self.initial_comment = ["gannotate plugin configuration"]
58
 
        self.validate(Validator())
 
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'
59
55
 
60
56
        self.apply()
61
57
        self._connect_signals()
63
59
    def apply(self):
64
60
        """Apply properties and such from gannotate.conf, or
65
61
        gannotate_configspec defaults."""
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"])
 
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'))
70
66
 
71
 
        if self["window"]["maximized"]:
 
67
        if self['window'].as_bool('maximized'):
72
68
            self.window.maximize()
73
69
 
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
 
 
85
70
    def _connect_signals(self):
86
71
        self.window.connect("destroy", self._write)
87
72
        self.window.connect("configure-event", self._save_window_props)
88
73
        self.window.connect("window-state-event", self._save_window_props)
89
74
        self.pane.connect("notify", self._save_pane_props)
90
 
        self.span_selector.connect("custom-span-added",
91
 
                                   self._save_custom_spans)
92
75
 
93
76
    def _save_window_props(self, w, e, *args):
94
 
        if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED:
 
77
        if e.window.get_state() & Gdk.WindowState.MAXIMIZED:
95
78
            maximized = True
96
79
        else:
97
80
            self["window"]["width"], self["window"]["height"] = w.get_size()
98
81
            self["window"]["x"], self["window"]["y"] = w.get_position()
99
82
            maximized = False
100
 
 
101
83
        self["window"]["maximized"] = maximized
102
 
        
103
84
        return False
104
85
 
105
86
    def _save_pane_props(self, w, gparam):
106
 
        if gparam.name == "position":
 
87
        if gparam and gparam.name == "position":
107
88
            self["window"]["pane_position"] = w.get_position()
108
89
 
109
90
        return False
110
91
 
111
 
    def _save_custom_spans(self, w, *args):
112
 
        self["spans"]["custom_spans"] = w.custom_spans
113
 
 
114
 
        return False
115
 
 
116
92
    def _write(self, *args):
 
93
        config.ensure_config_dir_exists()
117
94
        self.write()
118
 
 
119
95
        return False
120
96