##// END OF EJS Templates
cleaning...
ldufrechou -
Show More
@@ -180,7 +180,7 b' class NonBlockingIPShell(object):'
180 """
180 """
181
181
182 self._line_to_execute = line
182 self._line_to_execute = line
183
183 #we launch the ipython line execution in a thread to make it interruptible
184 self.ce = _CodeExecutor(self,self._afterExecute)
184 self.ce = _CodeExecutor(self,self._afterExecute)
185 self.ce.start()
185 self.ce.start()
186
186
@@ -40,7 +40,7 b' except Exception,e:'
40 raise "Error importing IPython (%s)" % str(e)
40 raise "Error importing IPython (%s)" % str(e)
41
41
42
42
43 from non_blocking_ip_shell import *
43 from NonBlockingIPShell import *
44
44
45 class WxNonBlockingIPShell(NonBlockingIPShell):
45 class WxNonBlockingIPShell(NonBlockingIPShell):
46 '''
46 '''
@@ -54,28 +54,28 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
54
54
55 #user_ns['addGUIShortcut'] = self.addGUIShortcut
55 #user_ns['addGUIShortcut'] = self.addGUIShortcut
56 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
56 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
57 cin, cout, cerr,
57 cin, cout, cerr,
58 ask_exit_handler)
58 ask_exit_handler)
59
59
60 # This creates a new Event class and a EVT binder function
60 # This creates a new Event class and a EVT binder function
61 (self.IPythonAskExitEvent, EVT_IP_ASK_EXIT) = wx.lib.newevent.NewEvent()
61 (self.IPythonAskExitEvent, EVT_IP_ASK_EXIT) = wx.lib.newevent.NewEvent()
62 (self.IPythonAddButtonEvent, EVT_IP_ADD_BUTTON_EXIT) = \
62 #(self.IPythonAddButtonEvent, EVT_IP_ADD_BUTTON_EXIT) = \
63 wx.lib.newevent.NewEvent()
63 # wx.lib.newevent.NewEvent()
64 (self.IPythonExecuteDoneEvent, EVT_IP_EXECUTE_DONE) = \
64 (self.IPythonExecuteDoneEvent, EVT_IP_EXECUTE_DONE) = \
65 wx.lib.newevent.NewEvent()
65 wx.lib.newevent.NewEvent()
66
66
67 wx_instance.Bind(EVT_IP_ASK_EXIT, wx_instance.ask_exit_handler)
67 wx_instance.Bind(EVT_IP_ASK_EXIT, wx_instance.ask_exit_handler)
68 wx_instance.Bind(EVT_IP_ADD_BUTTON_EXIT, wx_instance.add_button_handler)
68 #wx_instance.Bind(EVT_IP_ADD_BUTTON_EXIT, wx_instance.add_button_handler)
69 wx_instance.Bind(EVT_IP_EXECUTE_DONE, wx_instance.evtStateExecuteDone)
69 wx_instance.Bind(EVT_IP_EXECUTE_DONE, wx_instance.evtStateExecuteDone)
70
70
71 self.wx_instance = wx_instance
71 self.wx_instance = wx_instance
72 self._IP.ask_exit = self._askExit
72 self._IP.ask_exit = self._askExit
73
73
74 def addGUIShortcut(self,text,func):
74 #def addGUIShortcut(self,text,func):
75 evt = self.IPythonAddButtonEvent(
75 # evt = self.IPythonAddButtonEvent(
76 button_info={ 'text':text,
76 # button_info={ 'text':text,
77 'func':self.wx_instance.doExecuteLine(func)})
77 # 'func':self.wx_instance.doExecuteLine(func)})
78 wx.PostEvent(self.wx_instance, evt)
78 # wx.PostEvent(self.wx_instance, evt)
79
79
80 def _askExit(self):
80 def _askExit(self):
81 evt = self.IPythonAskExitEvent()
81 evt = self.IPythonAskExitEvent()
@@ -480,7 +480,7 b' class WxIPythonViewPanel(wx.Panel):'
480 '''
480 '''
481 wx.Panel.__init__(self,parent,-1)
481 wx.Panel.__init__(self,parent,-1)
482
482
483 ### IPython thread instanciation ###
483 ### IPython non blocking shell instanciation ###
484 self.cout = StringIO()
484 self.cout = StringIO()
485
485
486 self.add_button_handler = add_button_handler
486 self.add_button_handler = add_button_handler
@@ -492,6 +492,7 b' class WxIPythonViewPanel(wx.Panel):'
492 self.IP = WxNonBlockingIPShell(self,
492 self.IP = WxNonBlockingIPShell(self,
493 cout=self.cout,cerr=self.cout,
493 cout=self.cout,cerr=self.cout,
494 ask_exit_handler = ask_exit_handler)
494 ask_exit_handler = ask_exit_handler)
495
495 ### IPython wx console view instanciation ###
496 ### IPython wx console view instanciation ###
496 #If user didn't defined an intro text, we create one for him
497 #If user didn't defined an intro text, we create one for him
497 #If you really wnat an empty intrp just call wxIPythonViewPanel with intro=''
498 #If you really wnat an empty intrp just call wxIPythonViewPanel with intro=''
@@ -518,30 +519,10 b' class WxIPythonViewPanel(wx.Panel):'
518 #and we focus on the widget :)
519 #and we focus on the widget :)
519 self.SetFocus()
520 self.SetFocus()
520
521
521 ### below are the thread communication variable ###
522 #widget state management (for key handling different cases)
522 # the IPython thread is managed via unidirectional communication.
523 self.setCurrentState('IDLE')
523 # It's a thread slave that can't interact by itself with the GUI.
524 # When the GUI event loop is done runStateMachine() is called and the thread sate is then
525 # managed.
526
527 #Initialize the state machine #kept for information
528 #self.states = ['IDLE',
529 # 'DO_EXECUTE_LINE',
530 # 'WAIT_END_OF_EXECUTION',
531 # 'SHOW_DOC',
532 # 'SHOW_PROMPT']
533
534 self.cur_state = 'IDLE'
535 self.pager_state = 'DONE'
524 self.pager_state = 'DONE'
536 #wx.CallAfter(self.runStateMachine)
537
538 # This creates a new Event class and a EVT binder function
539 #(self.AskExitEvent, EVT_ASK_EXIT) = wx.lib.newevent.NewEvent()
540 #(self.AddButtonEvent, EVT_ADDBUTTON_EXIT) = wx.lib.newevent.NewEvent()
541
542
525
543 #self.Bind(wx.EVT_IDLE, self.runStateMachine)
544
545 def __del__(self):
526 def __del__(self):
546 WxConsoleView.__del__()
527 WxConsoleView.__del__()
547
528
@@ -554,27 +535,29 b' class WxIPythonViewPanel(wx.Panel):'
554 #print >>sys.__stdout__,"command:",line
535 #print >>sys.__stdout__,"command:",line
555 self.IP.doExecute(line.replace('\t',' '*4))
536 self.IP.doExecute(line.replace('\t',' '*4))
556 self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
537 self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
557 self.cur_state = 'WAIT_END_OF_EXECUTION'
538 self.setCurrentState('WAIT_END_OF_EXECUTION')
558
539
559
540
560 def evtStateExecuteDone(self,evt):
541 def evtStateExecuteDone(self,evt):
561 self.doc = self.IP.getDocText()
542 self.doc = self.IP.getDocText()
562 self.help = self.IP.getHelpText()
543 self.help = self.IP.getHelpText()
563 if self.doc:
544 if self.doc:
564 self.pager_state = 'INIT'
545 self.pager_lines = self.doc[7:].split('\n')
565 self.cur_state = 'SHOW_DOC'
546 self.pager_state = 'INIT'
547 self.setCurrentState('SHOW_DOC')
566 self.pager(self.doc)
548 self.pager(self.doc)
567 #if self.pager_state == 'DONE':
549
568 if self.help:
550 if self.help:
569 self.pager_state = 'INIT_HELP'
551 self.pager_lines = self.help.split('\n')
570 self.cur_state = 'SHOW_DOC'
552 self.pager_state = 'INIT'
553 self.setCurrentState('SHOW_DOC')
571 self.pager(self.help)
554 self.pager(self.help)
572
555
573 else:
556 else:
574 self.stateShowPrompt()
557 self.stateShowPrompt()
575
558
576 def stateShowPrompt(self):
559 def stateShowPrompt(self):
577 self.cur_state = 'SHOW_PROMPT'
560 self.setCurrentState('SHOW_PROMPT')
578 self.text_ctrl.setPrompt(self.IP.getPrompt())
561 self.text_ctrl.setPrompt(self.IP.getPrompt())
579 self.text_ctrl.setIndentation(self.IP.getIndentation())
562 self.text_ctrl.setIndentation(self.IP.getIndentation())
580 self.text_ctrl.setPromptCount(self.IP.getPromptCount())
563 self.text_ctrl.setPromptCount(self.IP.getPromptCount())
@@ -583,55 +566,12 b' class WxIPythonViewPanel(wx.Panel):'
583 self.text_ctrl.showReturned(rv)
566 self.text_ctrl.showReturned(rv)
584 self.cout.truncate(0)
567 self.cout.truncate(0)
585 self.IP.initHistoryIndex()
568 self.IP.initHistoryIndex()
586 self.cur_state = 'IDLE'
569 self.setCurrentState('IDLE')
587
588 ## def runStateMachine(self,event):
589 ## #print >>sys.__stdout__,"state:",self.cur_state
590 ## self.updateStatusTracker(self.cur_state)
591 ##
592 ## #if self.cur_state == 'DO_EXECUTE_LINE':
593 ## # self.doExecuteLine()
594 ##
595 ## if self.cur_state == 'WAIT_END_OF_EXECUTION':
596 ## if self.IP.isExecuteDone():
597 ## #self.button = self.IP.getAddButton()
598 ## #if self.IP.getAskExit():
599 ## # evt = self.AskExitEvent()
600 ## # wx.PostEvent(self, evt)
601 ## # self.IP.clearAskExit()
602 ## self.doc = self.IP.getDocText()
603 ## if self.doc:
604 ## self.pager_state = 'INIT'
605 ## self.cur_state = 'SHOW_DOC'
606 ## #if self.button:
607 ## #self.IP.doExecute('print "cool"')#self.button['func'])
608 ## #self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
609 ##
610 ## # self.button['func']='print "cool!"'
611 ## # self.add_button_handler(self.button)
612 ## # self.IP.shortcutProcessed()
613 ##
614 ## else:
615 ## self.cur_state = 'SHOW_PROMPT'
616 ##
617 ## if self.cur_state == 'SHOW_PROMPT':
618 ## self.text_ctrl.setPrompt(self.IP.getPrompt())
619 ## self.text_ctrl.setIndentation(self.IP.getIndentation())
620 ## self.text_ctrl.setPromptCount(self.IP.getPromptCount())
621 ## rv = self.cout.getvalue()
622 ## if rv: rv = rv.strip('\n')
623 ## self.text_ctrl.showReturned(rv)
624 ## self.cout.truncate(0)
625 ## self.IP.initHistoryIndex()
626 ## self.cur_state = 'IDLE'
627 ##
628 ## if self.cur_state == 'SHOW_DOC':
629 ## self.pager(self.doc)
630 ## if self.pager_state == 'DONE':
631 ## self.cur_state = 'SHOW_PROMPT'
632 ##
633 ## event.Skip()
634
570
571 def setCurrentState(self, state):
572 self.cur_state = state
573 self.updateStatusTracker(self.cur_state)
574
635 #---------------------------- IPython pager ---------------------------------------
575 #---------------------------- IPython pager ---------------------------------------
636 def pager(self,text):#,start=0,screen_lines=0,pager_cmd = None):
576 def pager(self,text):#,start=0,screen_lines=0,pager_cmd = None):
637 if self.pager_state == 'WAITING':
577 if self.pager_state == 'WAITING':
@@ -640,22 +580,12 b' class WxIPythonViewPanel(wx.Panel):'
640
580
641 if self.pager_state == 'INIT':
581 if self.pager_state == 'INIT':
642 #print >>sys.__stdout__,"PAGER state:",self.pager_state
582 #print >>sys.__stdout__,"PAGER state:",self.pager_state
643 self.pager_lines = text[7:].split('\n')
583 self.pager_nb_lines = len(self.pager_lines)
644 self.pager_nb_lines = len(self.pager_lines)
645 self.pager_index = 0
584 self.pager_index = 0
646 self.pager_do_remove = False
585 self.pager_do_remove = False
647 self.text_ctrl.write('\n')
586 self.text_ctrl.write('\n')
648 self.pager_state = 'PROCESS_LINES'
587 self.pager_state = 'PROCESS_LINES'
649
588
650 if self.pager_state == 'INIT_HELP':
651 #print >>sys.__stdout__,"HELP PAGER state:",self.pager_state
652 self.pager_lines = text[:].split('\n')
653 self.pager_nb_lines = len(self.pager_lines)
654 self.pager_index = 0
655 self.pager_do_remove = False
656 self.text_ctrl.write('\n')
657 self.pager_state = 'PROCESS_LINES'
658
659 if self.pager_state == 'PROCESS_LINES':
589 if self.pager_state == 'PROCESS_LINES':
660 #print >>sys.__stdout__,"PAGER state:",self.pager_state
590 #print >>sys.__stdout__,"PAGER state:",self.pager_state
661 if self.pager_do_remove == True:
591 if self.pager_do_remove == True:
@@ -711,7 +641,7 b' class WxIPythonViewPanel(wx.Panel):'
711 if event.KeyCode == wx.WXK_RETURN:
641 if event.KeyCode == wx.WXK_RETURN:
712 if self.cur_state == 'IDLE':
642 if self.cur_state == 'IDLE':
713 #we change the state ot the state machine
643 #we change the state ot the state machine
714 self.cur_state = 'DO_EXECUTE_LINE'
644 self.setCurrentState('DO_EXECUTE_LINE')
715 self.stateDoExecuteLine()
645 self.stateDoExecuteLine()
716 return
646 return
717 if self.pager_state == 'WAITING':
647 if self.pager_state == 'WAITING':
General Comments 0
You need to be logged in to leave comments. Login now