Skip to content

Commit 59729bd

Browse files
committed
Main line merge
2 parents 7141253 + d80d0fc commit 59729bd

File tree

4 files changed

+28
-43
lines changed

4 files changed

+28
-43
lines changed

bpython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626

2727
def embed(locals_=None, args=['-i', '-q'], banner=None):
2828
from bpython.cli import main
29-
return main(args, locals_)
29+
return main(args, locals_, banner)

bpython/args.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def error(self, msg):
2121
raise OptionParserFailed()
2222

2323

24-
def parse(args, extras=None):
24+
def parse(args, extras=None, ignore_stdin=False):
2525
"""Receive an argument list - if None, use sys.argv - parse all args and
2626
take appropriate action. Also receive optional extra options: this should
2727
be a tuple of (title, description, options)
@@ -87,8 +87,11 @@ def parse(args, extras=None):
8787
'See AUTHORS for detail.')
8888
raise SystemExit
8989

90-
if not (sys.stdin.isatty() and sys.stdout.isatty()):
91-
run_stdin(sys.stdin)
90+
if not ignore_stdin and not (sys.stdin.isatty() and sys.stdout.isatty()):
91+
interpreter = code.InteractiveInterpreter()
92+
interpreter.runsource(sys.stdin.read())
93+
raise SystemExit
94+
9295
path = os.path.expanduser('~/.bpythonrc')
9396
# migrating old configuration file
9497
if os.path.isfile(path):
@@ -110,11 +113,3 @@ def exec_code(interpreter, args):
110113
sys.path.insert(0, os.path.abspath(os.path.dirname(args[0])))
111114
interpreter.runcode(code_obj)
112115
sys.argv = old_argv
113-
114-
def run_stdin(stdin):
115-
"""
116-
Run code from a file-like object and exit.
117-
"""
118-
interpreter = code.InteractiveInterpreter()
119-
interpreter.runsource(stdin.read())
120-
raise SystemExit

bpython/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class CLIRepl(repl.Repl):
252252

253253
def __init__(self, scr, interp, statusbar, config, idle=None):
254254
repl.Repl.__init__(self, interp, config)
255-
interp.writetb = self.writetb
255+
self.interp.writetb = self.writetb
256256
self.scr = scr
257257
self.stdout_hist = ''
258258
self.list_win = newwin(get_colpair(config, 'background'), 1, 1, 1, 1)

bpython/gtk_.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@
5050
_COLORS = dict(b='blue', c='cyan', g='green', m='magenta', r='red',
5151
w='white', y='yellow', k='black', d='black')
5252

53-
def run_stdin(stdin):
54-
"""
55-
Overwrite stdin reader from args as GTK does not supply a stdin/stdout
56-
as a tty.
57-
"""
58-
pass
59-
60-
bpython.args.run_stdin = run_stdin
61-
6253
class ArgspecFormatter(object):
6354
"""
6455
Format an argspec using Pango markup language.
@@ -147,7 +138,6 @@ class Statusbar(gtk.Statusbar):
147138
"""Contains feedback messages"""
148139
def __init__(self):
149140
gtk.Statusbar.__init__(self)
150-
151141
self.context_id = self.get_context_id('Statusbar')
152142

153143
def message(self, s, n=3):
@@ -285,23 +275,27 @@ def __init__(self, config, statusbar):
285275
repl.Interaction.__init__(self, config, statusbar)
286276

287277
def confirm(self, q):
288-
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO, q)
289-
response = True if dialog.run() == gtk.RESPONSE_YES else False
278+
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
279+
gtk.BUTTONS_YES_NO, q)
280+
response = dialog.run()
290281
dialog.destroy()
291-
return response
282+
return response == gtk.RESPONSE_YES
292283

293284
def file_prompt(self, s):
294285
chooser = gtk.FileChooserDialog(title="File to save to",
295286
action=gtk.FILE_CHOOSER_ACTION_SAVE,
296-
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
287+
buttons=(gtk.STOCK_CANCEL,
288+
gtk.RESPONSE_CANCEL,
289+
gtk.STOCK_OPEN,
290+
gtk.RESPONSE_OK))
297291
chooser.set_default_response(gtk.RESPONSE_OK)
298292
chooser.set_current_name('test.py')
299293
chooser.set_current_folder(os.path.expanduser('~'))
300-
294+
301295
pyfilter = gtk.FileFilter()
302296
pyfilter.set_name("Python files")
303297
pyfilter.add_pattern("*.py")
304-
chooser.add_filter(pyfilter)
298+
chooser.add_filter(pyfilter)
305299

306300
allfilter = gtk.FileFilter()
307301
allfilter.set_name("All files")
@@ -331,7 +325,7 @@ class ReplWidget(gtk.TextView, repl.Repl):
331325
def __init__(self, interpreter, config):
332326
gtk.TextView.__init__(self)
333327
repl.Repl.__init__(self, interpreter, config)
334-
interpreter.writetb = self.writetb
328+
self.interp.writetb = self.writetb
335329
self.editing = Nested()
336330
self.reset_indent = False
337331
self.modify_font(pango.FontDescription(self.config.gtk_font))
@@ -627,12 +621,12 @@ def on_suggestion_selection_changed(self, selection, word):
627621
self.get_cursor_iter())
628622
self.text_buffer.insert_at_cursor(word)
629623

630-
631624
def do_paste(self, widget):
632625
clipboard = gtk.clipboard_get()
633626
paste_url = self.pastebin()
634-
clipboard.set_text(paste_url)
635-
clipboard.store()
627+
if paste_url:
628+
clipboard.set_text(paste_url)
629+
clipboard.store()
636630

637631
def do_write2file(self, widget):
638632
self.write2file()
@@ -644,7 +638,6 @@ def do_partial_paste(self, widget):
644638
pass
645639
else:
646640
self.pastebin(self.text_buffer.get_text(bounds[0], bounds[1]))
647-
648641

649642
def write(self, s):
650643
"""For overriding stdout defaults"""
@@ -663,8 +656,6 @@ def write(self, s):
663656
self.echo(s)
664657
self.s_hist.append(s.rstrip())
665658

666-
667-
668659
def prompt(self, more):
669660
"""
670661
Show the appropriate Python prompt.
@@ -755,7 +746,8 @@ def main(args=None):
755746
"Options specific to bpython's Gtk+ front end",
756747
[optparse.Option('--socket-id', dest='socket_id',
757748
type='int', help='Embed bpython')])
758-
config, options, exec_args = bpython.args.parse(args, gtk_options)
749+
config, options, exec_args = bpython.args.parse(args, gtk_options,
750+
True)
759751

760752
interpreter = repl.Interpreter(None, getpreferredencoding())
761753
repl_widget = ReplWidget(interpreter, config)
@@ -800,21 +792,20 @@ def main(args=None):
800792

801793
filem = gtk.MenuItem("File")
802794
filem.set_submenu(filemenu)
803-
804-
save = gtk.MenuItem("Save to file")
795+
796+
save = gtk.ImageMenuItem(gtk.STOCK_SAVE)
805797
save.connect("activate", repl_widget.do_write2file)
806798
filemenu.append(save)
807799

808-
809800
pastebin = gtk.MenuItem("Pastebin")
810801
pastebin.connect("activate", repl_widget.do_paste)
811802
filemenu.append(pastebin)
812803

813804
pastebin_partial = gtk.MenuItem("Pastebin selection")
814805
pastebin_partial.connect("activate", repl_widget.do_partial_paste)
815806
filemenu.append(pastebin_partial)
816-
817-
exit = gtk.MenuItem("Exit")
807+
808+
exit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
818809
exit.connect("activate", gtk.main_quit)
819810
filemenu.append(exit)
820811

@@ -824,7 +815,6 @@ def main(args=None):
824815

825816
container.pack_start(vbox, expand=False)
826817

827-
828818
# read from config
829819
sw = gtk.ScrolledWindow()
830820
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

0 commit comments

Comments
 (0)