/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 __init__.py

  • Committer: Szilveszter Farkas
  • Date: 2009-05-26 13:58:24 UTC
  • mto: (635.2.6 trunk)
  • mto: This revision was merged to the branch mainline in revision 639.
  • Revision ID: szilveszter.farkas@gmail.com-20090526135824-fwvt03uqtl2p6vk7
Updated the README entry about GtkSourceView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
"""Graphical support for Bazaar using GTK.
16
16
 
17
17
This plugin includes:
18
 
gannotate         GTK+ annotate.
19
 
gbranch           GTK+ branching.
20
 
gcheckout         GTK+ checkout.
 
18
gannotate         GTK+ annotate. 
 
19
gbranch           GTK+ branching. 
 
20
gcheckout         GTK+ checkout. 
21
21
gcommit           GTK+ commit dialog.
22
 
gconflicts        GTK+ conflicts.
23
 
gdiff             Show differences in working tree in a GTK+ Window.
 
22
gconflicts        GTK+ conflicts. 
 
23
gdiff             Show differences in working tree in a GTK+ Window. 
24
24
ginit             Initialise a new branch.
 
25
ginfo             GTK+ branch info dialog
25
26
gloom             GTK+ loom browse dialog
26
27
gmerge            GTK+ merge dialog
27
 
gmissing          GTK+ missing revisions dialog.
28
 
gpreferences      GTK+ preferences dialog.
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
29
30
gpush             GTK+ push.
30
31
gsend             GTK+ send merge directive.
31
32
gstatus           GTK+ status dialog.
32
33
gtags             Manage branch tags.
33
 
visualise         Graphically visualise this branch.
 
34
visualise         Graphically visualise this branch. 
34
35
"""
35
36
 
36
 
from __future__ import absolute_import
37
 
 
38
 
import os
39
 
import sys
40
 
 
41
 
if getattr(sys, "frozen", None) is not None: # we run bzr.exe
42
 
 
43
 
    # FIXME: Unless a better packaging solution is found, the following
44
 
    # provides a workaround for https://bugs.launchpad.net/bzr/+bug/388790 Also
45
 
    # see https://code.edge.launchpad.net/~vila/bzr-gtk/388790-windows-setup
46
 
    # for more details about while it's needed.
47
 
 
48
 
    # NOTE: _lib must be ahead of bzrlib or sax.saxutils (in olive) fails
49
 
    here = os.path.dirname(__file__)
50
 
    sys.path.insert(0, os.path.join(here, '_lib'))
51
 
    sys.path.append(os.path.join(here, '_lib/gtk-2.0'))
52
 
 
53
 
 
54
37
import bzrlib
55
38
import bzrlib.api
 
39
from bzrlib import errors
56
40
from bzrlib.commands import plugin_cmds
57
41
 
58
 
from bzrlib.plugins.gtk.info import (
59
 
    bzr_plugin_version as version_info,
60
 
    bzr_compatible_versions,
61
 
    )
 
42
import os.path
 
43
 
 
44
version_info = (0, 96, 0, 'dev', 1)
62
45
 
63
46
if version_info[3] == 'final':
64
47
    version_string = '%d.%d.%d' % version_info[:3]
66
49
    version_string = '%d.%d.%d%s%d' % version_info
67
50
__version__ = version_string
68
51
 
69
 
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
 
52
COMPATIBLE_BZR_VERSIONS = [(1, 6, 0), (1, 7, 0), (1, 8, 0), (1, 9, 0),
 
53
                           (1, 10, 0), (1, 11, 0), (1, 12, 0), (1, 13, 0),
 
54
                           (1, 15, 0),]
 
55
 
 
56
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
70
57
 
71
58
if __name__ != 'bzrlib.plugins.gtk':
72
59
    from bzrlib.trace import warning
73
60
    warning("Not running as bzrlib.plugins.gtk, things may break.")
74
61
 
 
62
def import_pygtk():
 
63
    try:
 
64
        import pygtk
 
65
    except ImportError:
 
66
        raise errors.BzrCommandError("PyGTK not installed.")
 
67
    pygtk.require('2.0')
 
68
    return pygtk
 
69
 
75
70
 
76
71
def set_ui_factory():
77
 
    from bzrlib.plugins.gtk.ui import GtkUIFactory
 
72
    import_pygtk()
 
73
    from ui import GtkUIFactory
78
74
    import bzrlib.ui
79
75
    bzrlib.ui.ui_factory = GtkUIFactory()
80
76
 
97
93
    return data_path(os.path.join('icons', *args))
98
94
 
99
95
 
 
96
def open_display():
 
97
    pygtk = import_pygtk()
 
98
    try:
 
99
        import gtk
 
100
    except RuntimeError, e:
 
101
        if str(e) == "could not open display":
 
102
            raise NoDisplayError
 
103
    set_ui_factory()
 
104
    return gtk
 
105
 
 
106
 
100
107
commands = {
101
108
    "gannotate": ["gblame", "gpraise"],
102
109
    "gbranch": [],
105
112
    "gconflicts": [],
106
113
    "gdiff": [],
107
114
    "ginit": [],
 
115
    "ginfo": [],
108
116
    "gmerge": [],
109
117
    "gmissing": [],
110
118
    "gpreferences": [],
111
119
    "gpush": [],
 
120
    "gselftest": [],
112
121
    "gsend": [],
113
122
    "gstatus": ["gst"],
114
123
    "gtags": [],
115
 
    "visualise": ["visualize", "vis", "viz", 'glog'],
 
124
    "visualise": ["visualize", "vis", "viz"],
116
125
    }
117
126
 
118
127
try:
126
135
    plugin_cmds.register_lazy("cmd_%s" % cmd, aliases,
127
136
                              "bzrlib.plugins.gtk.commands")
128
137
 
129
 
def save_commit_messages(*args):
130
 
    from bzrlib.plugins.gtk import commitmsgs
131
 
    commitmsgs.save_commit_messages(*args)
132
 
 
133
 
try:
134
 
    from bzrlib.hooks import install_lazy_named_hook
135
 
except ImportError:
136
 
    from bzrlib.branch import Branch
137
 
    Branch.hooks.install_named_hook('post_uncommit',
138
 
                                    save_commit_messages,
139
 
                                    "Saving commit messages for gcommit")
140
 
else:
141
 
    install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
142
 
        'post_uncommit', save_commit_messages, "Saving commit messages for gcommit")
143
 
 
144
 
try:
145
 
    from bzrlib.registry import register_lazy
146
 
except ImportError:
147
 
    from bzrlib import config
148
 
    option_registry = getattr(config, "option_registry", None)
149
 
    if option_registry is not None:
150
 
        config.option_registry.register_lazy('nautilus_integration',
151
 
                'bzrlib.plugins.gtk.config', 'opt_nautilus_integration')
152
 
else:
153
 
    register_lazy("bzrlib.config", "option_registry",
154
 
        'nautilus_integration', 'bzrlib.plugins.gtk.config',
155
 
        'opt_nautilus_integration')
 
138
 
 
139
import gettext
 
140
gettext.install('olive-gtk')
 
141
 
 
142
# Let's create a specialized alias to protect '_' from being erased by other
 
143
# uses of '_' as an anonymous variable (think pdb for one).
 
144
_i18n = gettext.gettext
 
145
 
 
146
class NoDisplayError(errors.BzrCommandError):
 
147
    """gtk could not find a proper display"""
 
148
 
 
149
    def __str__(self):
 
150
        return "No DISPLAY. Unable to run GTK+ application."
156
151
 
157
152
 
158
153
def load_tests(basic_tests, module, loader):
164
159
    try:
165
160
        result = basic_tests
166
161
        try:
167
 
            import gi.repository.Gtk
168
 
        except ImportError:
 
162
            import_pygtk()
 
163
        except errors.BzrCommandError:
169
164
            return basic_tests
170
165
        basic_tests.addTest(loader.loadTestsFromModuleNames(
171
166
                ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
174
169
            reload(sys)
175
170
            sys.setdefaultencoding(default_encoding)
176
171
    return basic_tests
177