|
29 | 29 |
|
30 | 30 | from __future__ import with_statement |
31 | 31 | import inspect |
32 | | -import sys |
| 32 | +import optparse |
33 | 33 | import os |
| 34 | +import sys |
34 | 35 | from locale import LC_ALL, getpreferredencoding, setlocale |
35 | 36 |
|
36 | 37 | import gobject |
37 | 38 | import gtk |
38 | 39 | import pango |
39 | 40 |
|
40 | 41 | from bpython import importcompletion, repl |
41 | | -from bpython.config import Struct, loadini |
42 | 42 | from bpython.formatter import theme_map |
43 | 43 | import bpython.args |
44 | 44 |
|
@@ -623,40 +623,49 @@ def init_import_completion(): |
623 | 623 | def main(args=None): |
624 | 624 |
|
625 | 625 | setlocale(LC_ALL, '') |
626 | | - config = Struct() |
627 | 626 |
|
628 | | - config, options, exec_args = bpython.args.parse(args) |
629 | | - |
630 | | - loadini(config, '~/.bpython/config', options.config) |
| 627 | + gtk_options = ('gtk-specific options', |
| 628 | + "Options specific to bpython's Gtk+ front end", |
| 629 | + [optparse.Option('--socket-id', dest='socket_id', |
| 630 | + type='int', help='Embed bpython')]) |
| 631 | + config, options, exec_args = bpython.args.parse(args, gtk_options) |
631 | 632 |
|
632 | 633 | interpreter = repl.Interpreter(None, getpreferredencoding()) |
633 | 634 | repl_widget = ReplWidget(interpreter, config) |
634 | 635 |
|
635 | | - # sys.stderr = repl_widget |
| 636 | + sys.stderr = repl_widget |
636 | 637 | sys.stdout = repl_widget |
637 | 638 |
|
638 | | - gobject.idle_add(init_import_completion) |
| 639 | +# repl.startup() |
639 | 640 |
|
640 | | - window = gtk.Window() |
| 641 | + gobject.idle_add(init_import_completion) |
641 | 642 |
|
642 | | - # branding |
| 643 | + if not options.socket_id: |
| 644 | + print options.socket_id |
| 645 | + parent = gtk.Window() |
| 646 | + parent.connect('delete-event', lambda widget, event: gtk.main_quit()) |
643 | 647 |
|
644 | | - # fix icon to be distributed and loaded from the correct path |
645 | | - icon = gtk.gdk.pixbuf_new_from_file(os.path.join(os.path.dirname(__file__), |
646 | | - 'logo.png')) |
| 648 | + # branding |
| 649 | + # fix icon to be distributed and loaded from the correct path |
| 650 | + icon = gtk.gdk.pixbuf_new_from_file(os.path.join(os.path.dirname(__file__), |
| 651 | + 'logo.png')) |
647 | 652 |
|
648 | | - window.set_title('bpython') |
649 | | - window.set_icon(icon) |
650 | | - window.resize(600, 300) |
| 653 | + parent.set_title('bpython') |
| 654 | + parent.set_icon(icon) |
| 655 | + parent.resize(600, 300) |
| 656 | + else: |
| 657 | + parent = gtk.Plug(options.socket_id) |
| 658 | + parent.connect('destroy', gtk.main_quit) |
651 | 659 |
|
652 | 660 | # read from config |
653 | 661 |
|
654 | 662 | sw = gtk.ScrolledWindow() |
655 | 663 | sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) |
656 | 664 | sw.add(repl_widget) |
657 | | - window.add(sw) |
658 | | - window.show_all() |
659 | | - window.connect('delete-event', lambda widget, event: gtk.main_quit()) |
| 665 | + parent.add(sw) |
| 666 | + parent.show_all() |
| 667 | + parent.connect('delete-event', lambda widget, event: gtk.main_quit()) |
| 668 | + |
660 | 669 | gtk.main() |
661 | 670 |
|
662 | 671 |
|
|
0 commit comments