def __init__(self, session=None):
        self._session = session
        self._module_name = self.__class__.__name__
        self.__name__ = self._module_name
        self._logger = qi.Logger(self._module_name)
        self._logger.info(":::: Starting {} ::::".format(self._module_name))
        self._pref_domain = "tool.applauncher"  # @TODO: "com.sbr.apps.app-launcher"

        # public variables
        self._logger.info("Initializing public variables...")
        self.current_state = qi.Property("s")
        self.current_state.setValue("")
        self.current_page = qi.Property("s")
        self.current_page.setValue("Home")
        self.apps_full_list = qi.Property()
        self.apps_full_list.setValue({})
        self.pages_definition = qi.Property()
        self.pages_definition.setValue({})
        self.autonomous_enabled = qi.Property("b")
        self.autonomous_enabled.setValue(True)
        self.display_app_name = qi.Property("b")
        self.display_app_name.setValue(True)
        self.ping_required = qi.Signal("(i)")

        # internal variables
        self._logger.info("Initializing internal variables...")
        self._app_uuid = helpers.find_app_name(self._logger)
        self._current_app = ""
        self._preferences_manager = PreferencesManager(self._logger, self._session, self._pref_domain)
        self._app_list_manager = AppListManager(self._logger, self._session, self._preferences_manager,
                                                self._app_uuid, self.apps_full_list, self.pages_definition)
        self._view_manager = ViewManager(self._logger, self._session, self._preferences_manager,
                                         self._app_uuid, self.current_state, self.ping_required)
        self._dialog_manager = DialogManager(self._logger, self._session, self._preferences_manager,
                                             self.pages_definition, self.autonomous_enabled, self.current_page)

        _pref_display_app_name = self._preferences_manager.get_value('behaviorNameDisplayed', True)
        if _pref_display_app_name:
            self.display_app_name.setValue(True)
        else:
            self.display_app_name.setValue(False)

        self._logger.info(":::: Ready! ::::")
Beispiel #2
0
def run_game():
    # 初始化游戏
    pygame.init()
    # 创建ViewManager对象
    view_manager = ViewManager()
    # 设置显示屏幕,返回Surface对象
    screen = pygame.display.set_mode((view_manager.screen_width, 
        view_manager.screen_height))
    # 设置标题
    pygame.display.set_caption('合金弹头')

    while(True):
        # 处理游戏事件
        gf.check_events(screen, view_manager)
        # 更新游戏屏幕
        gf.update_screen(screen, view_manager, mm)
Beispiel #3
0
def run_game():
    # 初始化游戏
    pygame.init()
    # 创建ViewManager对象
    view_manager = ViewManager()
    # 设置显示屏幕,返回Surface对象
    screen = pygame.display.set_mode(
        (view_manager.screen_width, view_manager.screen_height))
    # 设置标题
    pygame.display.set_caption('合金弹头test')
    # 创建玩家角色
    player = Player(view_manager, '孙悟空', MAX_HP)
    while True:
        # 处理游戏事件
        gf.check_event(screen, view_manager, player)
        # 更新游戏屏幕
        gf.update_screen(screen, view_manager, mm, player)
Beispiel #4
0
def main():
    view = ViewManager()
    view.show_frame("ClockView")
    clock_thread = Thread(target=clock_process, args=(view, ), daemon=True)
    clock_thread.start()
    computer_thread = Thread(target=computer_process,
                             args=(view, ),
                             daemon=True)
    computer_thread.start()
    assistant_thread = Thread(target=assistant_process,
                              args=(view, ),
                              daemon=True)
    assistant_thread.start()
    view.mainloop()
Beispiel #5
0
def run_game():
    # 初始化游戏
    pygame.init()
    # 初始化混音器模块
    pygame.mixer.init()
    # 加载背景音乐
    pygame.mixer.music.load('music/background.mp3')
    # 创建ViewManager对象
    view_manager = ViewManager()
    # 设置显示屏幕,返回Surface对象
    screen = pygame.display.set_mode(
        (view_manager.screen_width, view_manager.screen_height))
    # 设置标题
    pygame.display.set_caption('合金弹头')
    # 创建玩家角色
    player = Player(view_manager, '孙悟空', MAX_HP)
    while (True):
        # 处理游戏事件
        gf.check_events(screen, view_manager, player)
        # 更新游戏屏幕
        gf.update_screen(screen, view_manager, mm, player)
        # 播放背景音乐
        if pygame.mixer.music.get_busy() == False:
            pygame.mixer.music.play()
Beispiel #6
0
                      seconds=10,
                      args=(traffic_records, RECORD_RETENTION_PERIOD))

    scheduler.add_job(display_current_rate,
                      'interval',
                      seconds=1,
                      args=(traffic_records, ))

    # this is the queue for receiving info from the network-sniffing subprocess
    incoming_data_queue = multiprocessing.Queue()

    # Putting the app inside this 'with' allows the client's terminal to be
    # restored to its former state on exit, even if the process doesn't exit
    # cleanly.
    with term.fullscreen(), term.cbreak(), term.hidden_cursor():
        view_manager = ViewManager(term)
        view_manager.update_listening_info(port, ip)

        # Initialize a sniffer
        sniffer = sniffers.get_sniffer(backend)
        # Start the sniffer in a new process
        snifferProcess = Process(target=sniffer.run_sniffer,
                                 args=(ip, port, incoming_data_queue))
        snifferProcess.daemon = True
        snifferProcess.start()

        # Start the scheduler
        scheduler.start()

        # Start the view update loop
        viewProcess = Process(target=view_manager.start_view_update_loop)
class AppLauncher:

    @qi.nobind
    def __init__(self, session=None):
        self._session = session
        self._module_name = self.__class__.__name__
        self.__name__ = self._module_name
        self._logger = qi.Logger(self._module_name)
        self._logger.info(":::: Starting {} ::::".format(self._module_name))
        self._pref_domain = "tool.applauncher"  # @TODO: "com.sbr.apps.app-launcher"

        # public variables
        self._logger.info("Initializing public variables...")
        self.current_state = qi.Property("s")
        self.current_state.setValue("")
        self.current_page = qi.Property("s")
        self.current_page.setValue("Home")
        self.apps_full_list = qi.Property()
        self.apps_full_list.setValue({})
        self.pages_definition = qi.Property()
        self.pages_definition.setValue({})
        self.autonomous_enabled = qi.Property("b")
        self.autonomous_enabled.setValue(True)
        self.display_app_name = qi.Property("b")
        self.display_app_name.setValue(True)
        self.ping_required = qi.Signal("(i)")

        # internal variables
        self._logger.info("Initializing internal variables...")
        self._app_uuid = helpers.find_app_name(self._logger)
        self._current_app = ""
        self._preferences_manager = PreferencesManager(self._logger, self._session, self._pref_domain)
        self._app_list_manager = AppListManager(self._logger, self._session, self._preferences_manager,
                                                self._app_uuid, self.apps_full_list, self.pages_definition)
        self._view_manager = ViewManager(self._logger, self._session, self._preferences_manager,
                                         self._app_uuid, self.current_state, self.ping_required)
        self._dialog_manager = DialogManager(self._logger, self._session, self._preferences_manager,
                                             self.pages_definition, self.autonomous_enabled, self.current_page)

        _pref_display_app_name = self._preferences_manager.get_value('behaviorNameDisplayed', True)
        if _pref_display_app_name:
            self.display_app_name.setValue(True)
        else:
            self.display_app_name.setValue(False)

        self._logger.info(":::: Ready! ::::")

    @qi.nobind
    def cleanup(self):
        try:
            self._logger.info(":::: Stopping app launcher... ::::")
        except NameError:
            print "╔══════════════════════════╦══════════════════════════╗"
            print "║ End of automatic logging ║ was the app uninstalled? ║"
            print "╚══════════════════════════╩══════════════════════════╝"

            class DummyLog:
                def __init__(self):
                    pass

                @staticmethod
                def verbose(*args):
                    for a in args:
                        print "verbose: {}".format(a)

                @staticmethod
                def info(*args):
                    for a in args:
                        print "info: {}".format(a)

                @staticmethod
                def warning(*args):
                    for a in args:
                        print "warning: {}".format(a)

                @staticmethod
                def error(*args):
                    for a in args:
                        print "error: {}".format(a)

            self._logger = DummyLog()
            self._dialog_manager._logger = self._logger
            self._view_manager._logger = self._logger
            self._app_list_manager._logger = self._logger
            self._app_list_manager._icons_storage._logger = self._logger
            self._preferences_manager._logger = self._logger
        try:
            # clean variables
            self._dialog_manager.cleanup()
            self._view_manager.cleanup()
            self._app_list_manager.cleanup()
            self._preferences_manager.cleanup()
        except Exception as e:
            self._logger.info("error while stopping app launcher: {}".format(e))

        # Reset states
        try:
            basic = self._session.service("ALBasicAwareness")
            basic.setEnabled(True)
        except Exception as e:
            self._logger.info("error while configuring ALBasicAwareness: {}".format(e))

        self._logger.info(":::: Stopped! ::::")

    """
        Public bound functions
    """
    @qi.bind(paramsType=[qi.Int32], returnType=qi.Void, methodName="ping")
    def ping(self, seconds_before_next_ping_request):
        """ This function should be called by the web page to signal that it is still alive.
        When the signal ping_required is raised, the web page should call this function.
        In case ping is not called in time, the tablet will be reset.

        Argument: delay in seconds before next ping will be asked."""
        self._view_manager.ping(seconds_before_next_ping_request)

    @qi.bind(paramsType=[], returnType=qi.Void, methodName="_updateAppList")
    def _update_app_list(self):
        """ Reload the list of applications and pages."""
        self._app_list_manager.update_app_lists(None, True)

    @qi.bind(paramsType=[qi.String], returnType=qi.Void, methodName="runBehavior")
    def run_behavior(self, behavior):
        """ Ask autonomous life to start a given behavior and check if the launch was ok after 15s.

        Argument: behavior to launch."""
        try:
            # If an error occurs during launch, the tablet will be displayed again
            app_launched_check = qi.async(self._view_manager.display_view, delay=15000000)
            # Life switch focus to the chosen app
            life = self._session.service("ALAutonomousLife")
            life.switchFocus(behavior)
            self._logger.info("Switch focus")
            app_launched_check.cancel()
            self._logger.info("Application launch end")

        except Exception as e:
            self._logger.error("Run behavior error: " + str(e))

    @qi.bind(paramsType=[], returnType=qi.Void, methodName="stopBehavior")
    def stop_behavior(self):
        """ Stop the current running behavior. """
        self._session.service('ALBehaviorManager').stop_behavior(self._current_app)
        self._logger.info("Stop behavior: {}" .format(self._current_app))

    @qi.bind(paramsType=[qi.Int32], returnType=qi.Void, methodName="adjustVolume")
    def adjust_volume(self, diff):
        """ Change the robot volume. The volume will not go higher than 100% or lower than 20%.

        Argument: delta (positive or negative) to add to the volume. """
        audio = self._session.service('ALAudioDevice')
        current_volume = audio.getOutputVolume()
        new_volume = current_volume + diff
        if new_volume > 100:
            new_volume = 100
        elif new_volume < 20:
            new_volume = 20
        audio.setOutputVolume(new_volume)
        self._logger.info("New volume: {}" .format(new_volume))
Beispiel #8
0
# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
size = (width, height)

root_view = RootMenu()
view_manager = ViewManager(size, root_view, '1')

try:
    while 1:
        if not GPIO.input(U_pin): # button is released
            view_manager.handle_key('up')

        if not GPIO.input(L_pin): # button is released
            view_manager.handle_key('left')

        if not GPIO.input(R_pin): # button is released
            view_manager.handle_key('right')

        if not GPIO.input(D_pin): # button is released
            view_manager.handle_key('down')