Exemple #1
0
 def Pause(self, dummy):
     if not (self.user_program.isRunning or self.user_program.isStepped):
         return
     if self.user_program.isPaused:
         self.user_program.isPaused = False
         arg = self.status_bar.running_field, _("Program is running")
         event_manager.SendCustomEvent(self, arg)
     else:
         self.user_program.isPaused = True
         arg = self.status_bar.running_field, _("Program paused")
         event_manager.SendCustomEvent(self, arg)
Exemple #2
0
 def OnPageChanged(self, event):
     status_bar = self.parent.status_bar
     # status_bar is dead during shutdown so check if it's alive.
     if status_bar:
         arg = status_bar.notebook_new_page, event.GetSelection()
         event_manager.SendCustomEvent(self.parent, arg)
         event.Skip()
Exemple #3
0
    def OpenProgramFile(self, dummy):
        if self.isRunning:
            return

        openedFileName = dialogs.openDialog(
            _("Choose a file"),
            _("Program files (*.rur)|*.rur| All files (*.*)|*.*"), "",
            settings.USER_PROGS_DIR)

        if openedFileName != "":
            global code
            self.filename = openedFileName
            arg = self.status_bar.program_field, \
                  os.path.basename(self.filename)
            event_manager.SendCustomEvent(self, arg)
            code = open(self.filename, 'r').read()
            code = parser.FixLineEnding(code)
            self.ProgramEditor.SetText(code)
            no_error, mesg = parser.ParseProgram(code)
            settings.USER_PROGS_DIR = os.path.dirname(self.filename)
            if no_error:
                self.raw_code = code
                self.ProgramEditor.SetSavePoint()
            else:
                code = ""
                dialogs.messageDialog(mesg, _("Program will not be used."))
Exemple #4
0
 def BeepersUpdateStatusBar(self):
     arg = self.status_bar.beeper_field, \
           self.world.robot_dict['robot']._beeper_bag
     event_manager.SendCustomEvent(self, arg)
     # update the world window text at the same time
     self.rightWindow.DestroyChildren()  # removes the old wx.StaticText
     wx.StaticText(self.rightWindow, -1, self.WorldDisplay.UpdateEditor(),
                   (10, 10))
Exemple #5
0
 def AddRemoveRobot(self, dummy):
     if self.user_program.isRunning:
         return
     if self.world.robot_dict:
         # remove all robots from non-empty dict
         self.world.robot_dict = {}
         arg = self.status_bar.beeper_field, self.status_bar.no_robot
     else:
         self.world.robot_dict = {}
         self.world.addOneRobot(name='robot')
         self.backup_dict['robot'] = self.world.robot_dict[
             'robot']._getInfoTuple()
         arg = self.status_bar.beeper_field, \
               self.world.robot_dict['robot']._beeper_bag
     event_manager.SendCustomEvent(self, arg)
     self.world.DoDrawing()
     self.WorldDisplay.drawImage()
     self.WorldDisplay.Refresh()
Exemple #6
0
    def SaveWorldFile(self, dummy):
        if self.isRunning:
            return
        txt = self.WorldDisplay.UpdateEditor()
        savedFileName = dialogs.checkedSaveDialog(
            txt, _("Save new world as"),
            _("World files (*.wld)|*.wld| All files (*.*)|*.*"),
            self.world_filename, settings.USER_WORLDS_DIR)

        self.world_filename = savedFileName

        arg = self.status_bar.world_field, \
              os.path.basename(self.world_filename)
        event_manager.SendCustomEvent(self, arg)
        settings.SAMPLE_WORLDS_DIR = os.path.dirname(self.world_filename)
        # save a backup copy to 'reset world'
        self.backup_dict = {}
        exec txt in self.backup_dict
Exemple #7
0
    def OpenWorldFile(self, dummy):
        if self.isRunning:
            return

        openedFileName = dialogs.openDialog(
            _("Choose a file"),
            _("World files (*.wld)|*.wld| All files (*.*)|*.*"), "",
            settings.USER_WORLDS_DIR)

        if openedFileName != "":
            self.world_filename = openedFileName
            self.ReadWorldFile()
            self.UpdateWorld()
            self.user_program.clear_trace()
            settings.USER_WORLDS_DIR = os.path.dirname(self.world_filename)
            arg = self.status_bar.world_field, \
                  os.path.basename(self.world_filename)
            event_manager.SendCustomEvent(self, arg)
Exemple #8
0
    def SaveProgramFile(self, dummy):
        if self.isRunning:
            return
        global code
        code = self.ProgramEditor.GetText()
        no_error, mesg = parser.ParseProgram(code)
        if no_error:
            savedFileName = savedFileName = dialogs.checkedSaveDialog(
                code, _("Save new program as"),
                _("Program files (*.rur)|*.rur| All files (*.*)|*.*"),
                self.filename, settings.USER_PROGS_DIR)

            self.filename = savedFileName
            arg = self.status_bar.program_field, \
                  os.path.basename(self.filename)
            event_manager.SendCustomEvent(self, arg)
            settings.USER_PROGS_DIR = os.path.dirname(self.filename)
            self.ProgramEditor.SetSavePoint()
        else:
            code = ""
            dialogs.messageDialog(mesg, _("Program will not be saved."))
Exemple #9
0
 def StopProgram(self, dummy):
     self.user_program.StopProgram()
     arg = self.status_bar.running_field, _("Program not running")
     event_manager.SendCustomEvent(self, arg)
     self.user_program.stopped_by_user = True
Exemple #10
0
    def UpdateWorld(self):
        try:
            av = self.backup_dict['avenues']
        except:
            dialogs.messageDialog(
                _("Problem with %s\nPlease recreate world file.") %
                _("avenues"), _("Invalid world file format"))
            return
        try:
            st = self.backup_dict['streets']
        except:
            dialogs.messageDialog(
                _("Problem with %s\nPlease recreate world file.") %
                _("streets"), _("Invalid world file format"))
            return
        self.world.resetDimensions(av, st)
        try:
            if 'robot' in self.backup_dict:
                x, y, key, beep = self.backup_dict['robot']
                arg = self.status_bar.beeper_field, beep
                event_manager.SendCustomEvent(self, arg)
        except:
            dialogs.messageDialog(
                _("Problem with %s\nPlease recreate world file.") % _("robot"),
                _("Invalid world file format"))
            return
        # We might be reloading the world, to which robots may have been added
        # Remove all robots that have been added, if any;
        # recall that "named" robots are added through a user-defined program,
        # not in a world file.
        self.world.robot_dict = {}
        # Recreate the robot that was in the original file
        if 'robot' in self.backup_dict:
            self.world.addOneRobot(x, y, key, beep, name='robot')

        # world characteristics
        # note: we make shallow copies of rurApp.backup_dict as we
        # may need it if we call ResetWorld().
        try:
            for corner in self.world.beepers_dict:
                del self.world.beepers_dict[
                    corner]  # empty, but keep reference
            for corner in self.backup_dict['beepers']:
                self.world.beepers_dict[corner] = self.backup_dict['beepers'][
                    corner]
        except:
            dialogs.messageDialog(
                _("Problem with %s\nPlease recreate world file.") %
                _("beepers"), _("Invalid world file format"))
            return
        # We need to keep one reference only to walls_list
        try:
            for col, row in self.world.walls_list:
                self.world.walls_list.remove(
                    (col, row))  # empty, but keep ref.
            for col, row in self.backup_dict['walls']:
                self.world.walls_list.append((col, row))
        except:
            dialogs.messageDialog(
                _("Problem with %s\nPlease recreate world file.") % _("walls"),
                _("Invalid world file format"))
            return

        # prepare to recreate the background images
        self.world.background_images_created = False
        self.world.AdjustWorldSize()
        self.world.InitTileSizes()
        self.WorldDisplay.InitialiseVariables()
        self.world.DoDrawing()
        # create a new bitmap image
        self.WorldDisplay.buffer = wx.EmptyBitmap(self.world.maxWidth,
                                                  self.world.maxHeight)
        self.WorldDisplay.drawImage()
        self.WorldDisplay.Refresh()  # added to fix refresh bug (issue #23)