Example #1
0
    def set_delay(self, delay):
        '''Sets the delay value between robot actions.'''
        if delay >= 0 and delay <= 10:
            self._delay = delay
        else:
            mesg = _("""Setting delay failed.
Accepted values are between 0 and 10.""")
            dialogs.messageDialog(mesg, _("Error"))
Example #2
0
    def set_delay(self, delay):
        '''Sets the delay value between robot actions.'''
        if delay >= 0 and delay <= 10:
            self._delay = delay
        else:
            mesg = _("""Setting delay failed.
Accepted values are between 0 and 10.""")
            dialogs.messageDialog(mesg, _("Error"))
Example #3
0
 def execute_program(self):
     self.clear_trace()
     if self.code == "":
         dialogs.messageDialog(_("All done!"),
                               _("No instruction to execute."))
         return
     self.parent.outputWindow.redirect()
     if 'robot' in self.parent.world.robot_dict:
         time_delay = [5, 1, 0.6, 0.3, 0.1, 0.06, 0.03, 0.01, 0.]
         selected = self.parent.slider_speed.GetValue()
         self.parent.world.robot_dict['robot'].delay = time_delay[selected]
     self.isRunning = True
     MyGlobals = {
         'move': self.move,
         'turn_left': self.turn_left,
         'pick_beeper': self.pick_beeper,
         'put_beeper': self.put_beeper,
         'set_trace_style': self.set_trace_style,
         'set_delay': self.set_delay,
         'RefurbishedRobot': RefurbishedRobot,
         'UsedRobot': UsedRobot,
         'turn_off': self.turn_off,
         'repeat': self.repeat,
         'set_line_number': self.set_line_number,
         'front_is_clear': self.front_is_clear,
         'left_is_clear': self.left_is_clear,
         'right_is_clear': self.right_is_clear,
         'on_beeper': self.next_to_a_beeper,  # new, as suggested
         'next_to_a_beeper':
         self.next_to_a_beeper,  # compatibility with old code
         'carries_beepers': self.carries_beepers,
         'facing_north': self.facing_north,
         'HitWallException': dialogs.HitWallException,
         'setBackgroundColour': self.setBackgroundColour,
         'input_int': self.inputInt,
         'input_string': self.inputString
     }
     arg = self.parent.status_bar.running_field, _("Program is running")
     event_manager.SendCustomEvent(self.parent, arg)
     try:
         try:
             sys.settrace(self.my_trace)
             exec self.code in MyGlobals
             sys.settrace(None)
             self.world.DoDrawing()
             self.WorldDisplay.drawImage()
             self.WorldDisplay.Refresh()
             raise dialogs.NoTurnOffException(
                 _("You forgot to turn me off!"))
         except dialogs.NoTurnOffException, mesg:
             dialogs.NoTurnOffError(mesg)
         except dialogs.NormalEnd, mesg:
             dialogs.NormalEndDialog(mesg)
Example #4
0
 def execute_program(self):
     self.clear_trace()
     if self.code=="":
         dialogs.messageDialog(_("All done!"),
                 _("No instruction to execute."))
         return
     self.parent.outputWindow.redirect()
     self.update_slider_speed(None)
     if 'robot' in self.robot_dict:
         self.robot_dict['robot'].set_trace_style(5, "sea green")
     self.isRunning = True
     MyGlobals = {'move': self.move,
                  'turn_left': self.turn_left,
                  'turn_right': self.turn_right,
                  'grab_beeper': self.pick_beeper, # new
                  'pick_beeper': self.pick_beeper, # compatibility
                  'drop_beeper': self.put_beeper,  # new
                  'put_beeper': self.put_beeper,   # compatibility
                  'set_trace_style': self.set_trace_style,
                  'set_delay': self.set_delay,
                  'RefurbishedRobot': RefurbishedRobot,
                  'UsedRobot' : UsedRobot,
                  'turn_off': self.turn_off,
                  'repeat': self.repeat,
                  'set_line_number': self.set_line_number,
                  'front_is_clear': self.front_is_clear,
                  'left_is_clear': self.left_is_clear,
                  'right_is_clear': self.right_is_clear,
                  'on_beeper': self.next_to_a_beeper,  # new, as suggested
                  'next_to_a_beeper': self.next_to_a_beeper, # compatibility with old code
                  'carries_beepers': self.carries_beepers,
                  'facing_north': self.facing_north,
                  'HitWallException': dialogs.HitWallException,
                  'setBackgroundColour': self.setBackgroundColour,
                  'input_int': self.inputInt,
                  'input_string': self.inputString}
     arg = self.parent.status_bar.running_field, _("Program is running")
     event_manager.SendCustomEvent(self.parent, arg)
     try:
         try:
             sys.settrace(self.my_trace)
             exec self.code in MyGlobals
             sys.settrace(None)
             self.world.DoDrawing()
             self.WorldDisplay.drawImage()
             self.WorldDisplay.Refresh()
             raise dialogs.NoTurnOffException(_("You forgot to turn me off!"))
         except dialogs.NoTurnOffException, mesg:
             dialogs.NoTurnOffError(mesg)
         except dialogs.NormalEnd, mesg:
             dialogs.NormalEndDialog(mesg)
Example #5
0
 def restart(self, r_dict):
     code = self.ProgramEditor.GetText()
     no_error, mesg = parser.ParseProgram(code)
     if no_error:
         self.code = parser.FixLineEnding(code)
         self.lines_of_code = self.code.split('\n')
         code, flag = test_import.process_file(code)
     else:
         self.code = ""
         dialogs.messageDialog(mesg, _("Error found in your program."))
     self.robot_dict = r_dict
     self.isPaused = False
     self.stopped_by_user = False
     self.execute_program()
Example #6
0
 def restart(self, r_dict):
     code = self.ProgramEditor.GetText()
     no_error, mesg = parser.ParseProgram(code)
     if no_error:
         self.code = parser.FixLineEnding(code)
         self.lines_of_code = self.code.split('\n')
         code, flag = test_import.process_file(code)
     else:
         self.code = ""
         dialogs.messageDialog(mesg, _("Error found in your program."))
     self.robot_dict = r_dict
     self.isPaused = False
     self.stopped_by_user = False
     self.execute_program()
Example #7
0
    def MyKeys(self, event):
        message = """
            F5: Help (i.e. this message)
            F11: Toggle editing mode

Robot actions:
            Up arrow:     move robot forward
            Left arrow:   turn robot left
            Right arrow:   turn robot right
            lower case g: grab_beeper
            lower case d: drop_beeper
            lower case p: print text to console
            lower case o: turn_off
            lower case u: undo last robot action

            Errors will occur if you attempt to move through a wall,
            put a beeper when you carry none,
            or try to pick up a beeper where there is none.

Editing world (only when in editing mode):
            lower case e: toggle in/out of edit walls mode
            Left mouse button: add or remove walls (if in edit walls mode)
            Right mouse button: put beepers at intersection
            F7: creates New_improved_robot
            F8: creates Used_robot (default)"""
        code = keycode(event)
        if code == wx.WXK_F5:
            dialogs.messageDialog(message, "Help :-)")
        elif code == wx.WXK_F11:
            if self.editMode == False:
                self.editMode = True
                self.app.ch.showEditButtons()
                self.app.ch.showRunButtons()
                self.controlMode = True
                self.app.ProgramEditor.SetReadOnly(False)
                self.app.outputWindow.SetReadOnly(False)
            else:
                self.editMode = False
                self.app.ch.showEditButtons(False)
                if not self.app.traceMode:
                    self.controlMode = False
        elif self.controlMode == False:
            pass
        elif code == wx.WXK_UP:           # up arrow
            if 'robot' in self.world.robot_dict:
                try:
                    self.world.MoveRobot('robot') # may raise an exception
                    self.scrollWorld('robot')
                except dialogs.HitWallException, mesg:
                    dialogs.DialogHitWallError(mesg)
Example #8
0
    def ChooseLanguage(self, event):
        translation.select(event.GetString())
        # notebook tabs
        self.grand_parent.window.SetPageText(0, _("  RUR: Read and Learn  "))
        self.grand_parent.window.SetPageText(1, _("Robot: Code and Learn"))
        self.grand_parent.window.SetPageText(2, _("Python: Code and Learn"))
        self.grand_parent.window.SetPageText(3, _("Python: simple editor"))
        self.grand_parent.SetTitle(_("RUR: a Python Learning Environment"))
        # tool tips; recreate the list in the new language and use it
        tip_list = [
            _("Open local html file"),
            _("Go back in browser history"),
            _("Home"),
            _("Go forward in browser history"),
            _("Select a language")
        ]
        for i in range(len(tip_list)):
            self.btn_list[i].SetToolTipString(tip_list[i])
        self.parent.Refresh()
        # choice window in Robot page
        self.grand_parent.ch.SelectLanguage()
        # choice window in Python editor
        self.grand_parent.py_ch.SelectLanguage()

        self.lessons_dir = conf.getLessonsNlDir()
        # page loaded in browser
        current_page = self.html.GetOpenedPage()
        relPath = relPathOfPage(current_page)
        if len(relPath) > 0:
            new_page = os.path.join(self.lessons_dir, relPath)
            if os.path.isfile(new_page):
                self.html.LoadPage(new_page)
            else:
                lessonbase = conf.getSettings().LESSONS_DIR
                new_page = os.path.join(lessonbase, 'en', relPath)
                if os.path.isfile(new_page):
                    self.html.LoadPage(new_page)
                else:
                    dialogs.messageDialog(
                        _('Cannot find a translation for %s') % current_page,
                        _('Translation Problem'))
        # status bar
        self.grand_parent.status_bar.ChangeLanguage()
        # world display
        self.grand_parent.world.background_images_created = False
        self.grand_parent.world.DoDrawing()
Example #9
0
    def ChooseLanguage(self, event):
        translation.select(event.GetString()) 
        # notebook tabs
        self.grand_parent.window.SetPageText(0, _("  RUR: Read and Learn  "))
        self.grand_parent.window.SetPageText(1, _("Robot: Code and Learn"))
        self.grand_parent.window.SetPageText(2, _("Python: Code and Learn"))
        self.grand_parent.window.SetPageText(3, _("Python: simple editor"))
        self.grand_parent.SetTitle(_("RUR: a Python Learning Environment"))
        # tool tips; recreate the list in the new language and use it
        tip_list = [_("Open local html file"), _("Go back in browser history"),
                     _("Home"), _("Go forward in browser history"),
                     _("Select a language")]
        for i in range(len(tip_list)):
            self.btn_list[i].SetToolTipString(tip_list[i])
        self.parent.Refresh()
        # choice window in Robot page
        self.grand_parent.ch.SelectLanguage()
        # choice window in Python editor
        self.grand_parent.py_ch.SelectLanguage()

        self.lessons_dir = conf.getLessonsNlDir()
        # page loaded in browser
        current_page = self.html.GetOpenedPage()
        relPath = relPathOfPage(current_page)
        if len(relPath) > 0:
            new_page = os.path.join(self.lessons_dir, relPath)
            if os.path.isfile(new_page):
                self.html.LoadPage(new_page)
            else:
                lessonbase = conf.getSettings().LESSONS_DIR
                new_page = os.path.join(lessonbase, 'en', relPath)
                if os.path.isfile(new_page):
                    self.html.LoadPage(new_page)
                else:
                    dialogs.messageDialog(
                        _('Cannot find a translation for %s') % current_page,
                        _('Translation Problem'))
        # status bar
        self.grand_parent.status_bar.ChangeLanguage()
        # world display
        self.grand_parent.world.background_images_created = False
        self.grand_parent.world.DoDrawing()
Example #10
0
         dialogs.NoTurnOffError(mesg)
     except dialogs.NormalEnd, mesg:
         dialogs.NormalEndDialog(mesg)
     except dialogs.HitWallException, mesg:
         dialogs.DialogHitWallError(mesg)
     except dialogs.PickBeeperException, mesg:
         dialogs.DialogPickBeeperError(mesg)
     except dialogs.PutBeeperException, mesg:
         dialogs.DialogPutBeeperError(mesg)
     except dialogs.UserStopException, mesg:
         dialogs.UserStopError(mesg)
     except Exception, info:
         # There should be only two remaining possibilities...
         if "invalid syntax" in info:
             info = _("Error found near line %s.")%info[1][1]
             dialogs.messageDialog(info, _("Execution error"))
         else:
             dialogs.messageDialog(
             _("%s\nUnrecognized instruction.")%info, 
                        _("Execution error"))
 finally:
     self.isRunning = False
     self.isStepped = False
     self.isPaused = False
     end = self.parent.status_bar.running_field, _("Program not running")
     event_manager.SendCustomEvent(self.parent, end)
     #self.parent.outputWindow.redirect('reset')
     sys.settrace(None)
     self.ProgramEditor.remove_highlight()
     self.ProgramEditor.Refresh()
     if self.parent.outputWindow.highlightMode:
Example #11
0
         dialogs.NoTurnOffError(mesg)
     except dialogs.NormalEnd, mesg:
         dialogs.NormalEndDialog(mesg)
     except dialogs.HitWallException, mesg:
         dialogs.DialogHitWallError(mesg)
     except dialogs.PickBeeperException, mesg:
         dialogs.DialogPickBeeperError(mesg)
     except dialogs.PutBeeperException, mesg:
         dialogs.DialogPutBeeperError(mesg)
     except dialogs.UserStopException, mesg:
         dialogs.UserStopError(mesg)
     except Exception, info:
         # There should be only two remaining possibilities...
         if "invalid syntax" in info:
             info = _("Error found near line %s.") % info[1][1]
             dialogs.messageDialog(info, _("Execution error"))
         else:
             dialogs.messageDialog(
                 _("%s\nUnrecognized instruction.") % info,
                 _("Execution error"))
 finally:
     self.isRunning = False
     self.isStepped = False
     self.isPaused = False
     end = self.parent.status_bar.running_field, _(
         "Program not running")
     event_manager.SendCustomEvent(self.parent, end)
     self.parent.outputWindow.redirect('reset')
     sys.settrace(None)
     self.ProgramEditor.remove_highlight()
     self.ProgramEditor.Refresh()
Example #12
0
         try:
             self.world.robot_dict['robot'].drop_beeper()
             if self.editor:
                 self.editor.DestroyChildren()
                 wx.StaticText(self.editor, -1, self.UpdateEditor(), (10, 10))
         except dialogs.PutBeeperException, mesg:
             dialogs.DialogPutBeeperError(mesg)
 elif code == 101:            # e - lower case
     if self.world.editWalls:
         self.world.editWalls = False
         self.world.DoDrawing()
     else:
         self.world.editWalls = True
         self.world.DoDrawing()
 elif code == wx.WXK_F5:
     dialogs.messageDialog(message, "Help :-)")
 elif code == wx.WXK_F7:
     self.world.robot_dict['robot'] = New_improved_robot(parent = self.world)
     self.world.DoDrawing()
     self.newRobot = True
 elif code == wx.WXK_F8:
     self.world.robot_dict['robot'] = Used_robot(parent = self.world)
     self.world.DoDrawing()
     self.newRobot = False
 elif code == wx.WXK_RIGHT:       # right arrow
     if self.newRobot:         # only New_improved_robot can turn right.
         self.world.TurnRobotRight('robot')
     else:
         pass
 else:
     pass
Example #13
0
             self.world.robot_dict['robot'].put_beeper()
             if self.editor:
                 self.editor.DestroyChildren()
                 wx.StaticText(self.editor, -1, self.UpdateEditor(),
                               (10, 10))
         except dialogs.PutBeeperException, mesg:
             dialogs.DialogPutBeeperError(mesg)
 elif code == 101:  # e - lower case
     if self.world.editWalls:
         self.world.editWalls = False
         self.world.DoDrawing()
     else:
         self.world.editWalls = True
         self.world.DoDrawing()
 elif code == wx.WXK_F5:
     dialogs.messageDialog(message, "Help :-)")
 elif code == wx.WXK_F7:
     self.world.robot_dict['robot'] = New_improved_robot(
         parent=self.world)
     self.world.DoDrawing()
     self.newRobot = True
 elif code == wx.WXK_F8:
     self.world.robot_dict['robot'] = Used_robot(parent=self.world)
     self.world.DoDrawing()
     self.newRobot = False
 elif code == wx.WXK_RIGHT:  # right arrow
     if self.newRobot:  # only New_improved_robot can turn right.
         self.world.TurnRobotRight('robot')
     else:
         pass
 else: