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."))
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."))
def BeepersToRobot(self, dummy): if self.user_program.isRunning: return self.user_program.clear_trace() try: dummy = self.backup_dict['robot'] except KeyError: msg = _("No robot in world to give beepers to.") dialogs.messageDialog(msg, 'error') return dialogs.RobotBeeperDialog(self, -1, _("Beepers!"))
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)
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)
def OnClose(self, event): if self.ProgramEditor.GetModify(): ret = dialogs.messageDialog(_(u'Save changes to %s?') % unicode(self.filename), _("About to close"), wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION | wx.STAY_ON_TOP) if ret == wx.ID_YES: if len(self.filename) > 0: try: f = open(self.filename, 'w') f.write(content) f.close() except IOError, e: messageDialog(unicode(e[1]), (u'IO Error'), wx.OK | wx.STAY_ON_TOP) else: self.SaveProgramFile(event) elif ret == wx.ID_NO: self.Destroy()
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
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
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)
def SelectLanguage(self): # recreate the list, using the new language tip_list = [ _("Open Python file"), _("Save Python file"), _("Run Python program"), _("Run program with argument list"), _("Help"), _("Go to line number"), _("Hide or show output window"), _("Change layout"), _("Clear text") ] for i in range(len(tip_list)): self.btn_list[i].SetToolTipString(tip_list[i])
def OnClose(self, event): if self.ProgramEditor.GetModify(): ret = dialogs.messageDialog( _(u'Save changes to %s?') % unicode(self.filename), _("About to close"), wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION | wx.STAY_ON_TOP) if ret == wx.ID_YES: if len(self.filename) > 0: try: f = open(self.filename, 'w') f.write(content) f.close() except IOError, e: messageDialog(unicode(e[1]), (u'IO Error'), wx.OK | wx.STAY_ON_TOP) else: self.SaveProgramFile(event) elif ret == wx.ID_NO: self.Destroy()
def __init__(self, parent, titre, world_filename): wx.Frame.__init__(self, None, -1, _(titre), size=(510, 550), style=wx.DEFAULT_FRAME_STYLE) self.parent = parent self.world_filename = world_filename icon = wx.EmptyIcon() icon.CopyFromBitmap(images.ICON) self.SetIcon(icon) self.statusbar = self.CreateStatusBar() self.Show(True) self.window = RURPanel(self) self.world = self.WorldDisplay.world if self.world_filename != None: try: txt = open(self.world_filename, 'r').read() except: rD.rurMessageDialog( _("Fichier monde %s inexistant\nIl ne sera pas chargé") % _(self.world_filename), _("Fichier monde")) return try: txt = parser.FixLineEnding(txt) flag = parser.ParseWorld(txt) if not flag: raise IOError self.backup_dict = {} # used to 'reset' the world exec txt in self.backup_dict # extracts avenues, streets, robot, # walls and beepers av = self.backup_dict['avenues'] st = self.backup_dict['streets'] self.SetSize((120 + 40 * av, 130 + 40 * st)) self.world.resetDimensions(av, st) 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] 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: rD.rurMessageDialog( _("Erreurs dans le fichier monde %s\nIl ne sera pas chargé" ) % _(self.world_filename), _("Fichier monde")) self.window.SetFocus() self.SendSizeEvent() # added to attempt to solve problem on MacOS wx.EVT_CLOSE(self, self.OnClose) self.onExit = False
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."))
def load_images(self, event): for heading in ("South", "North", "East", "West"): openedFileName = dialogs.openDialog( _("Choose an image: robot facing " + heading), _("All files (*.*)|*.*"), "", os.getcwd()) if openedFileName != "": setattr(self, "file" + heading, openedFileName) else: return () image_south = getImage(images.GREY_ROBOT_S) image_north = getImage(images.GREY_ROBOT_N) image_east = getImage(images.GREY_ROBOT_E) image_west = getImage(images.GREY_ROBOT_W) try: image_south = wx.Image(self.fileSouth).ConvertToBitmap() image_north = wx.Image(self.fileNorth).ConvertToBitmap() image_east = wx.Image(self.fileEast).ConvertToBitmap() image_west = wx.Image(self.fileWest).ConvertToBitmap() except Exception, info: print "Conversion or loading problems: can not use new images." print "info = %", info
def load_images(self, event): for heading in ("South", "North", "East", "West"): openedFileName = dialogs.openDialog( _("Choose an image: robot facing " + heading), _("All files (*.*)|*.*"), "", os.getcwd()) if openedFileName != "": setattr(self, "file" + heading, openedFileName) else: return() image_south = getImage(images.GREY_ROBOT_S) image_north = getImage(images.GREY_ROBOT_N) image_east = getImage(images.GREY_ROBOT_E) image_west = getImage(images.GREY_ROBOT_W) try: image_south = wx.Image(self.fileSouth).ConvertToBitmap() image_north = wx.Image(self.fileNorth).ConvertToBitmap() image_east = wx.Image(self.fileEast).ConvertToBitmap() image_west = wx.Image(self.fileWest).ConvertToBitmap() except Exception, info: print "Conversion or loading problems: can not use new images." print "info = %", info
def SetWorld(self, world_filename): self.world_filename = world_filename self.world = self.WorldDisplay.world if self.world_filename != None: try: txt = open(self.world_filename, 'r').read() except: rD.rurMessageDialog( _("Fichier monde %s inexistant\nIl ne sera pas chargé") % _(self.world_filename), _("Fichier monde")) return try: txt = parser.FixLineEnding(txt) flag = parser.ParseWorld(txt) if not flag: raise IOError self.backup_dict = {} # used to 'reset' the world exec txt in self.backup_dict # extracts avenues, streets, robot, # walls and beepers av = self.backup_dict['avenues'] st = self.backup_dict['streets'] self.SetSize((120 + 40 * av, 130 + 40 * st)) self.world.resetDimensions(av, st) 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] 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: rD.rurMessageDialog( _("Erreurs dans le fichier monde %s\nIl ne sera pas chargé" ) % _(self.world_filename), _("Fichier monde")) self.window.SetFocus()
sys.path.append(os.getcwd()) from rur_py import conf conf.getSettings() except OSError, e: print 'Cannot change to rur-ple directory.' sys.exit(1) from rur_py.translation import _ import rur_py.conf as conf # a few global variables import rur_py.wxutils as wxutils # do not check version when make a 'bundle' of the application # ref: http://www.wxpython.org/docs/api/wxversion-module.html if not hasattr(sys, 'frozen'): if wxutils.wxversiontuple() < (2, 6): print _("wxPython versions less than 2.6 are not supported.") sys.exit(1) import wx import wx.lib.buttons import wx.py as py # For the interpreter import rur_py.images as images # load all images from rur_py.images import getImage import rur_py.dialogs as dialogs # contains dialogs and exception classes from rur_py.translation import _ from rur_py.sash import MySashWindow from rur_py.lightning import EditorSashWindow import rur_py.parser as parser from rur_py.bouton import pythonChoiceWindow
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)
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)
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
def ResizeWorld(self, dummy): if self.user_program.isRunning: return self.user_program.clear_trace() dialogs.ResizeWorldDialog(self, -1, _("World size!"))
sys.path.append(os.getcwd()) from rur_py import conf conf.getSettings() except OSError, e: print 'Cannot change to rur-ple directory.' sys.exit(1) from rur_py.translation import _ import rur_py.conf as conf # a few global variables import rur_py.wxutils as wxutils # do not check version when make a 'bundle' of the application # ref: http://www.wxpython.org/docs/api/wxversion-module.html if not hasattr(sys, 'frozen'): if wxutils.wxversiontuple() < (2,6): print _("wxPython versions less than 2.6 are not supported.") sys.exit(1) import wx import wx.lib.buttons import wx.py as py # For the interpreter import rur_py.images as images # load all images from rur_py.images import getImage import rur_py.dialogs as dialogs # contains dialogs and exception classes from rur_py.translation import _ from rur_py.sash import MySashWindow from rur_py.lightning import EditorSashWindow import rur_py.parser as parser from rur_py.bouton import pythonChoiceWindow
wx.StaticText(self.editor, -1, self.UpdateEditor(), (10, 10)) except dialogs.PickBeeperException, mesg: dialogs.DialogPickBeeperError(mesg) elif code == 100: # d - lower case if 'robot' in self.world.robot_dict: try: self.world.robot_dict['robot'].put_beeper() self.world.DoDrawing() self.app.BeepersUpdateStatusBar() if self.editor: self.editor.DestroyChildren() wx.StaticText(self.editor, -1, self.UpdateEditor(), (10, 10)) except dialogs.PutBeeperException, mesg: dialogs.DialogPutBeeperError(mesg) elif code == 112: # p - lower case dlg = wx.TextEntryDialog(self, _("What do you want to print?"), _("Print text"), '') user_response = '' if dlg.ShowModal() == wx.ID_OK: user_response = dlg.GetValue() dlg.Destroy() if user_response: print user_response self.world.robot_dict['robot']._stay_put() elif code == 117: # u - lower case self.app.outputWindow.Undo() self.app.outputWindow.Undo() self.world.robot_dict['robot']._undo() self.world.DoDrawing() self.scrollWorld('robot') self.app.BeepersUpdateStatusBar() elif self.editMode == False:
def __init__(self, parent, editor): wx.Panel.__init__(self, parent, -1) btn_size = (32, 32) spacer_small = (4, 4) spacer_large = (25, 25) tip_list = [ _("Open Python file"), _("Save Python file"), _("Run Python program"), _("Run program with argument list"), _("Help"), _("Go to line number"), _("Hide or show output window"), _("Change layout"), _("Clear text") ] helpId = wx.NewId() openId = wx.NewId() saveId = wx.NewId() runId = wx.NewId() runWithId = wx.NewId() goToId = wx.NewId() showId = wx.NewId() clearId = wx.NewId() switchId = wx.NewId() # temporary list until images are created labels = ["Help", "Run with", "Go to", "Hide/show", "Layout"] button_list = [[None, False, None, None, spacer_small, None], [ openId, True, editor.openFile, images.OPEN_PYTHON, btn_size, tip_list[0] ], [None, False, None, None, spacer_small, None], [ saveId, True, editor.saveFile, images.SAVE_PYTHON, btn_size, tip_list[1] ], [None, False, None, None, spacer_large, None], [ runId, True, editor.run, images.RUN_PROGRAM, btn_size, tip_list[2] ], [None, False, None, None, spacer_small, None], [ runWithId, True, editor.run_with, images.RUN_WITH, btn_size, tip_list[3] ], [None, False, None, None, spacer_large, None], [ helpId, True, editor.help, images.HELP, btn_size, tip_list[4] ], [None, False, None, None, spacer_large, None], [ goToId, True, editor.goToLine, images.GOTO, btn_size, tip_list[5] ], [None, False, None, None, spacer_large, None], [ showId, True, editor.show, images.SHOW_HIDE, btn_size, tip_list[6] ], [None, False, None, None, spacer_large, None], [ switchId, True, editor.switch_layout, images.LAYOUT, btn_size, tip_list[7] ], [None, False, None, None, spacer_large, None], [ clearId, True, editor.clear, images.CLEAR_TEXT, btn_size, tip_list[8] ]] box = wx.BoxSizer(wx.HORIZONTAL) self.btn_list = [] for id, button, action, img, size, tip in button_list: if button: btn = wx.BitmapButton(self, id, img, size=size) #btn = wx.lib.buttons.GenBitmapButton(self, id, img, size=size) #btn = wx.Button(self, id, tip[:7], size=size) btn.SetToolTipString(tip) self.Bind(wx.EVT_BUTTON, action, btn) box.Add(btn, 0, wx.SHAPED) self.btn_list.append(btn) # create a list for later reference else: box.Add(size, 0, wx.EXPAND) self.SetSizer(box) aTable = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('O'), openId), (wx.ACCEL_CTRL, ord('S'), saveId), (wx.ACCEL_CTRL, ord('R'), runId), (wx.ACCEL_NORMAL, wx.WXK_F5, runWithId), (wx.ACCEL_CTRL, ord('E'), clearId), (wx.ACCEL_NORMAL, wx.WXK_F1, helpId), (wx.ACCEL_CTRL, ord('H'), showId), (wx.ACCEL_CTRL, ord('G'), goToId), (wx.ACCEL_CTRL, ord('L'), switchId)]) editor.SetAcceleratorTable(aTable)
def __init__(self): wx.Frame.__init__(self, None, -1, _("RUR: a Python Learning Environment"), size=(settings.SCREEN[0], settings.SCREEN[1]), style=wx.DEFAULT_FRAME_STYLE) self.raw_code = "" self.filename = "" self.world_filename = "" self.isPaused = False self.isRunning = False self.isStepped = False self.status_bar = rurStatusBar(self) self.SetStatusBar(self.status_bar) # icon on top left of window icon = wx.EmptyIcon() icon.CopyFromBitmap(getImage(images.ICON)) self.SetIcon(icon) # self.Show(True) self.window = RURnotebook(self) # win = browser.TestHtmlPanel(self.window, self) self.window.AddPage(win, _(" RUR: Read and Learn ")) # self.sash = MySashWindow(self.window, self) self.outputWindow = self.sash.output_window self.window.AddPage(self.sash, _("Robot: Code and Learn")) # See MySashWindow for the following 'shortcut' notation self.world = self.WorldDisplay.world # create a backup copy that will be used to "reset" the world self.backup_dict = {} self.backup_dict['avenues'] = self.world.av self.backup_dict['streets'] = self.world.st self.backup_dict['beepers'] = {} self.backup_dict['walls'] = [] # add a robot to start self.world.addOneRobot(name='robot') self.backup_dict['robot'] = self.world.robot_dict[ 'robot']._getInfoTuple() # create user_program object as a two-step process: create Singleton self.user_program = rur_program() # binds attributes explicitly self.user_program.myInit(self, self.world, self.WorldDisplay, self.ProgramEditor, self.world.robot_dict) # We will then be able to "link" to the one rur_program() without # having to worry about changing attributes # recreate the image so that the robot shows up. self.world.DoDrawing() self.WorldDisplay.drawImage() self.WorldDisplay.Refresh() # win = py.shell.Shell(self.window, -1, introText="") self.window.AddPage(win, _("Python: Code and Learn")) self.sash2 = EditorSashWindow(self.window, grand_parent=self, controller=pythonChoiceWindow, top_control=True, top_control_height=40) # 40 = bouton "." btn_size[1] + 8 self.window.AddPage(self.sash2, _("Python: simple editor")) self.SetSize((settings.SCREEN[0], settings.SCREEN[1])) self.window.SetFocus() self.SendSizeEvent() # added to attempt to solve problem on MacOS wx.EVT_CLOSE(self, self.OnClose)
def __init__(self, parent, great_grand_parent): wx.ScrolledWindow.__init__(self, parent, -1) self.ggp = great_grand_parent # rurApp instance! btn_size = (32, 32) self.ggp.BUTTON_HEIGHT = btn_size[0] + 8 spacer_small = (4, 4) spacer_large = (25, 25) tip_list = [ _("Opens existing robot program"), _("Saves robot program"), _("Opens existing world file"), _("Saves world file"), _("Resets world - from open file"), _("Runs robot program"), _("Steps through robot program instructions"), _("Pause program"), _("Stops program"), _("Adjust robot speed"), _("Edit walls"), _("Resize world"), _("Give beepers to robot"), _("Remove/add robot from/to world"), _("Toggle world file view"), "Load new images for robot" ] button_list1 = [ [ wx.NewId(), True, self.ggp.OpenProgramFile, images.OPEN_PROGRAM, btn_size, tip_list[0] ], [ wx.NewId(), True, self.ggp.SaveProgramFile, images.SAVE_PROGRAM, btn_size, tip_list[1] ], [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.OpenWorldFile, images.OPEN_WORLD, btn_size, tip_list[2] ], [ wx.NewId(), True, self.ggp.SaveWorldFile, images.SAVE_WORLD, btn_size, tip_list[3] ], [ wx.NewId(), True, self.ggp.ResetWorld, images.RESET_WORLD, btn_size, tip_list[4] ], [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.RunProgram, images.RUN_PROGRAM, btn_size, tip_list[5] ], [ wx.NewId(), True, self.ggp.Step, images.STEP, btn_size, tip_list[6] ], [ wx.NewId(), True, self.ggp.Pause, images.PAUSE, btn_size, tip_list[7] ], [ wx.NewId(), True, self.ggp.StopProgram, images.STOP, btn_size, tip_list[8] ], [None, False, None, None, spacer_large, None], [wx.NewId(), True, None, images.SPEED, btn_size, tip_list[9]] ] button_list2 = [ [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.EditWalls, images.WALL, btn_size, tip_list[10] ], [ wx.NewId(), True, self.ggp.ResizeWorld, images.RESIZE, btn_size, tip_list[11] ], [ wx.NewId(), True, self.ggp.BeepersToRobot, images.BEEPERS_ROBOT, btn_size, tip_list[12] ], [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.AddRemoveRobot, images.ADD_REMOVE_ROBOT, btn_size, tip_list[13] ], [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.ToggleWorldWindow, images.SHOW_WORLD_FILE, btn_size, tip_list[14] ], [None, False, None, None, spacer_large, None], [ wx.NewId(), True, self.ggp.load_images, images.NEW_ROBOT_IMAGES, btn_size, tip_list[15] ], ] box = wx.BoxSizer(wx.HORIZONTAL) self.btn_list = [] for id, button, action, img, size, tip in button_list1: if button: name = wx.lib.buttons.GenBitmapButton(self, id, img, size=size) name.SetToolTipString(tip) wx.EVT_BUTTON(self, id, action) box.Add(name, 0, wx.SHAPED) self.btn_list.append(name) # create lists for later reference else: box.Add(size, 0, wx.EXPAND) min_speed = 0 max_speed = 8 default_speed = 3 self.ggp.slider_speed = wx.Slider( # id, value, min, max, (x, y), (length, height) self, -1, default_speed, min_speed, max_speed, (-1, -1), (-1, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS #| wx.SL_LABELS ) self.ggp.slider_speed.SetTickFreq(1, 1) self.ggp.slider_speed.SetToolTipString(tip_list[9]) box.Add(self.ggp.slider_speed, 0, wx.SHAPED) self.ggp.slider_speed.SetFocus( ) # to make it same colour as background for id, button, action, img, size, tip in button_list2: if button: name = wx.lib.buttons.GenBitmapButton(self, id, img, size=size) name.SetToolTipString(tip) wx.EVT_BUTTON(self, id, action) box.Add(name, 0, wx.SHAPED) self.btn_list.append(name) # create lists for later reference else: box.Add(size, 0, wx.EXPAND) self.SetSizer(box) self.SetScrollRate(10, 0)
def __init__(self): wx.Frame.__init__(self, None, -1, _("RUR: a Python Learning Environment"), size = (settings.SCREEN[0], settings.SCREEN[1]), style=wx.DEFAULT_FRAME_STYLE) self.raw_code = "" self.filename = "" self.world_filename = "" self.isPaused = False self.isRunning = False self.isStepped = False self.status_bar = rurStatusBar(self) self.SetStatusBar(self.status_bar) # icon on top left of window icon = wx.EmptyIcon() icon.CopyFromBitmap(getImage(images.ICON)) self.SetIcon(icon) # self.Show(True) self.window = RURnotebook(self) # win = browser.TestHtmlPanel(self.window, self) self.window.AddPage(win, _(" RUR: Read and Learn ")) # self.sash = MySashWindow(self.window, self) self.outputWindow = self.sash.output_window self.window.AddPage(self.sash, _("Robot: Code and Learn")) # See MySashWindow for the following 'shortcut' notation self.world = self.WorldDisplay.world # create a backup copy that will be used to "reset" the world self.backup_dict = {} self.backup_dict['avenues'] = self.world.av self.backup_dict['streets'] = self.world.st self.backup_dict['beepers'] = {} self.backup_dict['walls'] = [] # add a robot to start self.world.addOneRobot(name='robot') self.backup_dict['robot'] = self.world.robot_dict[ 'robot']._getInfoTuple() # create user_program object as a two-step process: create Singleton self.user_program = rur_program() # binds attributes explicitly self.user_program.myInit(self, self.world, self.WorldDisplay, self.ProgramEditor, self.world.robot_dict) # We will then be able to "link" to the one rur_program() without # having to worry about changing attributes # recreate the image so that the robot shows up. self.world.DoDrawing() self.WorldDisplay.drawImage() self.WorldDisplay.Refresh() # win = py.shell.Shell(self.window, -1, introText = "") self.window.AddPage(win, _("Python: Code and Learn")) self.sash2 = EditorSashWindow(self.window, grand_parent=self, controller=pythonChoiceWindow, top_control=True, top_control_height=40) # 40 = bouton "." btn_size[1] + 8 self.window.AddPage(self.sash2, _("Python: simple editor")) self.SetSize((settings.SCREEN[0], settings.SCREEN[1])) self.window.SetFocus() self.SendSizeEvent() # added to attempt to solve problem on MacOS wx.EVT_CLOSE(self, self.OnClose)
def SelectLanguage(self): # recreate the list, using the new language tip_list = [ _("Opens existing robot program"), _("Saves robot program"), _("Opens existing world file"), _("Saves world file"), _("Resets world - from open file"), _("Runs robot program"), _("Steps through robot program instructions"), _("Pause program"), _("Stops program"), _("Adjust robot speed"), _("Edit walls"), _("Resize world"), _("Give beepers to robot"), _("Remove/add robot from/to world"), _("Toggle world file view"), "Load new images for robot" ] for i in range(len(tip_list)): self.btn_list[i].SetToolTipString(tip_list[i]) self.ggp.slider_speed.SetToolTipString(tip_list[9])