Exemplo n.º 1
0
 def at_beeper(self, x, y):
     '''Notifies interested parties about robot
     being at a beeper.
     '''
     onbeepersound = os.path.join(conf.getSettings().SOUNDS_DIR, 'beep.wav')
     if os.path.isfile(onbeepersound):
         play(onbeepersound)
Exemplo n.º 2
0
 def at_beeper(self, x, y):
     '''Notifies interested parties about robot
     being at a beeper.
     '''
     onbeepersound = os.path.join(conf.getSettings().SOUNDS_DIR, 'beep.wav')
     if os.path.isfile(onbeepersound):
         play(onbeepersound)
Exemplo n.º 3
0
def relPathOfPage(page):
    '''Returns the part of the URL after the language path. Used to
    switch between corresponding lessons of different languages.
    '''
    # Make sure that lessonbase has a http like path separator
    lessonbase = conf.getSettings().LESSONS_DIR.replace(os.path.sep, '/')
    if (page.startswith(lessonbase)):
        lbcount = len(lessonbase.split('/'))
        pageparts = page.split('/')
        return '/'.join(pageparts[lbcount + 1:])
    else:
        return ''
Exemplo n.º 4
0
def relPathOfPage(page):
    '''Returns the part of the URL after the language path. Used to
    switch between corresponding lessons of different languages.
    '''
    # Make sure that lessonbase has a http like path separator
    lessonbase = conf.getSettings().LESSONS_DIR.replace(os.path.sep, '/')
    if (page.startswith(lessonbase)):
        lbcount = len(lessonbase.split('/'))
        pageparts = page.split('/')
        return '/'.join(pageparts[lbcount +1:])
    else:
        return ''
Exemplo n.º 5
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()
Exemplo n.º 6
0
    def __init__(self, avenues=1, streets=1, orient_key = 'E',
                 beepers=0, name = 'robot', colour = 'grey', parent=None):
        Robot_brain1.__init__(self, parent, avenues, streets,
                              orient_key, beepers)

        settings = conf.getSettings()
        
        self._delay = 0.3
        self.name = name
        self.colour = colour.lower()

        # The following are used to follow the robot trail
        self.line_trace = []
        self.set_trace_style(5, "blue")  # default

    #--- Robot images
        # create a list of four objects
        if self.colour == 'yellow':
            self._image = [getImage(images.YELLOW_ROBOT_N), getImage(images.YELLOW_ROBOT_W),
                       getImage(images.YELLOW_ROBOT_S), getImage(images.YELLOW_ROBOT_E)]
        elif self.colour == 'blue':
            self._image = [getImage(images.BLUE_ROBOT_N), getImage(images.BLUE_ROBOT_W),
                       getImage(images.BLUE_ROBOT_S), getImage(images.BLUE_ROBOT_E)]
        elif self.colour == 'light blue':
            self._image = [getImage(images.LIGHT_BLUE_ROBOT_N), getImage(images.LIGHT_BLUE_ROBOT_W),
                       getImage(images.LIGHT_BLUE_ROBOT_S), getImage(images.LIGHT_BLUE_ROBOT_E)]
        elif self.colour == 'purple':
            self._image = [getImage(images.PURPLE_ROBOT_N), getImage(images.PURPLE_ROBOT_W),
                       getImage(images.PURPLE_ROBOT_S), getImage(images.PURPLE_ROBOT_E)]
        elif self.colour == 'green':
            self._image = [getImage(images.GREEN_ROBOT_N), getImage(images.GREEN_ROBOT_W),
                       getImage(images.GREEN_ROBOT_S), getImage(images.GREEN_ROBOT_E)]
        else:
            self._image = [getImage(images.GREY_ROBOT_N), getImage(images.GREY_ROBOT_W),
                       getImage(images.GREY_ROBOT_S), getImage(images.GREY_ROBOT_E)]

        self.imageOffset = (settings.SCREEN[7], settings.SCREEN[8])

        # image size (x, y) [all images equal]; for use in automatic scrolling
        self._image_size = self._image[0].GetWidth(), \
                           self._image[0].GetHeight()
        ## Note: for some reason, GetSize() did not work  using
        ## wxPython 2.4, which is why I used GetWidth() and GetHeight()

        # selecting the right image based on initial orientation
        self.robot_image = self._image[self._facing]
Exemplo n.º 7
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()
Exemplo n.º 8
0
CLEAR_TEXT = "clear_text.png"
RUN_WITH = "run_with.png"
HELP = "help.png"
GOTO = "goto.png"
LAYOUT = "layout.png"
SHOW_HIDE = "show_hide.png"

# others
SPLASH_SCREEN = "splash_screen.png"
ICON = "rur16x16.png"
HIT_WALL_IMAGE = "ouch.png"
MINI_SPLASH = "splash_screen_small.png"
NEXT = "next.png"
CHECK_MARK = "checkmark.png"

settings = conf.getSettings()

_imageBitmap = {}


def getImage(imagePath):
    """
    """
    global _imageBitmap, settings

    if not imagePath in _imageBitmap:
        _imageBitmap[imagePath] = wx.Image(
            os.path.join(settings.IMAGE_DIR, imagePath), wx.BITMAP_TYPE_PNG
        ).ConvertToBitmap()

    return _imageBitmap[imagePath]
Exemplo n.º 9
0
    def __init__(self, parent, grand_parent):

        settings = conf.getSettings()

        wx.Panel.__init__(self, parent, -1)
        self.grand_parent = grand_parent
        self.ID_WINDOW_TOP = wx.NewId()
        self.ID_WINDOW_RIGHT = wx.NewId()
        self.ID_WINDOW_LEFT = wx.NewId()
        self.ID_WINDOW_BOTTOM = wx.NewId()
        wx.EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
                                  self.ID_WINDOW_BOTTOM, self.OnSashDrag)
        wx.EVT_SIZE(self, self.OnSize)

        # The following will occupy the space not used by the Layout Algorithm
        self.grand_parent.WorldDisplay = WorldGUI(self, -1)
        # Create the other windows
        # At the top, a window-like a toolbar containing buttons

        win = wx.SashLayoutWindow(self, self.ID_WINDOW_TOP, wx.DefaultPosition,
                                  wx.Size(800, 40), wx.NO_BORDER | wx.SW_3D)
        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
        win.SetAlignment(wx.LAYOUT_TOP)  #top
        win.SetSashVisible(wx.SASH_BOTTOM, True)
        self.topWindow = win

        # A window to the right of the client window
        win = wx.SashLayoutWindow(self,
                                  self.ID_WINDOW_RIGHT, wx.DefaultPosition,
                                  wx.Size(350, 600), wx.NO_BORDER | wx.SW_3D)
        win.SetDefaultSize(wx.Size(0, 600))
        win.SetOrientation(wx.LAYOUT_VERTICAL)
        win.SetAlignment(wx.LAYOUT_RIGHT)
        win.SetSashVisible(wx.SASH_LEFT, True)
        self.grand_parent.rightWindow = win
        self.grand_parent.rightWindow.isVisible = False

        # Another window to the left of the client window
        win = wx.SashLayoutWindow(self,
                                  self.ID_WINDOW_LEFT, wx.DefaultPosition,
                                  wx.Size(300, 600), wx.NO_BORDER | wx.SW_3D)
        win.SetDefaultSize(wx.Size(settings.SCREEN[2], 600))
        win.SetOrientation(wx.LAYOUT_VERTICAL)
        win.SetAlignment(wx.LAYOUT_LEFT)
        win.SetSashVisible(wx.SASH_RIGHT, True)
        self.leftWindow = win
        #### new
        # Output window at the bottom
        win = wx.SashLayoutWindow(self, self.ID_WINDOW_BOTTOM,
                                  wx.DefaultPosition,
                                  wx.Size(800, settings.SCREEN[3]),
                                  wx.NO_BORDER | wx.SW_3D)
        #winids.append(win.GetId())
        #win.SetDefaultSize((WIDTH, self.output_default_height))
        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
        win.SetAlignment(wx.LAYOUT_BOTTOM)
        win.SetSashVisible(wx.SASH_TOP, True)
        self.bottomWindow = win
        self.output_window = LogWindow(self.bottomWindow)
        self.bottomWindow.SetDefaultSize(wx.Size(800, settings.SCREEN[3]))
        ####################
        self.grand_parent.ch = rurChoiceWindow(self.topWindow,
                                               self.grand_parent)
        self.topWindow.SetDefaultSize(
            wx.Size(800, self.grand_parent.BUTTON_HEIGHT))

        self.grand_parent.WorldEditor = wx.Panel(self.grand_parent.rightWindow,
                                                 -1)
        self.grand_parent.ProgramEditor = rur_editor(self.leftWindow, -1)
        # to update from within WorldDisplay, create the following link
        self.grand_parent.WorldDisplay.editor = self.grand_parent.rightWindow
Exemplo n.º 10
0
    def __init__(
        self,
        avenues=10,
        streets=10,
        walls=[],
        beepers={},
        robot={},
        editWalls=False,
        screen_offsets=(50, 50, 20, 40),
        tile_info=None,
        beeper_info=None,
        wall_colours=("black", "brown"),
        edit_wall_colours=("brown", "black"),
        grid_colour="light grey",
        wall_grid_colour="brown",
        beeper_outside_colour="cadet blue",
        beeper_inside_colour="white",
        beeper_number_colour="black",
    ):

        World.__init__(self, avenues, streets, walls, beepers, robot)

        settings = conf.getSettings()

        if tile_info == None:
            tile_info = (settings.SCREEN[4], settings.SCREEN[5])

        if beeper_info == None:
            beeper_info = (20, settings.SCREEN[6], 6, 3)

        # world positioning on "screen"
        self.xOffset = screen_offsets[0]  # left
        self.yOffset = screen_offsets[1]  # bottom
        self.yTopOffset = screen_offsets[2]  # top
        self.right_scroller_space = screen_offsets[3]  # right; leaving enough
        # room so that the right boundary is never hidden under the scrollbar.

        # rectangular walls or "tiles"
        self.tile_wide = tile_info[0]
        self.tile_narrow = tile_info[1]

        # the following 4 values are approximate values, used to center
        # beepers and beeper numbers, obtained through trial and error, based
        # on self.tile_wide=34, self.tile_narrow = 6
        self.beeper_radius = beeper_info[0]
        self.beeper_offset = beeper_info[1]
        self.beep_single_digit = beeper_info[2]
        self.beep_double_digit = beeper_info[3]

        # Walls are rectangles of a given colour, filled with a second.
        self.wall_outside_colour = wall_colours[0]

        self.wall_inside_colour = wall_colours[1]
        # allows for the possibility of using different colour when editing
        self.edit_wall_outside_colour = edit_wall_colours[0]
        self.edit_wall_inside_colour = edit_wall_colours[1]
        self.editWalls = editWalls

        self.grid_colour = grid_colour
        self.wall_grid_colour = wall_grid_colour

        self.beeper_outside_colour = beeper_outside_colour
        self.beeper_inside_colour = beeper_inside_colour
        self.beeper_number_colour = beeper_number_colour

        self.background_colour = wx.Brush("white")

        # we will create two basic world images and
        # then set this flag to True; if world dimension changes, we will
        # reset it to False
        self.background_images_created = False
        self.AdjustWorldSize()
        self.InitTileSizes()

        self.object_dict = {}  # keeps track or robots
Exemplo n.º 11
0
    def __init__(self, parent, great_grand_parent):
        settings = conf.getSettings()

        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_large = (settings.SCREEN[9], settings.SCREEN[9])

        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")
        ]

        widget_list1 = [[
            wx.NewId(), BUTTON, self.ggp.OpenProgramFile,
            getImage(images.OPEN_PROGRAM), btn_size, tip_list[0]
        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.SaveProgramFile,
                            getImage(images.SAVE_PROGRAM), btn_size,
                            tip_list[1]
                        ], [None, SPACER, None, None, spacer_large, None],
                        [
                            wx.NewId(), BUTTON, self.ggp.OpenWorldFile,
                            getImage(images.OPEN_WORLD), btn_size, tip_list[2]
                        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.SaveWorldFile,
                            getImage(images.SAVE_WORLD), btn_size, tip_list[3]
                        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.ResetWorld,
                            getImage(images.RESET_WORLD), btn_size, tip_list[4]
                        ], [None, SPACER, None, None, spacer_large, None],
                        [
                            wx.NewId(), BUTTON, self.ggp.RunProgram,
                            getImage(images.RUN_PROGRAM), btn_size, tip_list[5]
                        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.Step,
                            getImage(images.STEP), btn_size, tip_list[6]
                        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.Pause,
                            getImage(images.PAUSE), btn_size, tip_list[7]
                        ],
                        [
                            wx.NewId(), BUTTON, self.ggp.StopProgram,
                            getImage(images.STOP), btn_size, tip_list[8]
                        ], [None, SPACER, None, None, spacer_large, None],
                        [
                            wx.NewId(), BITMAP, None,
                            getImage(images.SPEED), btn_size, tip_list[9]
                        ]]

        widget_list2 = [
            [None, SPACER, None, None, spacer_large, None],
            [
                wx.NewId(), BUTTON, self.ggp.EditWalls,
                getImage(images.WALL), btn_size, tip_list[10]
            ],
            [
                wx.NewId(), BUTTON, self.ggp.ResizeWorld,
                getImage(images.RESIZE), btn_size, tip_list[11]
            ],
            [
                wx.NewId(), BUTTON, self.ggp.BeepersToRobot,
                getImage(images.BEEPERS_ROBOT), btn_size, tip_list[12]
            ],
            [None, SPACER, None, None, spacer_large, None],
            [
                wx.NewId(), BUTTON, self.ggp.AddRemoveRobot,
                getImage(images.ADD_REMOVE_ROBOT), btn_size, tip_list[13]
            ],
            [None, SPACER, None, None, spacer_large, None],
            [
                wx.NewId(), BUTTON, self.ggp.ToggleWorldWindow,
                getImage(images.SHOW_WORLD_FILE), btn_size, tip_list[14]
            ],
            [None, SPACER, None, None, spacer_large, None],
            [
                wx.NewId(), BUTTON, self.ggp.load_images,
                getImage(images.NEW_ROBOT_IMAGES), btn_size, tip_list[15]
            ],
        ]
        box = wx.BoxSizer(wx.HORIZONTAL)

        self.btn_list = []
        for id, widget, action, img, size, tip in widget_list1:
            if widget == 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
            elif widget == BITMAP:
                name = wx.StaticBitmap(self, -1, img, size=size)
                box.Add(name, 0, wx.SHAPED)
                self.btn_list.append(name)  # create lists for later reference
            elif widget == SPACER:
                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),
            (100, -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, widget, action, img, size, tip in widget_list2:
            if widget == 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
            elif widget == BITMAP:
                name = wx.StaticBitmap(self, -1, img, size=size)
                box.Add(name, 0, wx.SHAPED)
                self.btn_list.append(name)  # create lists for later reference
            elif widget == SPACER:
                box.Add(size, 0, wx.EXPAND)
        self.SetSizer(box)
        self.SetScrollRate(10, 0)
Exemplo n.º 12
0
class Visible_world(World):
    """ Visible_world extends World() by adding method to draw a representation
        of that world.  It comes with default values that should be sufficient
        for all practical purpose but nonetheless allows for a large degree
        of customization. """

    settings = conf.getSettings()

    #--- Initialisation
    def __init__(self,
                 avenues=10,
                 streets=10,
                 walls=[],
                 beepers={},
                 robot={},
                 editWalls=False,
                 screen_offsets=(50, 50, 20, 40),
                 tile_info=None,
                 beeper_info=None,
                 wall_colours=("black", "brown"),
                 edit_wall_colours=("brown", "black"),
                 grid_colour="light grey",
                 wall_grid_colour="brown",
                 beeper_outside_colour="cadet blue",
                 beeper_inside_colour="white",
                 beeper_number_colour="black"):

        World.__init__(self, avenues, streets, walls, beepers, robot)

        settings = conf.getSettings()

        if tile_info == None:
            tile_info = (settings.SCREEN[4], settings.SCREEN[5])

        if beeper_info == None:
            beeper_info = (20, settings.SCREEN[6], 6, 3)

        # world positioning on "screen"
        self.xOffset = screen_offsets[0]  # left
        self.yOffset = screen_offsets[1]  # bottom
        self.yTopOffset = screen_offsets[2]  # top
        self.right_scroller_space = screen_offsets[3]  # right; leaving enough
        #room so that the right boundary is never hidden under the scrollbar.

        # rectangular walls or "tiles"
        self.tile_wide = tile_info[0]
        self.tile_narrow = tile_info[1]

        # the following 4 values are approximate values, used to center
        # beepers and beeper numbers, obtained through trial and error, based
        # on self.tile_wide=34, self.tile_narrow = 6
        self.beeper_radius = beeper_info[0]
        self.beeper_offset = beeper_info[1]
        self.beep_single_digit = beeper_info[2]
        self.beep_double_digit = beeper_info[3]

        # Walls are rectangles of a given colour, filled with a second.
        self.wall_outside_colour = wall_colours[0]

        self.wall_inside_colour = wall_colours[1]
        # allows for the possibility of using different colour when editing
        self.edit_wall_outside_colour = edit_wall_colours[0]
        self.edit_wall_inside_colour = edit_wall_colours[1]
        self.editWalls = editWalls

        self.grid_colour = grid_colour
        self.wall_grid_colour = wall_grid_colour

        self.beeper_outside_colour = beeper_outside_colour
        self.beeper_inside_colour = beeper_inside_colour
        self.beeper_number_colour = beeper_number_colour

        self.background_colour = wx.Brush('white')

        # we will create two basic world images and
        # then set this flag to True; if world dimension changes, we will
        # reset it to False
        self.background_images_created = False
        self.AdjustWorldSize()
        self.InitTileSizes()

        self.object_dict = {}  # keeps track or robots

    def AdjustWorldSize(self):
        """ Computes the width and height of the display based on chosen
            parameters."""
        self.maxWidth = (self.num_cols - 1) * (
                        self.tile_wide + self.tile_narrow
                )/2 + self.tile_narrow + self.xOffset \
                         + self.right_scroller_space
        self.maxHeight = (self.num_rows - 1) * (
            self.tile_wide + self.tile_narrow
        ) / 2 + self.tile_narrow + self.yOffset + self.yTopOffset

    def InitTileSizes(self):
        """ Creates a two dimensional array of tiles containing the
            size information."""
        self.tiles_data = [[0 for row in range(self.num_rows)] \
                       for col in range(self.num_cols)]
        ns = self.tile_narrow  # temporary variable easier to read in equations
        ws = self.tile_wide  # temporary variable easier to read in equations
        for col in range(0, self.num_cols):
            for row in range(0, self.num_rows):
                x = (col // 2) * (ns + ws) + (col % 2) * ns + self.xOffset
                y = (row // 2) * (ns + ws) + (row % 2) * ns + self.yTopOffset
                if col % 2:
                    x_side = ws + 2 * ns
                    x -= ns
                else:
                    x_side = ns
                if row % 2:
                    y_side = ws + 2 * ns
                    y -= ns
                else:
                    y_side = ns
                self.tiles_data[col][row] = (x, y, x_side, y_side)

    #--- World changes from Graphical World Editor

    def CalculatePosition(self, x, y):
        """ Computes the corresponding (column, row) value from an (x, y)
            world coordinate."""
        tilePair = self.tile_narrow + self.tile_wide
        x -= self.xOffset
        y -= self.yTopOffset
        numberOfWideAndNarrow = x // tilePair
        if (x - numberOfWideAndNarrow * tilePair < self.tile_narrow):
            col = 2 * numberOfWideAndNarrow
        else:
            col = 2 * numberOfWideAndNarrow + 1
        numberOfWideAndNarrow = y // tilePair
        if (y - numberOfWideAndNarrow * tilePair < self.tile_narrow):
            row = 2 * numberOfWideAndNarrow
        else:
            row = 2 * numberOfWideAndNarrow + 1
        row = self.flipRow(row)
        return col, row

    # remember that row 0 on screen is on top; in RUR world, it is on bottom
    def flipRow(self, row):
        """ On the screen, row 0 is at the top.  To facilitate
            the calculation of row <---> street, we flip the rows
            in RUR world so that row 0 is at the bottom."""
        return self.num_rows - row - 1

    def ChangeWall(self, col, row):
        """ After "clicking" a point on the screen, we check if it corresponds
            to a wall area and, if so, adds a wall if there is none, or
            remove it if there is one."""
        if not self.editWalls: return
        if col == 0 or row == 0 or \
           col == self.num_cols -1 or \
           row == self.num_rows - 1 :
            return  # we are on the border

        # wall exists when (col, row) is either (odd, even) or (even, odd)
        if (row + col) % 2:
            self.ToggleWalls(col, row)
            self.DoDrawing()

    def MoveRobot(self, name):
        """ Change the robot position on the screen."""
        self.robot_dict[name].move()
        self.DoDrawing()

    def TurnRobotLeft(self, name):
        """ Change the robot orientation on the screen."""
        self.robot_dict[name].turn_left()
        self.DoDrawing()

    def TurnRobotRight(self, name):
        """ Change the robot orientation on the screen;
            only New_improved_robot can turn right."""
        self.robot_dict[name].turn_right()
        self.DoDrawing()

    def setBeepers(self, (av, st), nb):
        """ Sets the number of beepers at a given intersection from
            the Graphical world builder; robot induced changes
            are dealt with in class World."""
        World.setBeepers(self, (av, st), nb)
        self.DoDrawing()
Exemplo n.º 13
0
    def __init__(self,
                 avenues=10,
                 streets=10,
                 walls=[],
                 beepers={},
                 robot={},
                 editWalls=False,
                 screen_offsets=(50, 50, 20, 40),
                 tile_info=None,
                 beeper_info=None,
                 wall_colours=("black", "brown"),
                 edit_wall_colours=("brown", "black"),
                 grid_colour="light grey",
                 wall_grid_colour="brown",
                 beeper_outside_colour="cadet blue",
                 beeper_inside_colour="white",
                 beeper_number_colour="black"):

        World.__init__(self, avenues, streets, walls, beepers, robot)

        settings = conf.getSettings()

        if tile_info == None:
            tile_info = (settings.SCREEN[4], settings.SCREEN[5])

        if beeper_info == None:
            beeper_info = (20, settings.SCREEN[6], 6, 3)

        # world positioning on "screen"
        self.xOffset = screen_offsets[0]  # left
        self.yOffset = screen_offsets[1]  # bottom
        self.yTopOffset = screen_offsets[2]  # top
        self.right_scroller_space = screen_offsets[3]  # right; leaving enough
        #room so that the right boundary is never hidden under the scrollbar.

        # rectangular walls or "tiles"
        self.tile_wide = tile_info[0]
        self.tile_narrow = tile_info[1]

        # the following 4 values are approximate values, used to center
        # beepers and beeper numbers, obtained through trial and error, based
        # on self.tile_wide=34, self.tile_narrow = 6
        self.beeper_radius = beeper_info[0]
        self.beeper_offset = beeper_info[1]
        self.beep_single_digit = beeper_info[2]
        self.beep_double_digit = beeper_info[3]

        # Walls are rectangles of a given colour, filled with a second.
        self.wall_outside_colour = wall_colours[0]

        self.wall_inside_colour = wall_colours[1]
        # allows for the possibility of using different colour when editing
        self.edit_wall_outside_colour = edit_wall_colours[0]
        self.edit_wall_inside_colour = edit_wall_colours[1]
        self.editWalls = editWalls

        self.grid_colour = grid_colour
        self.wall_grid_colour = wall_grid_colour

        self.beeper_outside_colour = beeper_outside_colour
        self.beeper_inside_colour = beeper_inside_colour
        self.beeper_number_colour = beeper_number_colour

        self.background_colour = wx.Brush('white')

        # we will create two basic world images and
        # then set this flag to True; if world dimension changes, we will
        # reset it to False
        self.background_images_created = False
        self.AdjustWorldSize()
        self.InitTileSizes()

        self.object_dict = {}  # keeps track or robots
Exemplo n.º 14
0
                value = line[8:-2]
            elif line.startswith('"') or line.startswith("'"):
                if msgid:
                    key += line[1:-2]
                elif msgstr:
                    value += line[1:-2]
            elif line.startswith("\n"):
                key = key.replace("\\n", "")
                value = value.replace("\\n", "\n")
                translation[key] = value
                msgid = False
                msgstr = False
    return translation


rur_locale = conf.getSettings().LOCALE_DIR

for lang in conf.getAvailableLanguages():
    filename = os.path.join(rur_locale, lang, languages[lang][0] + '.po')
    languages[lang][1] = build_dict(filename)


def _select_code(langCode):
    global _selected
    for lang in conf.getAvailableLanguages():
        if lang == langCode:
            _selected = languages[lang][1]
            conf.setLanguage(langCode)


def select(language):
Exemplo n.º 15
0
OPEN_PYTHON = 'open_py.png'
SAVE_PYTHON = 'save_py.png'
CLEAR_TEXT = 'clear_text.png'
RUN_WITH = 'run_with.png'
HELP = 'help.png'
GOTO = 'goto.png'
LAYOUT = 'layout.png'
SHOW_HIDE = 'show_hide.png'

# others
SPLASH_SCREEN = 'splash_screen.png'
ICON = 'rur16x16.png'
HIT_WALL_IMAGE = 'ouch.png'
MINI_SPLASH = 'splash_screen_small.png'

settings = conf.getSettings()

_imageBitmap = {}


def getImage(imagePath):
    '''
    '''
    global _imageBitmap, settings

    if not imagePath in _imageBitmap:
        _imageBitmap[imagePath] = wx.Image(
            os.path.join(settings.IMAGE_DIR, imagePath),
            wx.BITMAP_TYPE_PNG).ConvertToBitmap()

    return _imageBitmap[imagePath]
Exemplo n.º 16
0
    def __init__(self, parent, great_grand_parent):
        settings = conf.getSettings()

        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_large = (settings.SCREEN[9], settings.SCREEN[9])

        tip_list = [_("Submits Answer & proceeds to next question"),
                          _("Resets World"),
                          _("Tests the program"),
                          _("Steps through robot program instructions"), 
                          _("Pause program"), 
                          _("Stops program"),
                          _("Bring up instructions"), 
                          _("Adjust robot speed")]

        widget_list1 = [
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.Submit,
                getImage(images.CHECK_MARK), btn_size, tip_list[0]],
            [None, SPACER, None, None, spacer_large, None],
            [None, SPACER, None, None, spacer_large, None],
            [None, SPACER, None, None, spacer_large, None],
            [None, SPACER, None, None, spacer_large, None],
            [None, SPACER, None, None, spacer_large, None],
            [None, SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.Reset,
                getImage(images.RESET_WORLD), btn_size, tip_list[1]],
            [wx.NewId(), BUTTON, self.ggp.RunProgram,
                getImage(images.RUN_PROGRAM), btn_size, tip_list[2]],
            [wx.NewId(), BUTTON, self.ggp.Step,
                getImage(images.STEP), btn_size, tip_list[3]],
            [wx.NewId(), BUTTON, self.ggp.Pause,
                getImage(images.PAUSE), btn_size, tip_list[4]],
            [wx.NewId(), BUTTON, self.ggp.StopProgram,
                getImage(images.STOP), btn_size, tip_list[5]],
            [wx.NewId(), BUTTON, self.ggp.InstructionSheet,
                getImage(images.HELP), btn_size, tip_list[6]],
            [None, SPACER, None, None, spacer_large, None]]


        box = wx.BoxSizer(wx.HORIZONTAL)

        self.btn_list = []
        for id, widget, action, img, size, tip in widget_list1:
            if widget == 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
            elif widget == BITMAP:
                name = wx.StaticBitmap(self, -1, img, size=size)
                box.Add(name, 0, wx.SHAPED)
                self.btn_list.append(name)  # create lists for later reference
            elif widget == SPACER:
                box.Add(size, 0, wx.EXPAND)

        min_speed = 0
        max_speed = 8
        default_speed = 4
        self.ggp.slider_speed = wx.Slider(
            # id, value, min, max, (x, y), (length, height)
            self, -1, default_speed, min_speed, max_speed,
            (-1, -1), (100, -1),
            wx.SL_HORIZONTAL | wx.SL_AUTOTICKS #| wx.SL_LABELS
            )
        self.ggp.slider_speed.SetTickFreq(1, 1)
        self.ggp.slider_speed.SetToolTipString(tip_list[7])
        box.Add(self.ggp.slider_speed, 0, wx.SHAPED)
        self.ggp.slider_speed.SetFocus()  # to make it same colour as background

        self.SetSizer(box)
        self.SetScrollRate(10, 0)
Exemplo n.º 17
0
    def __init__(self, parent, great_grand_parent):
        settings = conf.getSettings()

        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_large = (settings.SCREEN[9], settings.SCREEN[9])

        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")]

        widget_list1 = [
            [wx.NewId(), BUTTON, self.ggp.OpenProgramFile,
                getImage(images.OPEN_PROGRAM), btn_size, tip_list[0]],
            [wx.NewId(), BUTTON, self.ggp.SaveProgramFile,
                getImage(images.SAVE_PROGRAM), btn_size, tip_list[1]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.OpenWorldFile,
                getImage(images.OPEN_WORLD), btn_size, tip_list[2]],
            [wx.NewId(), BUTTON, self.ggp.SaveWorldFile,
                getImage(images.SAVE_WORLD), btn_size, tip_list[3]],
            [wx.NewId(), BUTTON, self.ggp.ResetWorld,
                getImage(images.RESET_WORLD), btn_size, tip_list[4]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.RunProgram,
                getImage(images.RUN_PROGRAM), btn_size, tip_list[5]],
            [wx.NewId(), BUTTON, self.ggp.Step,
                getImage(images.STEP), btn_size, tip_list[6]],
            [wx.NewId(), BUTTON, self.ggp.Pause,
                getImage(images.PAUSE), btn_size, tip_list[7]],
            [wx.NewId(), BUTTON, self.ggp.StopProgram,
                getImage(images.STOP), btn_size, tip_list[8]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(),  BITMAP, None,
                getImage(images.SPEED), btn_size, tip_list[9]]
            ]

        widget_list2 =[
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.EditWalls,
                getImage(images.WALL), btn_size, tip_list[10]],
            [wx.NewId(), BUTTON, self.ggp.ResizeWorld,
                getImage(images.RESIZE), btn_size, tip_list[11]],
            [wx.NewId(), BUTTON, self.ggp.BeepersToRobot,
                getImage(images.BEEPERS_ROBOT), btn_size, tip_list[12]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.AddRemoveRobot,
                getImage(images.ADD_REMOVE_ROBOT), btn_size, tip_list[13]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.ToggleWorldWindow,
                getImage(images.SHOW_WORLD_FILE), btn_size, tip_list[14]],
            [None,      SPACER, None, None, spacer_large, None],
            [wx.NewId(), BUTTON, self.ggp.load_images,
                getImage(images.NEW_ROBOT_IMAGES), btn_size, tip_list[15]],
            ]
        box = wx.BoxSizer(wx.HORIZONTAL)

        self.btn_list = []
        for id, widget, action, img, size, tip in widget_list1:
            if widget == 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
            elif widget == BITMAP:
                name = wx.StaticBitmap(self, -1, img, size=size)
                box.Add(name, 0, wx.SHAPED)
                self.btn_list.append(name)  # create lists for later reference
            elif widget == SPACER:
                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), (100, -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, widget, action, img, size, tip in widget_list2:
            if widget == 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
            elif widget == BITMAP:
                name = wx.StaticBitmap(self, -1, img, size=size)
                box.Add(name, 0, wx.SHAPED)
                self.btn_list.append(name)  # create lists for later reference
            elif widget == SPACER:
                box.Add(size, 0, wx.EXPAND)
        self.SetSizer(box)
        self.SetScrollRate(10, 0)
Exemplo n.º 18
0
    def __init__(self, parent, grand_parent):

        settings = conf.getSettings()
        
        wx.Panel.__init__(self, parent, -1)
        self.grand_parent = grand_parent
        self.ID_WINDOW_TOP = wx.NewId()
        self.ID_WINDOW_RIGHT = wx.NewId()
        self.ID_WINDOW_LEFT = wx.NewId()
        self.ID_WINDOW_BOTTOM = wx.NewId()
        wx.EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
                               self.ID_WINDOW_BOTTOM, self.OnSashDrag)
        wx.EVT_SIZE(self, self.OnSize)

        # The following will occupy the space not used by the Layout Algorithm
        self.grand_parent.WorldDisplay = WorldGUI(self, -1)
        # Create the other windows
        # At the top, a window-like a toolbar containing buttons

        win = wx.SashLayoutWindow(self, self.ID_WINDOW_TOP, wx.DefaultPosition,
                                 wx.Size(800, 40), wx.NO_BORDER|wx.SW_3D)
        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
        win.SetAlignment(wx.LAYOUT_TOP) #top
        win.SetSashVisible(wx.SASH_BOTTOM, True)
        self.topWindow = win

        # A window to the right of the client window
        win =  wx.SashLayoutWindow(self, self.ID_WINDOW_RIGHT,
                                  wx.DefaultPosition, wx.Size(350, 600),
                                  wx.NO_BORDER|wx.SW_3D)
        win.SetDefaultSize(wx.Size(0, 600))
        win.SetOrientation(wx.LAYOUT_VERTICAL)
        win.SetAlignment(wx.LAYOUT_RIGHT)
        win.SetSashVisible(wx.SASH_LEFT, True)
        self.grand_parent.rightWindow = win
        self.grand_parent.rightWindow.isVisible = False

        # Another window to the left of the client window
        win = wx.SashLayoutWindow(self, self.ID_WINDOW_LEFT,
                                 wx.DefaultPosition, wx.Size(300, 600),
                                 wx.NO_BORDER|wx.SW_3D)
        win.SetDefaultSize(wx.Size(settings.SCREEN[2], 600))
        win.SetOrientation(wx.LAYOUT_VERTICAL)
        win.SetAlignment(wx.LAYOUT_LEFT)
        win.SetSashVisible(wx.SASH_RIGHT, True)
        self.leftWindow = win
        #### new
        # Output window at the bottom
        win =  wx.SashLayoutWindow( self, self.ID_WINDOW_BOTTOM, 
                wx.DefaultPosition, wx.Size(800, settings.SCREEN[3]),
                wx.NO_BORDER|wx.SW_3D
                )
        #winids.append(win.GetId())
        #win.SetDefaultSize((WIDTH, self.output_default_height))
        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
        win.SetAlignment(wx.LAYOUT_BOTTOM)
        win.SetSashVisible(wx.SASH_TOP, True)
        self.bottomWindow = win
        self.output_window = LogWindow(self.bottomWindow)
        self.bottomWindow.SetDefaultSize(wx.Size(800, settings.SCREEN[3]))
        ####################
        self.grand_parent.ch = rurChoiceWindow(self.topWindow, self.grand_parent)
        self.topWindow.SetDefaultSize(wx.Size(800, self.grand_parent.BUTTON_HEIGHT))

        self.grand_parent.WorldEditor = wx.Panel(self.grand_parent.rightWindow, -1)
        self.grand_parent.ProgramEditor = rur_editor(self.leftWindow, -1)
        # to update from within WorldDisplay, create the following link
        self.grand_parent.WorldDisplay.editor = self.grand_parent.rightWindow
Exemplo n.º 19
0
    def __init__(self,
                 avenues=1,
                 streets=1,
                 orient_key='E',
                 beepers=0,
                 name='robot',
                 colour='grey',
                 parent=None):
        Robot_brain1.__init__(self, parent, avenues, streets, orient_key,
                              beepers)

        settings = conf.getSettings()

        self._delay = 0.3
        self.name = name
        self.colour = colour.lower()

        # The following are used to follow the robot trail
        self.line_trace = []
        self.set_trace_style(1, "sea green")  # default

        #--- Robot images
        # create a list of four objects
        if self.colour == 'yellow':
            self._image = [
                getImage(images.YELLOW_ROBOT_N),
                getImage(images.YELLOW_ROBOT_W),
                getImage(images.YELLOW_ROBOT_S),
                getImage(images.YELLOW_ROBOT_E)
            ]
        elif self.colour == 'blue':
            self._image = [
                getImage(images.BLUE_ROBOT_N),
                getImage(images.BLUE_ROBOT_W),
                getImage(images.BLUE_ROBOT_S),
                getImage(images.BLUE_ROBOT_E)
            ]
        elif self.colour == 'light blue':
            self._image = [
                getImage(images.LIGHT_BLUE_ROBOT_N),
                getImage(images.LIGHT_BLUE_ROBOT_W),
                getImage(images.LIGHT_BLUE_ROBOT_S),
                getImage(images.LIGHT_BLUE_ROBOT_E)
            ]
        elif self.colour == 'purple':
            self._image = [
                getImage(images.PURPLE_ROBOT_N),
                getImage(images.PURPLE_ROBOT_W),
                getImage(images.PURPLE_ROBOT_S),
                getImage(images.PURPLE_ROBOT_E)
            ]
        elif self.colour == 'green':
            self._image = [
                getImage(images.GREEN_ROBOT_N),
                getImage(images.GREEN_ROBOT_W),
                getImage(images.GREEN_ROBOT_S),
                getImage(images.GREEN_ROBOT_E)
            ]
        else:
            self._image = [
                getImage(images.GREY_ROBOT_N),
                getImage(images.GREY_ROBOT_W),
                getImage(images.GREY_ROBOT_S),
                getImage(images.GREY_ROBOT_E)
            ]

        self.imageOffset = (settings.SCREEN[7], settings.SCREEN[8])

        # image size (x, y) [all images equal]; for use in automatic scrolling
        self._image_size = self._image[0].GetWidth(), \
                           self._image[0].GetHeight()
        ## Note: for some reason, GetSize() did not work  using
        ## wxPython 2.4, which is why I used GetWidth() and GetHeight()

        # selecting the right image based on initial orientation
        self.robot_image = self._image[self._facing]
Exemplo n.º 20
0
                msgid = False
                value = line[8:-2]
            elif line.startswith('"') or line.startswith("'"):
                if msgid:
                    key += line[1:-2]
                elif msgstr:
                    value += line[1:-2]
            elif line.startswith("\n"):
                key = key.replace("\\n","")
                value = value.replace("\\n", "\n")
                translation[key] = value
                msgid = False
                msgstr = False
    return translation

rur_locale = conf.getSettings().LOCALE_DIR

for lang in conf.getAvailableLanguages():
    filename = os.path.join(rur_locale, lang, languages[lang][0]+'.po')
    languages[lang][1] = build_dict(filename)

def _select_code(langCode):
    global _selected
    for lang in  conf.getAvailableLanguages():
        if lang == langCode:
            _selected = languages[lang][1]
            conf.setLanguage(langCode)

def select(language):
    for lang in  conf.getAvailableLanguages():
        if language == languages[lang][2]: