/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: 2012-02-05 05:14:11 UTC
  • mto: This revision was merged to the branch mainline in revision 775.
  • Revision ID: sinzui.is@verizon.net-20120205051411-y9ra08wae1wsfv52
Remove unneeded gtksourceview1 support.

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
 
 
24
 
 
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")
 
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")
39
30
 
40
31
 
41
32
class GAnnotateConfig(configobj.ConfigObj):
47
38
    """
48
39
 
49
40
    def __init__(self, window):
50
 
        configobj.ConfigObj.__init__(self, gannotate_config_filename,
51
 
                                     configspec=gannotate_configspec)
 
41
        super(GAnnotateConfig, self).__init__(gannotate_config_filename())
52
42
        self.window = window
53
43
        self.pane = window.pane
54
 
        
55
 
        self.initial_comment = ["gannotate plugin configuration"]
56
 
        self['window']['width'] = 750
57
 
        self['window']['height'] = 550
58
 
        self['window']['maximized'] = False
59
 
        self['window']['x'] = 0
60
 
        self['window']['y'] = 0
61
 
        self['window']['pane_position'] = 325
62
 
        self['spans']['max_custom_spans'] = 4
63
 
        self['spans']['custom_spans'] = []
 
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'
64
55
 
65
56
        self.apply()
66
57
        self._connect_signals()
68
59
    def apply(self):
69
60
        """Apply properties and such from gannotate.conf, or
70
61
        gannotate_configspec defaults."""
71
 
        self.pane.set_position(self["window"]["pane_position"])
72
 
        self.window.set_default_size(self["window"]["width"],
73
 
                                     self["window"]["height"])
74
 
        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'))
75
66
 
76
 
        if self["window"]["maximized"]:
 
67
        if self['window'].as_bool('maximized'):
77
68
            self.window.maximize()
78
69
 
79
 
        # XXX Don't know how to set an empty list as default in
80
 
        # gannotate_configspec.
81
70
    def _connect_signals(self):
82
71
        self.window.connect("destroy", self._write)
83
72
        self.window.connect("configure-event", self._save_window_props)
85
74
        self.pane.connect("notify", self._save_pane_props)
86
75
 
87
76
    def _save_window_props(self, w, e, *args):
88
 
        if e.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED:
 
77
        if e.window.get_state() & Gdk.WindowState.MAXIMIZED:
89
78
            maximized = True
90
79
        else:
91
80
            self["window"]["width"], self["window"]["height"] = w.get_size()
92
81
            self["window"]["x"], self["window"]["y"] = w.get_position()
93
82
            maximized = False
94
 
 
95
83
        self["window"]["maximized"] = maximized
96
 
        
97
84
        return False
98
85
 
99
86
    def _save_pane_props(self, w, gparam):
100
 
        if gparam.name == "position":
 
87
        if gparam and gparam.name == "position":
101
88
            self["window"]["pane_position"] = w.get_position()
102
89
 
103
90
        return False
104
91
 
105
 
    def _save_custom_spans(self, w, *args):
106
 
        self["spans"]["custom_spans"] = w.custom_spans
107
 
 
108
 
        return False
109
 
 
110
92
    def _write(self, *args):
 
93
        config.ensure_config_dir_exists()
111
94
        self.write()
112
 
 
113
95
        return False
114
96