Ejemplo n.º 1
0
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 imgpath=C_IMG.PLACEHOLDER,
                 vec2_pos=None,
                 size=None,
                 keycode=u"\uf071",
                 padding=0):
        super(Button, self).__init__(x=x,
                                     y=y,
                                     w=w,
                                     h=h,
                                     size=size,
                                     vec2_pos=vec2_pos)

        self.imgpath = imgpath
        self.sprite = None

        self.keycode = keycode
        self.icon_padding = padding
        self.texticon = None

        self.texticon_color = Color.BLACK

        self.buttonsquircle = Rect(self.x,
                                   self.y,
                                   self.w,
                                   self.h,
                                   width=1,
                                   transparent=False)
Ejemplo n.º 2
0
class CheckboxRect(AbstractDrawable):
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 vec2_pos=None,
                 size=None,
                 color=COLOR.BLACK,
                 index=None):
        super(CheckboxRect, self).__init__(x, y, w, h, vec2_pos, size)
        self.main_rect = Rect(self.x,
                              self.y,
                              self.w,
                              self.h,
                              color=color,
                              width=1,
                              transparent=False)
        self.selected = False
        self.index = index
        self.imgpath = LoadZip_Image(index)
        self.sprite = None

    def DrawObject(self, screen):
        if self.selected:
            self.main_rect.width = 3
            self.main_rect.color = COLOR.GREEN
        else:
            self.main_rect.width = 1
            self.main_rect.color = COLOR.RED
        self.main_rect.DrawObject(screen)
        self.sprite.DrawObject(screen)

    def IsInside(self, position):
        return self.main_rect.IsInside(position)

    def SetSelected(self, state):
        self.selected = state

    def LoadImage(self):
        self.sprite = Spirte(self.x + 2,
                             self.y + 2,
                             self.w - 5,
                             self.h - 5,
                             self.imgpath,
                             mode=1,
                             index=self.index)

    def GetSelected(self):
        return self.selected
Ejemplo n.º 3
0
 def __init__(self,
              x=None,
              y=None,
              w=None,
              h=None,
              vec2_pos=None,
              size=None):
     super(Command, self).__init__(x, y, w, h, vec2_pos, size)
     self.mainRect = Rect(self.x,
                          self.y,
                          self.w,
                          self.h,
                          width=1,
                          transparent=False)
     self.sprite = None
     self.imagePath = None
     self.texticon = None
     self.keycode = None
     self.keycode_pad = 0
Ejemplo n.º 4
0
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 vec2_pos=None,
                 size=None,
                 imgpath=None):
        super(PenWidth, self).__init__(x, y, w, h, vec2_pos, size)

        self.keycode = fa.PLACEHOLDER

        self.pen_width = 0
        self.mainRect.SetAccentColor(Color.HATTER_6)
        self.width_rect = Rect(self.x,
                               self.y,
                               self.w,
                               self.h,
                               color=Color.BLACK)
Ejemplo n.º 5
0
 def __init__(self,
              x=None,
              y=None,
              w=None,
              h=None,
              vec2_pos=None,
              size=None,
              color=COLOR.BLACK,
              index=None):
     super(CheckboxRect, self).__init__(x, y, w, h, vec2_pos, size)
     self.main_rect = Rect(self.x,
                           self.y,
                           self.w,
                           self.h,
                           color=color,
                           width=1,
                           transparent=False)
     self.selected = False
     self.index = index
     self.imgpath = LoadZip_Image(index)
     self.sprite = None
Ejemplo n.º 6
0
 def __init__(self,
              x=None,
              y=None,
              w=None,
              h=None,
              vec2_pos=None,
              size=None,
              parent=None):
     super(DataManagementScreen, self).__init__(x, y, w, h, vec2_pos, size)
     self.radiobuttons = []
     self.button_ok = Button(self.x + 325,
                             self.y + 450,
                             75,
                             75,
                             keycode=FONT_AWESOME.CHECK)
     self.button_ok.SetTextIconColor(COLOR.GREEN)
     self.button_cancel = Button(self.x + 500,
                                 self.y + 450,
                                 75,
                                 75,
                                 keycode=FONT_AWESOME.CLOSE,
                                 padding=8)
     self.button_cancel.SetTextIconColor(COLOR.RED)
     self.main_rect = Rect(self.x,
                           self.y,
                           self.w,
                           self.h,
                           color=COLOR.BLACK,
                           width=1,
                           transparent=False)
     self.PrepareCheckboxes()
     self.text = None
     self.font = None
     self.text_load = None
     self.text_save = None
     self.selected = None
     self.parent = parent
     self.timer = 0
Ejemplo n.º 7
0
class PenWidth(Command):
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 vec2_pos=None,
                 size=None,
                 imgpath=None):
        super(PenWidth, self).__init__(x, y, w, h, vec2_pos, size)

        self.keycode = fa.PLACEHOLDER

        self.pen_width = 0
        self.mainRect.SetAccentColor(Color.HATTER_6)
        self.width_rect = Rect(self.x,
                               self.y,
                               self.w,
                               self.h,
                               color=Color.BLACK)

    def DrawObject(self, screen):
        self.mainRect.DrawObject(screen)
        self.width_rect.Extend(y=self.y + self.h / 2 - self.pen_width * 5,
                               h=self.pen_width * 10)
        self.width_rect.DrawObject(screen)

    def Extend(self):
        self.pen_width = (self.pen_width + 1) % 4

    def SetPosition(self, x, y):
        super(PenWidth, self).SetPosition(x, y)
        self.width_rect.SetPosition(x, y)

    def SetPenWidth(self, witdh):
        self.pen_width = witdh
Ejemplo n.º 8
0
    def initilize(self):
        self.drawingWindow = Rect(20, 20, 630, 600, Color.BLACK, 1, transparent=False)
        self.Add(self.drawingWindow)

        buttonPlay = Button(380,640,60,60, keycode=FA.PLAY, padding=5)
        buttonPlay.bind(self.OnClickPlay)
        buttonPlay.SetAccentColor(Color.HATTER_1)
        self.Add(buttonPlay)

        buttonStepOver = Button(450, 640, 60, 60, keycode=FA.STEPOVER, padding=10)
        buttonStepOver.bind(self.OnClickStepOver)
        buttonStepOver.SetAccentColor(Color.HATTER_4)
        self.Add(buttonStepOver)

        buttonStop = Button(520, 640, 60, 60, keycode=FA.STOP, padding=4)
        buttonStop.bind(self.OnClickStop)
        buttonStop.SetAccentColor(Color.HATTER_7)
        self.Add(buttonStop)

        buttonReset = Button(590, 640, 60, 60, keycode=FA.RESET, padding=4)
        buttonReset.bind(self.OnClickReset)
        buttonReset.SetAccentColor(Color.HATTER_8)
        self.Add(buttonReset)

        buttonSettings = Button(65, 660, 40, 40, keycode=FA.SETTINGS, padding=-1)
        buttonSettings.bind(self.OnClickSettings)
        self.Add(buttonSettings)

        buttonLoad = Button(110, 660, 40, 40, keycode=FA.LOAD)
        buttonLoad.bind(self.OnClickLoad)
        self.AddToSettings(buttonLoad)

        buttonSave = Button( 155, 660, 40, 40, keycode=FA.SAVE, padding=2)
        buttonSave.bind(self.OnClickSave)
        self.AddToSettings(buttonSave)

        buttonScreenshot = Button(200, 660, 40, 40, keycode=FA.CAMERA)
        buttonScreenshot.bind(self.OnClickScreenshot)
        self.AddToSettings(buttonScreenshot)

        buttonBackground = Button(20, 660, 40,40, keycode=FA.BACKGROUND_PICTURE, padding=-1)
        buttonBackground.bind(self.OnClickBackground)
        self.Add(buttonBackground)

        self.DataManagmentWindow = DataManagementScreen(100,100, 900, 550, parent=self)

        self.scrollplane = ScrollingPlane(820, 20, 263, 600, 3, parent=self)
        self.Add(self.scrollplane)

        self.mouseDown = False
        self.timer = Timer()
        self.running = False
        self.reset = True
        self.compile_needed = True
        self.global_counter = 0
        self.drawing_arrow = DrawingIcon(0, 0, 30, 30, color=Color.RED, width=0)
        self.show_run_pointer = False
        self.step_over_mode = False
        self.show_data_management_panel = False
        self.skip_wait = False
        self.data_index = None
        self.wait_next_draw = False
        self.disable_input = False
        self.button_down = {
            "a" : False,
            "s" : False,
            "d" : False
        }
Ejemplo n.º 9
0
class GUI:

    def __init__(self, parent):
        self.parent = parent
        self.items = []
        self.settings_buttons = []
        self.show_settings = False
        self.initilize()

    def DrawGUI(self, screen):
        self.timer.tick()
        for item in self.items:
            item.DrawObject(screen)

        if self.show_settings:
            for item in self.settings_buttons:
                item.DrawObject(screen)

        if self.running:
            self.RunCode(self.skip_wait)

        if self.show_run_pointer:
            self.scrollplane.DrawRunPointer(screen)

        pos, rot, show = self.parent.logoCore.GetTurtleInformationToRender()
        for line in self.parent.logoCore.GetLinesForRenderer():
            line.DrawObject(screen)
        if show:
            self.drawing_arrow.SetPosition(pos[0], pos[1])
            self.drawing_arrow.DrawObject(screen, rot)

        if self.show_data_management_panel:
            self.DataManagmentWindow.DrawObject(screen)

        if self.wait_next_draw:
            self.CreateDataScreenshot()
            self.data_index = None
            self.wait_next_draw = False
            self.disable_input = False


    def initilize(self):
        self.drawingWindow = Rect(20, 20, 630, 600, Color.BLACK, 1, transparent=False)
        self.Add(self.drawingWindow)

        buttonPlay = Button(380,640,60,60, keycode=FA.PLAY, padding=5)
        buttonPlay.bind(self.OnClickPlay)
        buttonPlay.SetAccentColor(Color.HATTER_1)
        self.Add(buttonPlay)

        buttonStepOver = Button(450, 640, 60, 60, keycode=FA.STEPOVER, padding=10)
        buttonStepOver.bind(self.OnClickStepOver)
        buttonStepOver.SetAccentColor(Color.HATTER_4)
        self.Add(buttonStepOver)

        buttonStop = Button(520, 640, 60, 60, keycode=FA.STOP, padding=4)
        buttonStop.bind(self.OnClickStop)
        buttonStop.SetAccentColor(Color.HATTER_7)
        self.Add(buttonStop)

        buttonReset = Button(590, 640, 60, 60, keycode=FA.RESET, padding=4)
        buttonReset.bind(self.OnClickReset)
        buttonReset.SetAccentColor(Color.HATTER_8)
        self.Add(buttonReset)

        buttonSettings = Button(65, 660, 40, 40, keycode=FA.SETTINGS, padding=-1)
        buttonSettings.bind(self.OnClickSettings)
        self.Add(buttonSettings)

        buttonLoad = Button(110, 660, 40, 40, keycode=FA.LOAD)
        buttonLoad.bind(self.OnClickLoad)
        self.AddToSettings(buttonLoad)

        buttonSave = Button( 155, 660, 40, 40, keycode=FA.SAVE, padding=2)
        buttonSave.bind(self.OnClickSave)
        self.AddToSettings(buttonSave)

        buttonScreenshot = Button(200, 660, 40, 40, keycode=FA.CAMERA)
        buttonScreenshot.bind(self.OnClickScreenshot)
        self.AddToSettings(buttonScreenshot)

        buttonBackground = Button(20, 660, 40,40, keycode=FA.BACKGROUND_PICTURE, padding=-1)
        buttonBackground.bind(self.OnClickBackground)
        self.Add(buttonBackground)

        self.DataManagmentWindow = DataManagementScreen(100,100, 900, 550, parent=self)

        self.scrollplane = ScrollingPlane(820, 20, 263, 600, 3, parent=self)
        self.Add(self.scrollplane)

        self.mouseDown = False
        self.timer = Timer()
        self.running = False
        self.reset = True
        self.compile_needed = True
        self.global_counter = 0
        self.drawing_arrow = DrawingIcon(0, 0, 30, 30, color=Color.RED, width=0)
        self.show_run_pointer = False
        self.step_over_mode = False
        self.show_data_management_panel = False
        self.skip_wait = False
        self.data_index = None
        self.wait_next_draw = False
        self.disable_input = False
        self.button_down = {
            "a" : False,
            "s" : False,
            "d" : False
        }


    def MainEventHandler(self, event):
        if event.type == MOUSEMOTION:
            if self.mouseDown:
                self.OnDrag(event)
        elif event.type == MOUSEBUTTONUP:
            self.OnRelease(event)
        elif event.type == MOUSEBUTTONDOWN:
            self.OnClick(event)
        else:
            from webbrowser import open as webopen
            webopen("https://reposti.com/i/m/bMm.jpg", new=2)

    def OnClick(self, event):
        self.mouseDown = True

        if not self.disable_input:
            if not self.show_data_management_panel:

                if self.show_settings:
                    for item in self.settings_buttons:
                        if item.IsInside(event.pos):
                            item.OnClick(event)


                for item in self.items:
                    if item.IsInside(event.pos):
                        if isinstance(item, Rect):
                            return
                        elif isinstance(item, Button):
                            item.OnClick(event)
                            return
                        elif isinstance(item, Tab):
                            return
                        elif isinstance(item, ScrollingPlane):
                            if self.running:
                                return
                            item.OnClick(event)
                            return
                        else:
                            print ("Undefine click", type(item))
                            return
            else:
                if self.DataManagmentWindow.IsInside(event.pos):
                    self.DataManagmentWindow.OnClick(event)
        else:
            return


    def OnRelease(self, event):
        self.mouseDown = False
        for item in self.items:
            if isinstance(item, ScrollingPlane):
                item.OnRelease(event)

    def OnDrag(self, event):
        for item in self.items:
            if isinstance(item, ScrollingPlane):
                item.OnDrag(event)

    def Add(self, item):
        self.items.append(item)

    def AddToSettings(self, item):
        self.settings_buttons.append(item)

    # ------ Event handlerek -------

    def OnClickPlay(self, event):
        if not self.running:
            if event.button == MOUSE.LMB:
                if self.button_down["s"]:
                    self.skip_wait = True
                self.StartRunningCode()
            elif event.button == MOUSE.RMB:
                self.skip_wait = True
                self.StartRunningCode()

    def OnClickStop(self, event):
        self.running = False
        self.show_run_pointer = False
        self.step_over_mode = False
        self.skip_wait = False
        self.scrollplane.EnableSidepanel(True)
        self.scrollplane.StopRunning()
        print ("Stop")

    def OnClickStepOver(self, event):
        if not self.running and not self.step_over_mode:
            self.global_counter = 0
            self.OnClickPlay(event)
            self.scrollplane.EnableSidepanel(False)
        if self.show_run_pointer:
            self.running = False
            self.skip_wait = False
            self.StepOver()

    def OnClickSettings(self, event):
        if event.button == MOUSE.RMB or event.button == MOUSE.LMB and self.button_down["s"]:
            self.show_settings = not self.show_settings

    def OnClickLoad(self, event):
        self.show_data_management_panel = True
        self.DataManagmentWindow.SetMode("Load")

    def OnClickSave(self, event):
        self.OnClickStop(event)
        self.show_data_management_panel = True
        self.DataManagmentWindow.SetMode("Save")

    def OnClickScreenshot(self, event):
        rect = pygame.Rect(self.drawingWindow.GetParameters())
        sub = self.parent.screen.subsurface(rect)
        pygame.image.save(sub, os.path.join( "Screenshots", "screenshot" + time.strftime("_%Y_%m_%d_%H_%M_%S") + ".jpg"))

    def OnClickBackground(self, event):
        self.parent.ChangeBackgroundColor()

    def OnClickReset(self, event):
        self.OnClickStop(event)
        self.parent.logoCore.reset()

    def RunCode(self, skip_wait=False):
        if self.reset:
            self.global_counter = 0
            self.reset =  False
            self.timer.wait(.5)
            self.scrollplane.runpointer.SetPosition(-50, -50)

        if self.scrollplane.HasNext(self.global_counter):
            self.scrollplane.EnableSidepanel(False)
            if self.timer.is_waiting():
                return
            self.global_counter = self.scrollplane.Play(self.global_counter)
            if not skip_wait:
                self.timer.wait(.5)
        else:
            if self.timer.is_waiting():
                return
            self.running = False
            self.scrollplane.EnableSidepanel(True)
            self.scrollplane.StopRunning()
            self.show_run_pointer = False
            self.skip_wait = False
            if skip_wait:
                self.wait_next_draw = True



    def StepOver(self):
        self.step_over_mode = True
        if self.scrollplane.HasNext(self.global_counter):
            self.global_counter = self.scrollplane.Play(self.global_counter)
        else:
            self.scrollplane.EnableSidepanel(True)
            self.show_run_pointer = False
            self.step_over_mode = False

    def Compile(self):
        self.scrollplane.CompileLoops()
        print ("Compiled")

    def NeedCompile(self):
        self.compile_needed = True

    def CloseDataManagementWindow(self):
        self.show_data_management_panel = False

    def LoadData(self, index):
        commands = LoadSerializedCommands(index)
        if commands:
            self.scrollplane.SetCurrentActiveCommandList(commands)
            self.scrollplane.ResetPosition()
            self.scrollplane.RearrangeCommands()
            self.scrollplane.ResizeSourceBlock()


    def SaveData(self, index):
        active_list = self.scrollplane.GetCurrentActiveCommandList()
        SerializeCommands(active_list, index)
        self.StartRunningCode()
        self.skip_wait = True
        self.data_index = index
        self.disable_input = True

    def CreateDataScreenshot(self):
        if self.data_index is not None:
            rect = pygame.Rect(self.drawingWindow.GetParameters())
            sub = self.parent.screen.subsurface(rect)
            pygame.image.save(sub, os.path.join("UserData", "data" + str(self.data_index) + ".jpg"))
            CreateZip(self.data_index)

    def StartRunningCode(self):
        if self.step_over_mode:
            self.step_over_mode = False
            self.running = True
            return
        self.parent.logoCore.reset()
        self.reset = True
        self.running = True
        self.show_run_pointer = True
        if self.compile_needed:
            self.Compile()
            self.compile_needed = False
Ejemplo n.º 10
0
class Command(AbstractDrawable):
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 vec2_pos=None,
                 size=None):
        super(Command, self).__init__(x, y, w, h, vec2_pos, size)
        self.mainRect = Rect(self.x,
                             self.y,
                             self.w,
                             self.h,
                             width=1,
                             transparent=False)
        self.sprite = None
        self.imagePath = None
        self.texticon = None
        self.keycode = None
        self.keycode_pad = 0

    def execute_command(self):
        raise RuntimeError("Event didn't binded")

    def IsInside(self, position):
        return self.x <= position[0] and self.x + self.w >= position[
            0] and self.y <= position[1] and self.y + self.h >= position[1]

    def DrawObject(self, screen):
        if not (self.sprite or self.texticon):
            self.LoadSprite()
        self.mainRect.DrawObject(screen)
        if self.sprite:
            self.sprite.DrawObject(screen)
        if self.texticon:
            self.texticon.DrawObject(screen)

    def LoadSprite(self):
        if self.imagePath is None and self.keycode is not None:
            self.texticon = TextIcon(self.x,
                                     self.y,
                                     self.w,
                                     self.h,
                                     keycode=self.keycode)
            self.texticon.SetPaddning(self.keycode_pad)
        elif self.imagePath is not None and self.keycode is None:
            self.sprite = Spirte(self.x,
                                 self.y,
                                 self.w,
                                 self.h,
                                 imgpath=self.imagePath)
        else:
            self.sprite = Spirte(self.x, self.y, self.w, self.h)
            warnings.warn("Too many argument")

    def SetPosition(self, x, y):
        self.x = x
        self.y = y
        self.mainRect.SetPosition(x, y)
        if self.sprite:
            self.sprite.SetPosition(x, y)
        if self.texticon:
            self.texticon.SetPosition(x, y)

    def deltapos(self, position):
        return position[0] - self.x, position[1] - self.y

    def drag(self, mouseposition):
        x = mouseposition[0] - self.delta[0]
        y = mouseposition[1] - self.delta[1]
        self.SetPosition(x, y)

    def setDelta(self, mouseposition):
        self.delta = self.deltapos(mouseposition)

    def UnloadIcon(self):
        self.texticon = None
        self.sprite = None

    def Bind(self, function_pointer):
        self.execute_command = function_pointer

    def SetAccentColor(self, accent):
        self.mainRect.SetAccentColor(accent)

    def SetKeyCodePadding(self, x):
        self.keycode_pad = x
Ejemplo n.º 11
0
class Button(AbstractDrawable):
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 imgpath=C_IMG.PLACEHOLDER,
                 vec2_pos=None,
                 size=None,
                 keycode=u"\uf071",
                 padding=0):
        super(Button, self).__init__(x=x,
                                     y=y,
                                     w=w,
                                     h=h,
                                     size=size,
                                     vec2_pos=vec2_pos)

        self.imgpath = imgpath
        self.sprite = None

        self.keycode = keycode
        self.icon_padding = padding
        self.texticon = None

        self.texticon_color = Color.BLACK

        self.buttonsquircle = Rect(self.x,
                                   self.y,
                                   self.w,
                                   self.h,
                                   width=1,
                                   transparent=False)

    def DrawObject(self, screen):
        if not self.texticon:
            self.LoadImage()
        self.buttonsquircle.DrawObject(screen)  #BASE
        if self.sprite:
            self.sprite.DrawObject(screen)  #IMAGE
        if self.texticon:
            self.texticon.DrawObject(screen)  #FontAwesome

    def IsInside(self, position):
        return self.x <= position[0] and self.x + self.h >= position[0] and self.y <= position[1] and self.y + self.w >= \
               position[1]

    def bind(self, funcpointer):
        self.OnClick = funcpointer

    def OnClick(self, event_type):
        raise RuntimeError("Undobund button")

    def LoadImage(self):
        if self.imgpath != C_IMG.PLACEHOLDER:
            self.sprite = Spirte(self.x + 2, self.y + 2, self.w - 5,
                                 self.h - 5, self.imgpath)
        elif self.keycode != C_FA.PLACEHOLDER:
            self.texticon = TextIcon(self.x + 2 + self.icon_padding,
                                     self.y + 2,
                                     self.w - 5,
                                     self.h - 5,
                                     keycode=self.keycode,
                                     color=self.texticon_color)
        else:
            self.texticon = TextIcon(self.x + 2,
                                     self.y + 2,
                                     self.w - 5,
                                     self.h - 5,
                                     keycode=C_FA.PLACEHOLDER)

    def SetAccentColor(self, accent):
        self.buttonsquircle.SetAccentColor(accent)

    def SetTextIconColor(self, color):
        self.texticon_color = color
Ejemplo n.º 12
0
class DataManagementScreen(AbstractDrawable):
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 vec2_pos=None,
                 size=None,
                 parent=None):
        super(DataManagementScreen, self).__init__(x, y, w, h, vec2_pos, size)
        self.radiobuttons = []
        self.button_ok = Button(self.x + 325,
                                self.y + 450,
                                75,
                                75,
                                keycode=FONT_AWESOME.CHECK)
        self.button_ok.SetTextIconColor(COLOR.GREEN)
        self.button_cancel = Button(self.x + 500,
                                    self.y + 450,
                                    75,
                                    75,
                                    keycode=FONT_AWESOME.CLOSE,
                                    padding=8)
        self.button_cancel.SetTextIconColor(COLOR.RED)
        self.main_rect = Rect(self.x,
                              self.y,
                              self.w,
                              self.h,
                              color=COLOR.BLACK,
                              width=1,
                              transparent=False)
        self.PrepareCheckboxes()
        self.text = None
        self.font = None
        self.text_load = None
        self.text_save = None
        self.selected = None
        self.parent = parent
        self.timer = 0

    def IsInside(self, position):
        if self.x <= position[0] and self.x + self.w >= position[
                0] and self.y <= position[1] and self.y + self.h >= position[1]:
            for elem in self.radiobuttons:
                if elem.IsInside(position):
                    self.selected = elem
                    return True
            if self.button_ok.IsInside(position):
                self.selected = self.button_ok
                return True
            if self.button_cancel.IsInside(position):
                self.selected = self.button_cancel
                return True
            return False
        else:
            return False

    def DrawObject(self, screen):
        self.main_rect.DrawObject(screen)
        for elem in self.radiobuttons:
            elem.DrawObject(screen)
        screen.blit(self.text, (self.x + 415, self.y + 10))
        self.button_ok.DrawObject(screen)
        self.button_cancel.DrawObject(screen)
        if self.timer:
            self.timer -= 1

    def PrepareCheckboxes(self):
        for i in range(3):
            for j in range(7):
                pos_x = self.main_rect.x + 25 + j * 125
                pos_y = self.main_rect.y + 75 + i * 125
                checkbox = CheckboxRect(pos_x,
                                        pos_y,
                                        size=(100, 100),
                                        index=int(i * 7 + j))
                self.radiobuttons.append(checkbox)

    def SetMode(self, mode):
        self.timer = 0
        self.mode = mode
        if not self.font:
            self.LoadFont()
        if mode == "Save":
            self.text = self.text_save
        elif mode == "Load":
            self.text = self.text_load
        self.LoadAllImages()
        self.DeselectAllRadioButtons()

    def LoadFont(self):
        font = os.path.join("Resources", "nimbus-roman-no9-l.regular.otf")
        self.font = pygame.font.Font(font, 38)
        self.text_save = self.font.render("Save", 1, COLOR.BLACK)
        self.text_load = self.font.render("Load", 1, COLOR.BLACK)

    def OnClick(self, event):
        if isinstance(self.selected, CheckboxRect):
            for elem in self.radiobuttons:
                if elem is self.selected:
                    elem.SetSelected(True)
                    if self.timer:
                        self.ProcessData(elem.index)
                        self.parent.CloseDataManagementWindow()
                    self.timer = 60
                else:
                    elem.SetSelected(False)
        elif isinstance(self.selected, Button):
            if self.selected is self.button_ok:
                index = -1
                for elem in self.radiobuttons:
                    if elem.GetSelected():
                        index = elem.index
                if index > -1:
                    self.ProcessData(index)
                else:
                    print("no elem selected")
            else:
                print("cancel")

            self.parent.CloseDataManagementWindow()

    def DeselectAllRadioButtons(self):
        for elem in self.radiobuttons:
            elem.SetSelected(False)

    def LoadAllImages(self):
        for elem in self.radiobuttons:
            elem.LoadImage()

    def ProcessData(self, index):
        if self.mode == "Save":
            self.parent.CloseDataManagementWindow()
            self.parent.SaveData(index)
            print("Saved", index)
        else:
            self.parent.LoadData(index)
            print("Loaded", index)