예제 #1
0
파일: 08b15.py 프로젝트: tfari/08b15
    def __init__(self, size):
        """
        :param size: tuple
        """
        self.size = size
        self.running = True

        self.document = Document(self.size)
        self.screen_handler = ScreenHandler(self.size)
        self.input_handler = InputHandler()

        self.using_mode = 0
        pygame.display.set_mode(size)
예제 #2
0
def init_globals(masteruri):
    # initialize the global handler
    global _ssh_handler
    global _screen_handler
    global _start_handler
    global _name_resolution
    global _history
    global _file_watcher
    global _file_watcher_param
    _ssh_handler = SSHhandler()
    _screen_handler = ScreenHandler()
    _start_handler = StartHandler()
    _name_resolution = NameResolution()
    _history = History()
    _file_watcher = FileWatcher()
    _file_watcher_param = FileWatcher()

    # test where the roscore is running (local or remote)
    __is_local('localhost')  ## fill cache
    return __is_local(_name_resolution.getHostname(masteruri))  ## fill cache
예제 #3
0
def main():
    '''
  Creates and runs the ROS node.
  '''
    setTerminalName(NODE_NAME)
    setProcessName(NODE_NAME)
    try:
        from PySide.QtGui import QApplication
        from PySide.QtCore import QTimer
    except:
        print >> sys.stderr, "please install 'python-pyside' package!!"
        sys.exit(-1)
    rospy.init_node(NODE_NAME, log_level=rospy.DEBUG)
    # Initialize Qt
    global app
    app = QApplication(sys.argv)

    # initialize the global handler
    global _ssh_handler
    global _screen_handler
    global _start_handler
    global _name_resolution
    _ssh_handler = SSHhandler()
    _screen_handler = ScreenHandler()
    _start_handler = StartHandler()
    _name_resolution = NameResolution()

    #start the gui
    import main_window
    mainForm = main_window.MainWindow()
    if not rospy.is_shutdown():
        mainForm.show()
        exit_code = -1
        try:
            rospy.on_shutdown(finish)
            exit_code = app.exec_()
            mainForm.finish()
        finally:
            sys.exit(exit_code)
예제 #4
0
def main(name, anonymous=False):
    global CFG_PATH
    masteruri = masteruri_from_ros()
    CFG_PATH = ''.join([get_ros_home(), os.sep, 'node_manager', os.sep])
    '''
  Creates and runs the ROS node.
  '''
    if not os.path.isdir(CFG_PATH):
        os.makedirs(CFG_PATH)

    args = rospy.myargv(argv=sys.argv)
    # decide to show main or echo dialog
    if len(args) >= 4 and args[1] == '-t':
        name = ''.join([name, '_echo'])
        anonymous = True

    try:
        from PySide.QtGui import QApplication
    except:
        print >> sys.stderr, "please install 'python-pyside' package!!"
        sys.exit(-1)
    # start ROS-Master, if not currently running
    StartHandler._prepareROSMaster(masteruri)
    rospy.init_node(name, anonymous=anonymous, log_level=rospy.DEBUG)
    setTerminalName(rospy.get_name())
    setProcessName(rospy.get_name())

    # Initialize Qt
    global app
    app = QApplication(sys.argv)

    # decide to show main or echo dialog
    import main_window, echo_dialog
    global main_form
    if len(args) >= 4 and args[1] == '-t':
        show_hz_only = (len(args) > 4 and args[4] == '--hz')
        main_form = echo_dialog.EchoDialog(args[2], args[3], show_hz_only)
    else:
        # initialize the global handler
        global _ssh_handler
        global _screen_handler
        global _start_handler
        global _name_resolution
        global _history
        _ssh_handler = SSHhandler()
        _screen_handler = ScreenHandler()
        _start_handler = StartHandler()
        _name_resolution = NameResolution()
        _history = History()

        # test where the roscore is running (local or remote)
        __is_local('localhost')  ## fill cache
        __is_local(_name_resolution.getHostname(masteruri))  ## fill cache
        local_master = is_local(_name_resolution.getHostname(masteruri))

        #start the gui
        main_form = main_window.MainWindow(args, not local_master)

    if not rospy.is_shutdown():
        os.chdir(PACKAGE_DIR
                 )  # change path to be able to the images of descriptions
        main_form.show()
        exit_code = -1
        rospy.on_shutdown(finish)
        exit_code = app.exec_()
예제 #5
0
파일: input.py 프로젝트: UCSD-PL/kraken
from addressbar_handler import AddressBarHandler
from screen_handler import ScreenHandler
from message import MessageHandler

message_handler = MessageHandler()
ScreenHandler(message_handler).start()
AddressBarHandler(message_handler).start()
예제 #6
0
    def HandleRequest(self, byteRequest):
        '''
        Handle request sent by client.
        Request is handled, then passed to SendMessage to send a reply with appropriate data to client, this step is blocking.
        Parameters:
            requestString (str): the reqeust string
        Returns:
            int: either ServerProgram.CONTINUE or ServerProgram.QUIT_PROGRAM
        '''
        immediate = False
        request, data = self.SplitRequest(byteRequest)

        state = HandlerState.INVALID
        extraInfo = None

        if (type(self.currHandler) != DirectoryHandler
                or request != "TRANSFER") and data:
            data = data.decode(FORMAT)

        print(
            request, data if data and len(data) < 512 else
            (len(data) if data else ''))
        # FINISH request exits the current handler
        # EXIT request finishes the program
        if request == "FINISH":
            if self.currHandler:
                self.currHandler = None
                state = HandlerState.SUCCEEDED
            else:
                self.SendMessage("INVALID", None)
        elif request == "EXIT":
            self.currHandler = None
            self.SendMessage("SUCCEEDED", None)
            return ServerProgram.QUIT_PROGRAM
        # If no handler is currently active
        elif not self.currHandler:
            # SHUTDOWN and SCREENSHOT are immeditate handlers
            if request == "SHUTDOWN":
                self.currHandler = ShutdownHandler()
                immediate = True
            elif request == "SCREENSHOT":
                self.currHandler = ScreenHandler()
                immediate = True
            elif request == "INFO":
                self.currHandler = InfoHandler()
                immediate = True
            # The rest needs additional requests and looping
            else:
                immediate = False
                state = HandlerState.SUCCEEDED
                if request == "PROCESS":
                    self.currHandler = ProcessHandler()
                elif request == "APPLICATION":
                    self.currHandler = ApplicationHandler()
                elif request == "KEYLOG":
                    self.currHandler = InputHandler(KEYLOG_FILE_PATH)
                elif request == "REGISTRY":
                    self.currHandler = RegistryHandler()
                elif request == "DIRECTORY":
                    self.currHandler = DirectoryHandler()
                elif request == "LIVESTREAM":
                    self.currHandler = LivestreamHandler(
                        self, self.serverSocket, ScreenHandler())

        # Else let current handler handle request
        else:
            state, extraInfo = self.currHandler.Execute(request, data)

        if self.currHandler and immediate:
            state, extraInfo = self.currHandler.Execute("", data)
            self.currHandler = None
            immediate = False

        print(
            state, extraInfo if extraInfo and len(extraInfo) < 512 else
            (len(extraInfo) if extraInfo else ''))

        if request == "SHUTDOWN" and state == HandlerState.SUCCEEDED:
            self.SendMessage("SUCCEEDED", extraInfo)
            return ServerProgram.QUIT_PROGRAM

        if state == HandlerState.SUCCEEDED:
            self.SendMessage("SUCCEEDED", extraInfo)
        elif state == HandlerState.FAILED:
            self.SendMessage("FAILED", extraInfo)
        else:
            self.SendMessage("INVALID", extraInfo)

        return ServerProgram.CONTINUE_PROGRAM
예제 #7
0
        liveSocket, address = hostSocket.accept()

        TARGET_FPS = 30
        TIME_FRAME = 1 / TARGET_FPS

        frame = 0

        start = time.perf_counter()
        while not self.livestreamEvent.is_set():
            w, h, data = self.screenHandler.TakeScreenshotAsBytes(960, 540)
            state = SendMessage(liveSocket,
                                str(w) + " " + str(h) + " " + str(frame + 1),
                                data)
            if not state:
                self.HandleMessageFault()
                break
            frame += 1
            targetTime = frame * TIME_FRAME
            end = time.perf_counter()
            elapsed = (end - start)
            waitTime = targetTime - elapsed if targetTime >= elapsed else 0.0
            time.sleep(waitTime)

        liveSocket.close()


if __name__ == "__main__":
    DEBUG = True
    a = ScreenHandler()
    m, n = a.Execute("", "")