| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1af2e61 commit 00e7cd6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ def parse(args, extras=None): | |||
| 28 | 28 | 'A full description of what these options are for', | |
| 29 | 29 | [optparse.Option('-f', action='store_true', dest='f', help='Explode'), | |
| 30 | 30 | optparse.Option('-l', action='store_true', dest='l', help='Love')])) | |
| 31 | - | ||
| 31 | + | ||
| 32 | 32 | ||
| 33 | 33 | Return a tuple of (config, options, exec_args) wherein "config" is the | |
| 34 | 34 | config object either parsed from a default/specified config file or default | |
@@ -56,16 +56,17 @@ def parse(args, extras=None): | |||
| 56 | 56 | if extras is not None: | |
| 57 | 57 | extras_group = OptionGroup(parser, extras[0], extras[1]) | |
| 58 | 58 | for option in extras[2]: | |
| 59 | - extras_group.option_list.append(option) | ||
| 59 | + extras_group.add_option(option) | ||
| 60 | 60 | parser.add_option_group(extras_group) | |
| 61 | 61 | ||
| 62 | 62 | all_args = set(parser._short_opt.keys() + parser._long_opt.keys()) | |
| 63 | - if args and not all_args.intersection(args): | ||
| 63 | + if args and not all_args.intersection(arg.split('=')[0] for arg in args): | ||
| 64 | 64 | # Just let Python handle this | |
| 65 | 65 | os.execv(sys.executable, [sys.executable] + args) | |
| 66 | 66 | else: | |
| 67 | 67 | # Split args in bpython args and args for the executed file | |
| 68 | - real_args = list(takewhile(lambda arg: arg in all_args, args)) | ||
| 68 | + real_args = list(takewhile(lambda arg: arg.split('=')[0] in all_args, | ||
| 69 | + args)) | ||
| 69 | 70 | exec_args = args[len(real_args):] | |
| 70 | 71 | ||
| 71 | 72 | options, args = parser.parse_args(real_args) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,16 +29,16 @@ | |||
| 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments