Example #1
0
class Main(App):
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)

    def build(self):
        self._cam = Camera(
            (Config.getint('graphics',
                           'width'), Config.getint('graphics', 'height')))
        self._control = ControlPanel()
        sm = ScreenManager(transition=NoTransition())
        sm.add_widget(DummyScreen(name='dummy'))
        sm.add_widget(SplashScreen(name='splash'))
        sm.add_widget(CalibrationScreen(self._cam, name='calibration'))
        sm.add_widget(PredictionScreen(self._cam, name='prediction'))
        sm.current = 'splash'
        Clock.schedule_interval(self.on_loop, 0.001)

        self._control.add_mode_sw_listener(
            sm.get_screen('prediction').changed_disp_mode)
        return sm

    def on_loop(self, dt):
        self._control.update()

    def on_stop(self):
        self._cam.release()
Example #2
0
 def __init__(self):
     self.__running = False
     self.screen = pygame.display.set_mode(
         (Consts.WINDOW_WIDTH, Consts.WINDOW_HEIGHT))
     self.__clock = pygame.time.Clock()  # frame clock
     self.__game_board = GameBoard()
     self.player = Player()
     self.control_panel = ControlPanel(self.player)
     self.caretaker = Caretaker(self.player)
Example #3
0
    def __init__(self):

        self.words_generator = WordGenerator('word.yml')
        self.layout = BoxLayout(orientation="vertical")
        self.keyboard = None
        self.control_panel = ControlPanel(self.start_timer, self.stop_ev,
                                          self.change_difficulty)
        self.timer = None
        self.stop_event = None
        self.tick_event = None
        self.ticks = MAX_TIME
        self.screen = Screen()
        self.difficulty = "Easy"
        super(TouchKeyboard, self).__init__()
Example #4
0
    def __init__(self):
        super().__init__()

        self.__windowTitle = "Firepost VA"
        self.__defaultSize = QtCore.QSize(1080, 720)

        self.thumbnailDisplay = ThumbnailDisplay()

        self.detailDisplay = DetailDisplay()

        self.controlPanel = ControlPanel()

        self.handler = Handler()
        self.watcher = Watcher(["./stream_0"], self.handler)

        # connect handler to thumbnail display
        self.handler.tx_sendpathtime.connect(self.watcher.SendImage)
        self.watcher.sendImage.connect(self.thumbnailDisplay.rx_put_thumbnail)
        self.setup_mainWidget()

        # connect handler to detail display
        self.handler.tx_sendpathtime.connect(
            self.detailDisplay.rx_write_details)

        # connect controlPanel button to watcher
        self.controlPanel.toggle_monitor_button.clicked.connect(
            self.watcher.rxToggleObserver)

        # this should be the last step
        self.setup_dashboard()
Example #5
0
    def build(self):
        self._cam = Camera(
            (Config.getint('graphics',
                           'width'), Config.getint('graphics', 'height')))
        self._control = ControlPanel()
        sm = ScreenManager(transition=NoTransition())
        sm.add_widget(DummyScreen(name='dummy'))
        sm.add_widget(SplashScreen(name='splash'))
        sm.add_widget(CalibrationScreen(self._cam, name='calibration'))
        sm.add_widget(PredictionScreen(self._cam, name='prediction'))
        sm.current = 'splash'
        Clock.schedule_interval(self.on_loop, 0.001)

        self._control.add_mode_sw_listener(
            sm.get_screen('prediction').changed_disp_mode)
        return sm
Example #6
0
    def __init__(self, simulation):
        super().__init__()
        self.simulation = simulation
        self.simulation.simulate_attractor()

        self.title(self.TITLE)
        self.place_window()

        # Visualization settings.
        self.control_panel = ControlPanel(master=self, simulation=simulation)
        self.animation_panel = tk.Frame(self)
        self.animation_panel.grid(row=0, column=1)
        figure = plt.figure(figsize=(7, 7))
        self.ax = figure.gca(projection='3d')
        self.ax.set_xlabel("X Axis")
        self.ax.set_ylabel("Y Axis")
        self.ax.set_zlabel("Z Axis")
        self.ax.set_title("Lorenz Attractor")

        self.canvas = FigureCanvasTkAgg(figure, self.animation_panel)
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tk.TOP,
                                         fill=tk.BOTH,
                                         expand=True)

        self.simulation.sim_animation = self

        self.plot(1)
Example #7
0
 def __init(cls, session, input_list):
     cls.__loading(session)      
     cls.filter_type = None
     cls.filter_str = ""
     cls.control_panel = ControlPanel(
         filter_type_list=cls.filter_types,
         input_list=input_list,
         loaded_list=cls.prelimi_wt
         )
Example #8
0
    def __init__(self, simulation):
        super().__init__()
        self.simulation = simulation

        self.title(self.TITLE)
        self.place_window()

        # Visualization settings.
        self.control_panel = ControlPanel(master=self, simulation=simulation)
        self.animation_panel = tk.Frame(self)
        self.animation_panel.grid(row=0, column=1)
        figure, axes = plt.subplots(ncols=2, figsize=(14, 7))
        self.graph = axes[1]
        self.graph.set_xlabel('Temperature[K]')
        self.graph.set_ylabel('Energy[meV]')
        self.image_anim = axes[0].imshow(self.simulation.lattice,
                                         interpolation='nearest',
                                         cmap=cm.get_cmap('coolwarm'),
                                         vmin=-1, vmax=1)

        # Set visibility of number axes of the animation
        self.image_anim.axes.get_xaxis().set_visible(False)
        self.image_anim.axes.get_yaxis().set_visible(False)

        self.canvas = FigureCanvasTkAgg(figure, self.animation_panel)
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH,
                                         expand=True)

        self.simulation.sim_animation = self

        # Quit settings with multi threading.
        self.protocol(Settings.TK_EXIT_BUTTON_CLICK, self.destroy_simulation)

        self.bind("<<REFRESH>>", self.plot)
        self.bind("<<REFRESH_TEMP_SLIDER>>",
                  lambda unused: self.control_panel.slider_temp.set(
                      self.simulation.temp))
Example #9
0
class TouchKeyboard(App):
    def __init__(self):

        self.words_generator = WordGenerator('word.yml')
        self.layout = BoxLayout(orientation="vertical")
        self.keyboard = None
        self.control_panel = ControlPanel(self.start_timer, self.stop_ev,
                                          self.change_difficulty)
        self.timer = None
        self.stop_event = None
        self.tick_event = None
        self.ticks = MAX_TIME
        self.screen = Screen()
        self.difficulty = "Easy"
        super(TouchKeyboard, self).__init__()

    def build(self):
        self.layout.add_widget(self.control_panel)
        self.layout.add_widget(self.screen)
        self.screen.difficulty.text = self.difficulty
        self.keyboard = Keyboard(self.screen.output, self.key_callback)
        self.layout.add_widget(self.keyboard)
        return self.layout

    def reshuffle_keys(self, instance):
        self.keyboard.generate_keyboard()

    def start_timer(self, instance: Button):
        self.control_panel.lock_controls()
        self.screen.output.text = ""
        self.screen.input.text = self.words_generator.generate_word(
            self.difficulty)
        self.timer = Timer.start(self.reshuffle_keys, CHANGE_TIME)
        self.tick_event = Timer.start(self.decrease_tick, 1)
        self.stop_event = Clock.schedule_once(self.stop_ev, MAX_TIME)

    def stop_ev(self, *largs):
        Clock.unschedule(self.timer)
        Clock.unschedule(self.stop_event)
        Clock.unschedule(self.tick_event)
        self.ticks = MAX_TIME
        self.control_panel.unlock_controls()
        self.screen.output.text = ""
        self.screen.time.text = str(self.ticks)
        self.screen.input.text = ""

    def decrease_tick(self, *largs):
        self.ticks -= 1
        self.screen.time.text = str(self.ticks)

    def key_callback(self, *largs):
        if self.screen.output.text == self.screen.input.text:
            self.stop_ev()
            self.show_win()

    def show_win(self):
        popup = Popup(title='Winner',
                      content=Label(text='You won', font_size='40sp'),
                      size_hint=(None, None),
                      size=(400, 400))
        popup.open()

    def change_difficulty(self, *largs):
        if self.difficulty == 'Easy':
            self.difficulty = 'Medium'
        elif self.difficulty == 'Medium':
            self.difficulty = 'Hard'
        else:
            self.difficulty = 'Easy'
        self.screen.difficulty.text = self.difficulty
Example #10
0
class Game:
    def __init__(self):
        self.__running = False
        self.screen = pygame.display.set_mode(
            (Consts.WINDOW_WIDTH, Consts.WINDOW_HEIGHT))
        self.__clock = pygame.time.Clock()  # frame clock
        self.__game_board = GameBoard()
        self.player = Player()
        self.control_panel = ControlPanel(self.player)
        self.caretaker = Caretaker(self.player)

    def start_game(self):
        pygame.display.set_caption("Silesian Game")
        self.__running = True
        self.__game_loop()

    def __game_loop(self):
        while self.__running:
            self.__clock.tick(Consts.FPS)
            self.__key_control()
            self.__draw()
            self.player.income_gold()
            pygame.display.update()

    def __draw(self):
        self.control_panel.draw(self.screen, self.player.get_gold())
        self.__game_board.draw(self.screen)
        self.player.draw_buildings(self.screen)

    def __build(self, building_type):
        if building_type == 0:
            if self.player.get_gold() >= Consts.WOODCUTTERS_HUT_COST:
                self.caretaker.store_snapshot()
                self.player.add_building(
                    WoodcuttersHut(self.player.next_building_position()))
                self.player.spend_gold(Consts.WOODCUTTERS_HUT_COST)
            else:
                print("Dont have enough gold!")
        elif building_type == 1:
            if self.player.get_gold() >= Consts.QUARRY_COST:
                self.caretaker.store_snapshot()
                self.player.add_building(
                    Quarry(self.player.next_building_position()))
                self.player.spend_gold(Consts.QUARRY_COST)
            else:
                print("Dont have enough gold!")
        elif building_type == 2:
            if self.player.get_gold() >= Consts.SAWMILL_COST:
                self.caretaker.store_snapshot()
                self.player.add_building(
                    Sawmill(self.player.next_building_position()))
                self.player.spend_gold(Consts.SAWMILL_COST)
            else:
                print("Dont have enough gold!")
        elif building_type == 3:
            if self.player.get_gold() >= Consts.GOLD_MINE_COST:
                self.caretaker.store_snapshot()
                self.player.add_building(
                    GoldMine(self.player.next_building_position()))
                self.player.spend_gold(Consts.GOLD_MINE_COST)
            else:
                print("Dont have enough gold!")
        elif building_type == 4:
            if self.player.get_gold() >= Consts.GOLD_MINT_COST:
                self.caretaker.store_snapshot()
                self.player.add_building(
                    GoldMint(self.player.next_building_position()))
                self.player.spend_gold(Consts.GOLD_MINT_COST)
            else:
                print("Dont have enough gold!")

    def __key_control(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.__running = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                building_type = self.__is_onclick(event.pos)
                if building_type in [0, 1, 2, 3, 4]:
                    if self.player.get_buildings_length(
                    ) >= Consts.NUMBER_OF_ROWS * Consts.NUMBER_OF_COLUMNS:
                        print("Cant build more!")
                        continue
                    self.__build(building_type)
                elif building_type == 5:
                    self.caretaker.undo()
                elif building_type == 6:
                    self.caretaker.redo()

    @staticmethod
    def __is_onclick(mouse_position):
        if (Consts.PANEL_BUILDING_0_POSITION[0] < mouse_position[0] <
                Consts.PANEL_BUILDING_0_POSITION[0] + Consts.ICON_SIZE
                and Consts.PANEL_BUILDING_0_POSITION[1] < mouse_position[1] <
                Consts.PANEL_BUILDING_0_POSITION[1] + Consts.ICON_SIZE):
            return 0
        elif (Consts.PANEL_BUILDING_1_POSITION[0] < mouse_position[0] <
              Consts.PANEL_BUILDING_1_POSITION[0] + Consts.ICON_SIZE
              and Consts.PANEL_BUILDING_1_POSITION[1] < mouse_position[1] <
              Consts.PANEL_BUILDING_1_POSITION[1] + Consts.ICON_SIZE):
            return 1
        elif (Consts.PANEL_BUILDING_2_POSITION[0] < mouse_position[0] <
              Consts.PANEL_BUILDING_2_POSITION[0] + Consts.ICON_SIZE
              and Consts.PANEL_BUILDING_2_POSITION[1] < mouse_position[1] <
              Consts.PANEL_BUILDING_2_POSITION[1] + Consts.ICON_SIZE):
            return 2
        elif (Consts.PANEL_BUILDING_3_POSITION[0] < mouse_position[0] <
              Consts.PANEL_BUILDING_3_POSITION[0] + Consts.ICON_SIZE
              and Consts.PANEL_BUILDING_3_POSITION[1] < mouse_position[1] <
              Consts.PANEL_BUILDING_3_POSITION[1] + Consts.ICON_SIZE):
            return 3
        elif (Consts.PANEL_BUILDING_4_POSITION[0] < mouse_position[0] <
              Consts.PANEL_BUILDING_4_POSITION[0] + Consts.ICON_SIZE
              and Consts.PANEL_BUILDING_4_POSITION[1] < mouse_position[1] <
              Consts.PANEL_BUILDING_4_POSITION[1] + Consts.ICON_SIZE):
            return 4
        elif (Consts.BACK_BUTTON_POSITION[0] < mouse_position[0] <
              Consts.BACK_BUTTON_POSITION[0] + Consts.ICON_SIZE
              and Consts.BACK_BUTTON_POSITION[1] < mouse_position[1] <
              Consts.BACK_BUTTON_POSITION[1] + Consts.ICON_SIZE):
            return 5
        elif (Consts.FORWARD_BUTTON_POSITION[0] < mouse_position[0] <
              Consts.FORWARD_BUTTON_POSITION[0] + Consts.ICON_SIZE
              and Consts.FORWARD_BUTTON_POSITION[1] < mouse_position[1] <
              Consts.FORWARD_BUTTON_POSITION[1] + Consts.ICON_SIZE):
            return 6
        else:
            return 7
Example #11
0
 def __init__(self, window, img):
     self.window = window
     self.control_panel = ControlPanel(self.window)
     self.workspace = Workspace(img)
     self.mouse_pos = Point(0, 0)
     self.sprite_outline_b = Point(0, 0)
Example #12
0
class App():
    def __init__(self, window, img):
        self.window = window
        self.control_panel = ControlPanel(self.window)
        self.workspace = Workspace(img)
        self.mouse_pos = Point(0, 0)
        self.sprite_outline_b = Point(0, 0)

    def add_slice(self, image: Image) -> None:
        """Add rough image slice to the image list."""
        self.control_panel.add_image(image)

    def add_final_subsprite(self, image: Image) -> None:
        """Add extracted sprite to final collection."""
        self.control_panel.add_final_subsprite(image)

    def change_mouse_pos(self, x: int, y: int) -> None:
        """Change the current mouse position."""
        self.mouse_pos = (x, y)

    def change_outline_end(self) -> None:
        """Change the outline's ending point."""
        self.workspace.change_outline_end(self.sheet_mouse_pos())

    def change_outline_start(self) -> None:
        """Change the outline's starting point."""
        self.workspace.change_outline_start(self.sheet_mouse_pos())

    def clear_slice_dir(self) -> None:
        """Delete the images in the slice dir."""
        for img in Path("slices").iterdir():
            if img.is_file():
                img.unlink()

    def crop_subsprite(self, img, mask) -> Image:
        """Return a cropped subsprite image."""
        box = self.workspace.crop_subsprite(mask)
        return img.crop(box)

    def first_preview_image(self) -> Image:
        """Return the first preview image."""
        return self.control_panel.preview_image(0)

    def get_pixel(self) -> Pixel:
        """Get single pixel's information."""
        return self.workspace.pixel(self.sheet_mouse_pos())

    def is_secondary_white(self) -> bool:
        """Return True is the secondary color is white."""
        return self.control_panel.is_secondary_white()

    def last_preview_image(self) -> Image:
        """Return the last preview image."""
        return self.control_panel.preview_image(-1)

    def p_color(self) -> Color:
        """Return the primary color choice."""
        return self.control_panel.get_primary_color()

    def pan_down(self) -> None:
        """Pan down on the workspace."""
        self.workspace.pan_down()

    def pan_left(self) -> None:
        """Pan left on the workspace."""
        self.workspace.pan_left()

    def pan_right(self) -> None:
        """Pan right on the workspace."""
        self.workspace.pan_right()

    def pan_up(self) -> None:
        """Pan up on the workspace."""
        self.workspace.pan_up()

    def ref_img_coords(self) -> Tuple[Point, Point]:
        """Return outline's A and B coordinates."""
        return self.workspace.ref_img_coords()

    def remove_secondary_color(self, sprite: Image) -> Image:
        """Set the secondary color's alpha to 0."""
        color = self.s_color()
        #KUDOS
        #https://stackoverflow.com/questions/28754852/how-to-set-alpha-value-of-a-pixel-in-python/28758075
        pixeldata = list(sprite.getdata())
        for i, pixel in enumerate(pixeldata):
            if pixel[:3] == color:
                pixeldata[i] = (255, 255, 255, 0)
        sprite.putdata(pixeldata)
        return sprite

    def s_color(self) -> Color:
        """Return the secondary color choice."""
        return self.control_panel.get_secondary_color()

    def sheet_scale(self) -> int:
        """Return sprite sheet scale size."""
        return self.workspace.sheet_scale()

    def slice(self) -> Image:
        """Return a slice of the spritesheet."""
        #TODO, separate the reference outline and the sheet outline
        coords = self.ref_img_coords()
        return self.workspace.slice(coords)

    def sliced_image(self) -> Image:
        """Returns the recently sliced image."""
        return self.control_panel.sliced_image()

    def sheet_coords(self) -> Tuple[int, int]:
        """Get sprite sheet's origin coordinates."""
        return self.workspace.sheet_coords()

    def sheet_mouse_pos(self) -> Point:
        """Get the mouse position relative to the sprite sheet."""
        x, y = self.sheet_coords()
        pos = self.mouse_pos
        return Point(int(pos[0] - x), int(pos[1] - y))

    def show_all_final_subsprites(self) -> None:
        self.control_panel.show_all_final_subsprites()

    def ref_mouse_pos(self) -> Point:
        """Get mouse position relative to the reference image."""
        x, y = self.sheet_coords()
        scale = self.sheet_scale()
        pos = self.mouse_pos
        return Point(int((pos[0] - x) // scale), int((pos[1] - y) // scale))

    def set_primary(self) -> None:
        """Set the primary color."""
        coord, color = self.get_pixel()
        self.control_panel.primary_color(coord, color)

    def set_secondary(self) -> None:
        """Set the secondary color."""
        coord, color = self.get_pixel()
        self.control_panel.secondary_color(coord, color)

    def zoom_in(self) -> None:
        """Zoom in on the workspace."""
        self.workspace.zoom_in()

    def zoom_out(self) -> None:
        """Zoom out on the workspace."""
        self.workspace.zoom_out()

    def reset(self) -> None:
        self.control_panel.reset()
        self.workspace.reset()
        self.clear_slice_dir()

    def update(self, dt) -> None:
        self.window.clear()
        self.workspace.update()
        self.control_panel.update()
Example #13
0
"""
Main class of the application. Used for testing purposes.
"""

from control_panel import ControlPanel

pccm_instance = ControlPanel()
pccm_instance.init_ds()
pccm_instance.init_mf()
pccm_instance.fit()
pccm_instance.print_df()

pccm_instance.plot()
Example #14
0
method=["BM","SGBM"][0]

print("Start initialization")
try: 
    # Stereo camera (independent thread)
    stereo_cam=StereoCam().start()

    # NXT LEGO control (independent thread)
    nxt=NXTControl()
    nxt_found=nxt.connect()

    # Disparity map estimation
    stereo=StereoMatch(method)

    # Stereo configurations
    control_panel=ControlPanel(stereo.get_params())

except Exception:
    print("Error in initialization")
    print(traceback.format_exc())
    
h,w=0,0

print("Start main loop. Exit with 'q'")
try: 
    while 1:
        start_time=time.time()

        im=stereo_cam.read()
        if type(im[0])==list:
            continue # waiting for the first image