/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: Jelmer Vernooij
  • Date: 2007-03-23 13:43:29 UTC
  • mfrom: (173.1.3 trunk)
  • Revision ID: jelmer@samba.org-20070323134329-xx25fcg5hsh7noat
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    bzrlib.ui.ui_factory = GtkUIFactory()
88
88
 
89
89
 
90
 
class cmd_gbranch(Command):
 
90
class GTKCommand(Command):
 
91
    """Abstract class providing GTK specific run commands."""
 
92
 
 
93
    def open_display(self):
 
94
        pygtk = import_pygtk()
 
95
        try:
 
96
            import gtk
 
97
        except RuntimeError, e:
 
98
            if str(e) == "could not open display":
 
99
                raise NoDisplayError
 
100
        set_ui_factory()
 
101
        return gtk
 
102
 
 
103
    def run(self):
 
104
        self.open_display()
 
105
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
106
        dialog.run()
 
107
 
 
108
 
 
109
class cmd_gbranch(GTKCommand):
91
110
    """GTK+ branching.
92
111
    
93
112
    """
94
113
 
95
 
    def run(self):
96
 
        pygtk = import_pygtk()
97
 
        try:
98
 
            import gtk
99
 
        except RuntimeError, e:
100
 
            if str(e) == "could not open display":
101
 
                raise NoDisplayError
102
 
 
 
114
    def get_gtk_dialog(self, path):
103
115
        from bzrlib.plugins.gtk.branch import BranchDialog
104
 
 
105
 
        set_ui_factory()
106
 
        dialog = BranchDialog(os.path.abspath('.'))
107
 
        dialog.run()
108
 
 
109
 
class cmd_gcheckout(Command):
 
116
        return BranchDialog(path)
 
117
 
 
118
 
 
119
class cmd_gcheckout(GTKCommand):
110
120
    """ GTK+ checkout.
111
121
    
112
122
    """
113
123
    
114
 
    def run(self):
115
 
        pygtk = import_pygtk()
116
 
        try:
117
 
            import gtk
118
 
        except RuntimeError, e:
119
 
            if str(e) == "could not open display":
120
 
                raise NoDisplayError
121
 
 
 
124
    def get_gtk_dialog(self, path):
122
125
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
123
 
 
124
 
        set_ui_factory()
125
 
        dialog = CheckoutDialog(os.path.abspath('.'))
126
 
        dialog.run()
127
 
 
128
 
 
129
 
class cmd_gpush(Command):
 
126
        return CheckoutDialog(path)
 
127
 
 
128
 
 
129
 
 
130
class cmd_gpush(GTKCommand):
130
131
    """ GTK+ push.
131
132
    
132
133
    """
134
135
 
135
136
    def run(self, location="."):
136
137
        (br, path) = branch.Branch.open_containing(location)
137
 
 
138
 
        pygtk = import_pygtk()
139
 
        try:
140
 
            import gtk
141
 
        except RuntimeError, e:
142
 
            if str(e) == "could not open display":
143
 
                raise NoDisplayError
144
 
 
 
138
        self.open_display()
145
139
        from push import PushDialog
146
 
 
147
 
        set_ui_factory()
148
140
        dialog = PushDialog(br)
149
141
        dialog.run()
150
142
 
151
143
 
152
 
class cmd_gdiff(Command):
 
144
 
 
145
class cmd_gdiff(GTKCommand):
153
146
    """Show differences in working tree in a GTK+ Window.
154
147
    
155
148
    Otherwise, all changes for the tree are listed.
242
235
            br.unlock()
243
236
 
244
237
 
245
 
class cmd_gannotate(Command):
 
238
class cmd_gannotate(GTKCommand):
246
239
    """GTK+ annotate.
247
240
    
248
241
    Browse changes to FILENAME line by line in a GTK+ window.
259
252
    aliases = ["gblame", "gpraise"]
260
253
    
261
254
    def run(self, filename, all=False, plain=False, line='1', revision=None):
262
 
        pygtk = import_pygtk()
263
 
 
264
 
        try:
265
 
            import gtk
266
 
        except RuntimeError, e:
267
 
            if str(e) == "could not open display":
268
 
                raise NoDisplayError
269
 
        set_ui_factory()
 
255
        self.open_display()
270
256
 
271
257
        try:
272
258
            line = int(line)
314
300
                wt.unlock()
315
301
 
316
302
 
317
 
class cmd_gcommit(Command):
 
303
 
 
304
class cmd_gcommit(GTKCommand):
318
305
    """GTK+ commit dialog
319
306
 
320
307
    Graphical user interface for committing revisions"""
325
312
 
326
313
    def run(self, filename=None):
327
314
        import os
328
 
        pygtk = import_pygtk()
329
 
 
330
 
        try:
331
 
            import gtk
332
 
        except RuntimeError, e:
333
 
            if str(e) == "could not open display":
334
 
                raise NoDisplayError
335
 
 
336
 
        set_ui_factory()
 
315
        self.open_display()
337
316
        from commit import CommitDialog
338
317
        from bzrlib.errors import (BzrCommandError,
339
318
                                   NotBranchError,
357
336
        commit.run()
358
337
 
359
338
 
360
 
class cmd_gstatus(Command):
 
339
 
 
340
class cmd_gstatus(GTKCommand):
361
341
    """GTK+ status dialog
362
342
 
363
343
    Graphical user interface for showing status 
369
349
 
370
350
    def run(self, path='.'):
371
351
        import os
372
 
        pygtk = import_pygtk()
373
 
 
374
 
        try:
375
 
            import gtk
376
 
        except RuntimeError, e:
377
 
            if str(e) == "could not open display":
378
 
                raise NoDisplayError
379
 
 
380
 
        set_ui_factory()
 
352
        self.open_display()
381
353
        from status import StatusDialog
382
354
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
383
355
        status = StatusDialog(wt, wt_path)
385
357
        status.run()
386
358
 
387
359
 
388
 
class cmd_gconflicts(Command):
 
360
 
 
361
class cmd_gconflicts(GTKCommand):
389
362
    """ GTK+ push.
390
363
    
391
364
    """
392
365
    def run(self):
393
366
        (wt, path) = workingtree.WorkingTree.open_containing('.')
394
 
        
395
 
        pygtk = import_pygtk()
396
 
        try:
397
 
            import gtk
398
 
        except RuntimeError, e:
399
 
            if str(e) == "could not open display":
400
 
                raise NoDisplayError
401
 
 
 
367
        self.open_display()
402
368
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
403
 
 
404
 
        set_ui_factory()
405
369
        dialog = ConflictsDialog(wt)
406
370
        dialog.run()
407
371
 
408
372
 
409
 
class cmd_gpreferences(Command):
 
373
 
 
374
class cmd_gpreferences(GTKCommand):
410
375
    """ GTK+ preferences dialog.
411
376
 
412
377
    """
413
378
    def run(self):
414
 
        pygtk = import_pygtk()
415
 
        try:
416
 
            import gtk
417
 
        except RuntimeError, e:
418
 
            if str(e) == "could not open display":
419
 
                raise NoDisplayError
420
 
 
 
379
        self.open_display()
421
380
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
422
 
 
423
 
        set_ui_factory()
424
381
        dialog = PreferencesWindow()
425
382
        dialog.run()
426
383
 
479
436
for cmd in commands:
480
437
    register_command(cmd)
481
438
 
 
439
 
 
440
class cmd_commit_notify(GTKCommand):
 
441
    """Run the bzr commit notifier.
 
442
 
 
443
    This is a background program which will pop up a notification on the users
 
444
    screen when a commit occurs.
 
445
    """
 
446
 
 
447
    def run(self):
 
448
        gtk = self.open_display()
 
449
        import cgi
 
450
        import dbus
 
451
        import dbus.service
 
452
        import pynotify
 
453
        from bzrlib.bzrdir import BzrDir
 
454
        from bzrlib import errors
 
455
        from bzrlib.osutils import format_date
 
456
        from bzrlib.transport import get_transport
 
457
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
458
            import dbus.glib
 
459
        from bzrlib.plugins.dbus import activity
 
460
        bus = dbus.SessionBus()
 
461
        # get the object so we can subscribe to callbacks from it.
 
462
        broadcast_service = bus.get_object(
 
463
            activity.Broadcast.DBUS_NAME,
 
464
            activity.Broadcast.DBUS_PATH)
 
465
        def catch_branch(revision_id, url):
 
466
            try:
 
467
                if isinstance(revision_id, unicode):
 
468
                    revision_id = revision_id.encode('utf8')
 
469
                transport = get_transport(url)
 
470
                try:
 
471
                    transport.local_abspath('.')
 
472
                except errors.TransportNotPossible:
 
473
                    # dont show remote urls for now.
 
474
                    return
 
475
                # here we should:
 
476
                a_dir = BzrDir.open_from_transport(transport)
 
477
                branch = a_dir.open_branch()
 
478
                revno = branch.revision_id_to_revno(revision_id)
 
479
                revision = branch.repository.get_revision(revision_id)
 
480
                summary = 'New revision %d in %s' % (revno, url)
 
481
                body  = 'Committer: %s\n' % revision.committer
 
482
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
483
                    revision.timezone)
 
484
                body += '\n'
 
485
                body += revision.message
 
486
                body = cgi.escape(body)
 
487
                #print repr(body)
 
488
                nw = pynotify.Notification(summary, body)
 
489
                nw.set_timeout(5000)
 
490
                nw.show()
 
491
            except Exception, e:
 
492
                print e
 
493
                raise
 
494
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
495
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
496
        pynotify.init("bzr commit-notify")
 
497
        gtk.main()
 
498
 
 
499
register_command(cmd_commit_notify)
 
500
 
 
501
 
482
502
import gettext
483
503
gettext.install('olive-gtk')
484
504
 
 
505
 
485
506
class NoDisplayError(BzrCommandError):
486
507
    """gtk could not find a proper display"""
487
508
 
488
509
    def __str__(self):
489
510
        return "No DISPLAY. Unable to run GTK+ application."
490
511
 
 
512
 
491
513
def test_suite():
492
514
    from unittest import TestSuite
493
515
    import tests