50
50
_COLORS = dict (b = 'blue' , c = 'cyan' , g = 'green' , m = 'magenta' , r = 'red' ,
51
51
w = 'white' , y = 'yellow' , k = 'black' , d = 'black' )
52
52
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
-
62
53
class ArgspecFormatter (object ):
63
54
"""
64
55
Format an argspec using Pango markup language.
@@ -147,7 +138,6 @@ class Statusbar(gtk.Statusbar):
147
138
"""Contains feedback messages"""
148
139
def __init__ (self ):
149
140
gtk .Statusbar .__init__ (self )
150
-
151
141
self .context_id = self .get_context_id ('Statusbar' )
152
142
153
143
def message (self , s , n = 3 ):
@@ -285,23 +275,27 @@ def __init__(self, config, statusbar):
285
275
repl .Interaction .__init__ (self , config , statusbar )
286
276
287
277
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 ()
290
281
dialog .destroy ()
291
- return response
282
+ return response == gtk . RESPONSE_YES
292
283
293
284
def file_prompt (self , s ):
294
285
chooser = gtk .FileChooserDialog (title = "File to save to" ,
295
286
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 ))
297
291
chooser .set_default_response (gtk .RESPONSE_OK )
298
292
chooser .set_current_name ('test.py' )
299
293
chooser .set_current_folder (os .path .expanduser ('~' ))
300
-
294
+
301
295
pyfilter = gtk .FileFilter ()
302
296
pyfilter .set_name ("Python files" )
303
297
pyfilter .add_pattern ("*.py" )
304
- chooser .add_filter (pyfilter )
298
+ chooser .add_filter (pyfilter )
305
299
306
300
allfilter = gtk .FileFilter ()
307
301
allfilter .set_name ("All files" )
@@ -331,7 +325,7 @@ class ReplWidget(gtk.TextView, repl.Repl):
331
325
def __init__ (self , interpreter , config ):
332
326
gtk .TextView .__init__ (self )
333
327
repl .Repl .__init__ (self , interpreter , config )
334
- interpreter .writetb = self .writetb
328
+ self . interp .writetb = self .writetb
335
329
self .editing = Nested ()
336
330
self .reset_indent = False
337
331
self .modify_font (pango .FontDescription (self .config .gtk_font ))
@@ -627,12 +621,12 @@ def on_suggestion_selection_changed(self, selection, word):
627
621
self .get_cursor_iter ())
628
622
self .text_buffer .insert_at_cursor (word )
629
623
630
-
631
624
def do_paste (self , widget ):
632
625
clipboard = gtk .clipboard_get ()
633
626
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 ()
636
630
637
631
def do_write2file (self , widget ):
638
632
self .write2file ()
@@ -644,7 +638,6 @@ def do_partial_paste(self, widget):
644
638
pass
645
639
else :
646
640
self .pastebin (self .text_buffer .get_text (bounds [0 ], bounds [1 ]))
647
-
648
641
649
642
def write (self , s ):
650
643
"""For overriding stdout defaults"""
@@ -663,8 +656,6 @@ def write(self, s):
663
656
self .echo (s )
664
657
self .s_hist .append (s .rstrip ())
665
658
666
-
667
-
668
659
def prompt (self , more ):
669
660
"""
670
661
Show the appropriate Python prompt.
@@ -755,7 +746,8 @@ def main(args=None):
755
746
"Options specific to bpython's Gtk+ front end" ,
756
747
[optparse .Option ('--socket-id' , dest = 'socket_id' ,
757
748
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 )
759
751
760
752
interpreter = repl .Interpreter (None , getpreferredencoding ())
761
753
repl_widget = ReplWidget (interpreter , config )
@@ -800,21 +792,20 @@ def main(args=None):
800
792
801
793
filem = gtk .MenuItem ("File" )
802
794
filem .set_submenu (filemenu )
803
-
804
- save = gtk .MenuItem ( "Save to file" )
795
+
796
+ save = gtk .ImageMenuItem ( gtk . STOCK_SAVE )
805
797
save .connect ("activate" , repl_widget .do_write2file )
806
798
filemenu .append (save )
807
799
808
-
809
800
pastebin = gtk .MenuItem ("Pastebin" )
810
801
pastebin .connect ("activate" , repl_widget .do_paste )
811
802
filemenu .append (pastebin )
812
803
813
804
pastebin_partial = gtk .MenuItem ("Pastebin selection" )
814
805
pastebin_partial .connect ("activate" , repl_widget .do_partial_paste )
815
806
filemenu .append (pastebin_partial )
816
-
817
- exit = gtk .MenuItem ( "Exit" )
807
+
808
+ exit = gtk .ImageMenuItem ( gtk . STOCK_QUIT )
818
809
exit .connect ("activate" , gtk .main_quit )
819
810
filemenu .append (exit )
820
811
@@ -824,7 +815,6 @@ def main(args=None):
824
815
825
816
container .pack_start (vbox , expand = False )
826
817
827
-
828
818
# read from config
829
819
sw = gtk .ScrolledWindow ()
830
820
sw .set_policy (gtk .POLICY_NEVER , gtk .POLICY_AUTOMATIC )
0 commit comments