示例#1
0
def dump_menuactions(display, xid):
    from xpra.util import AdHocStruct
    w = AdHocStruct()
    w.xid = xid
    try:
        props = get_menuaction_props(w)
    except Exception as e:
        log.error("Error: failed to get menus / actions for window %s:", w)
        log.error(" %s", e)
        return None

    log("gtk menu properties for window %#x on display %s: %s", xid, display.get_name(), props)
    app_id      = props.get("application-id")
    bus_name    = props.get("bus-name")
    app_path    = props.get("application-path")
    menu_path   = props.get("app-menu-path")
    window_path = props.get("window-path")
    if not (app_id and bus_name and app_path and menu_path and window_path):
        log.error("Error: some properties are missing - cannot continue")
        return

    return query_menuactions(app_id, bus_name,
                             app_path,      None, None,
                             window_path,   None, None,
                             menu_path,     None, None)
示例#2
0
文件: gui.py 项目: svn2github/Xpra
def main():
    from xpra.platform import init, clean
    try:
        init("Platform-Events", "Platform Events Test")
        import sys
        if "-v" in sys.argv or "--verbose" in sys.argv:
            from xpra.platform.win32.win32_events import log as win32_event_logger
            log.enable_debug()
            win32_event_logger.enable_debug()

        def suspend():
            log.info("suspend event")
        def resume():
            log.info("resume event")
        fake_client = AdHocStruct()
        fake_client.window_with_grab = None
        fake_client.suspend = suspend
        fake_client.resume = resume
        fake_client.keyboard_helper = None
        ClientExtras(fake_client)

        import gobject
        gobject.threads_init()

        log.info("Event loop is running")
        loop = gobject.MainLoop()
        try:
            loop.run()
        except KeyboardInterrupt:
            log.info("exiting on keyboard interrupt")
    finally:
        #this will wait for input on win32:
        clean()
示例#3
0
文件: gui.py 项目: svn2github/Xpra
 def force_ungrab(self, wid):
     kh = self.client.keyboard_helper
     if not kh:
         if not self._kh_warning:
             self._kh_warning = True
             log.warn("no keyboard support, cannot simulate keypress to lose grab!")
         return
     #xkbmap_keycodes is a list of: (keyval, name, keycode, group, level)
     ungrab_keys = [x for x in kh.xkbmap_keycodes if x[1]==UNGRAB_KEY]
     if len(ungrab_keys)==0:
         if not self._kh_warning:
             self._kh_warning = True
             log.warn("ungrab key %s not found, cannot simulate keypress to lose grab!", UNGRAB_KEY)
         return
     #ungrab_keys.append((65307, "Escape", 27, 0, 0))     #ugly hardcoded default value
     ungrab_key = ungrab_keys[0]
     log("lost focus whilst window %s has grab, simulating keypress: %s", wid, ungrab_key)
     key_event = AdHocStruct()
     key_event.keyname = ungrab_key[1]
     key_event.pressed = True
     key_event.modifiers = []
     key_event.keyval = ungrab_key[0]
     keycode = ungrab_key[2]
     try:
         key_event.string = chr(keycode)
     except:
         key_event.string = str(keycode)
     key_event.keycode = keycode
     key_event.group = 0
     #press:
     kh.send_key_action(wid, key_event)
     #unpress:
     key_event.pressed = False
     kh.send_key_action(wid, key_event)
示例#4
0
 def __init__(self, sock, addr, new_websocket_client, web_root="/usr/share/xpra/www/"):
     self.web_root = web_root
     self._new_websocket_client = new_websocket_client
     server = AdHocStruct()
     server.logger = log
     server.run_once = True
     server.verbose = WEBSOCKET_DEBUG
     WebSocketRequestHandler.__init__(self, sock, addr, server)
示例#5
0
 def __init__(self, sock, addr,
              web_root="/usr/share/xpra/www/",
              http_headers_dir="/usr/share/xpra/http-headers", script_paths=None):
     self.web_root = web_root
     self.http_headers_dir = http_headers_dir
     self.script_paths = script_paths or {}
     server = AdHocStruct()
     server.logger = log
     self.directory_listing = DIRECTORY_LISTING
     BaseHTTPRequestHandler.__init__(self, sock, addr, server)
示例#6
0
def main():
    from xpra.platform import program_context
    with program_context("Platform-Events", "Platform Events Test"):
        if "-v" in sys.argv or "--verbose" in sys.argv:
            from xpra.platform.win32.win32_events import log as win32_event_logger
            log.enable_debug()
            win32_event_logger.enable_debug()

        import gobject
        gobject.threads_init()      #@UndefinedVariable

        log.info("Event loop is running")
        loop = gobject.MainLoop()

        def suspend():
            log.info("suspend event")
        def resume():
            log.info("resume event")
        fake_client = AdHocStruct()
        fake_client._focused = False
        fake_client.keyboard_grabbed = False
        fake_client.window_with_grab = None
        fake_client.suspend = suspend
        fake_client.resume = resume
        fake_client.keyboard_helper = None
        def signal_quit(*args):
            loop.quit()
        fake_client.signal_disconnect_and_quit = signal_quit
        ClientExtras(fake_client, None)

        try:
            loop.run()
        except KeyboardInterrupt:
            log.info("exiting on keyboard interrupt")
示例#7
0
文件: websocket.py 项目: cattaka/Xpra
 def __init__(self, sock, addr, new_websocket_client, web_root="/usr/share/xpra/www/", http_headers_dir="/usr/share/xpra/http-headers", script_paths={}, disable_nagle=True):
     self.web_root = web_root
     self.http_headers_dir = http_headers_dir
     self._new_websocket_client = new_websocket_client
     self.script_paths = script_paths
     server = AdHocStruct()
     server.logger = log
     server.run_once = True
     server.verbose = WEBSOCKET_DEBUG
     self.disable_nagle_algorithm = disable_nagle
     WebSocketRequestHandler.__init__(self, sock, addr, server)
示例#8
0
 def __init__(self, sock, addr,
              web_root="/usr/share/xpra/www/",
              http_headers_dirs=("/etc/xpra/http-headers",), script_paths=None):
     self.web_root = web_root
     self.http_headers_dirs = http_headers_dirs
     self.script_paths = script_paths or {}
     server = AdHocStruct()
     server.logger = log
     self.directory_listing = DIRECTORY_LISTING
     self.extra_headers = {}
     super().__init__(sock, addr, server)
示例#9
0
 def __init__(self,
              sock,
              addr,
              new_websocket_client,
              web_root="/usr/share/xpra/www/"):
     self.web_root = web_root
     self._new_websocket_client = new_websocket_client
     server = AdHocStruct()
     server.logger = log
     server.run_once = True
     server.verbose = WEBSOCKET_DEBUG
     WebSocketRequestHandler.__init__(self, sock, addr, server)
示例#10
0
 def add_window(self, model, x, y, w, h):
     assert self.flags() & gtk.REALIZED
     s = AdHocStruct()
     s.shown = False
     s.geom = [x, y, w, h]
     self._models[model] = s
     model.connect("unmanaged", self._unmanaged)
     model.connect("ownership-election", self._elect_me)
     def new_geom(window_model, *args):
         log("new_geom(%s,%s)", window_model, args)
     model.connect("notify::geometry", new_geom)
     model.ownership_election()
示例#11
0
    def sound_data(self, codec, data, metadata, packet_metadata=()):
        log("sound_data(%s, %s, %s, %s) sound sink=%s", codec, len(data or []),
            metadata, packet_metadata, self.sound_sink)
        if self.is_closed():
            return
        if self.sound_sink is not None and codec != self.sound_sink.codec:
            log.info("sound codec changed from %s to %s",
                     self.sound_sink.codec, codec)
            self.sound_sink.cleanup()
            self.sound_sink = None
        if metadata.get("end-of-stream"):
            log("client sent end-of-stream, closing sound pipeline")
            self.stop_receiving_sound()
            return
        if not self.sound_sink:
            if not self.audio_loop_check("microphone"):
                #make a fake object so we don't fire the audio loop check warning repeatedly
                from xpra.util import AdHocStruct
                self.sound_sink = AdHocStruct()
                self.sound_sink.codec = codec

                def noop(*_args):
                    pass

                self.sound_sink.add_data = noop
                self.sound_sink.cleanup = noop
                return
            try:

                def sound_sink_error(*args):
                    log("sound_sink_error%s", args)
                    log.warn("stopping sound input because of error")
                    self.stop_receiving_sound()

                from xpra.sound.wrapper import start_receiving_sound
                ss = start_receiving_sound(codec)
                if not ss:
                    return
                self.sound_sink = ss
                log("sound_data(..) created sound sink: %s", self.sound_sink)
                ss.connect("error", sound_sink_error)
                ss.start()
                log("sound_data(..) sound sink started")
            except Exception:
                log.error("failed to setup sound", exc_info=True)
                return
        if packet_metadata:
            if not self.sound_properties.boolget("bundle-metadata"):
                for x in packet_metadata:
                    self.sound_sink.add_data(x)
                packet_metadata = ()
        self.sound_sink.add_data(data, metadata, packet_metadata)
示例#12
0
    def test_webcam(self):
        if not POSIX or OSX:
            get_util_logger().info("webcam test skipped: %s not supported yet",
                                   sys.platform)
            return
        from xpra.platform.xposix.webcam import get_virtual_video_devices, check_virtual_dir
        if not check_virtual_dir():
            get_util_logger().info(
                "webcam test skipped: no virtual video device directory")
            return
        devices = get_virtual_video_devices()
        if not devices:
            get_util_logger().info(
                "webcam test skipped: no virtual video devices found")
            return
        from xpra.server.source.webcam_mixin import WebcamMixin
        server = AdHocStruct()
        wm = WebcamMixin()
        server.webcam_enabled = True
        server.webcam_device = None
        server.webcam_encodings = ["png", "jpeg"]
        wm.init_from(None, server)
        wm.init_state()
        wm.hello_sent = True
        packets = []

        def send(*args):
            packets.append(args)

        #wm.send = send
        wm.send_async = send
        try:
            assert wm.get_info()
            device_id = 0
            w, h = 640, 480
            assert wm.start_virtual_webcam(device_id, w, h)
            assert wm.get_info().get("webcam", {}).get("active-devices",
                                                       0) == 1
            assert len(packets) == 1  #ack sent
            frame_no = 0
            encoding = "png"
            buf = BytesIOClass()
            from PIL import Image
            image = Image.new('RGB', size=(w, h), color=(155, 0, 0))
            image.save(buf, 'jpeg')
            data = buf.getvalue()
            buf.close()
            wm.process_webcam_frame(device_id, frame_no, encoding, w, h, data)
            assert len(packets) == 2  #ack sent
            wm.stop_virtual_webcam(device_id)
        finally:
            wm.cleanup()
示例#13
0
 def test_clipboard(self):
     with DisplayContext():
         if POSIX and not OSX:
             from xpra.x11.gtk_x11.gdk_display_source import init_gdk_display_source
             init_gdk_display_source()
         from xpra.server.mixins.clipboard_server import ClipboardServer
         from xpra.server.source.clipboard_connection import ClipboardConnection
         opts = AdHocStruct()
         opts.clipboard = "yes"
         opts.clipboard_direction = "both"
         opts.clipboard_filter_file = None
         self._test_mixin_class(ClipboardServer, opts, {},
                                ClipboardConnection)
示例#14
0
	def test_networkstate(self):
		x = NetworkState()
		opts = AdHocStruct()
		opts.pings = True
		x.init(opts)
		assert x.get_caps() is not None
		x.server_capabilities = typedict({"start_time" : monotonic_time()})
		x.parse_server_capabilities()
		assert x.server_start_time>=x.start_time, "server_start_time=%s vs start_time=%s" % (x.server_start_time, x.start_time)
		x.send_info_request()
		packet = ["info-response", {"foo" : "bar"}]
		x._process_info_response(packet)
		assert x.server_last_info.get("foo")=="bar"
示例#15
0
 def _default_opts(self):
     opts = AdHocStruct()
     opts.av_sync = True
     opts.speaker = "no"
     opts.microphone = "no"
     opts.sound_source = ""
     opts.speaker_codec = []
     opts.microphone_codec = []
     opts.tray_icon = ""
     return opts
示例#16
0
 def _test_mixin_class(self, mclass, opts, caps=None, protocol_type="xpra"):
     x = self.mixin = mclass()
     x.quit = self.fake_quit
     fake_protocol = AdHocStruct()
     fake_protocol.get_info = lambda: {}
     fake_protocol.set_compression_level = lambda _x: None
     fake_protocol.TYPE = protocol_type
     x._protocol = fake_protocol  #pylint: disable=protected-access
     x.add_packet_handlers = self.add_packet_handlers
     x.add_packet_handler = self.add_packet_handler
     x.idle_add = self.glib.idle_add
     x.timeout_add = self.glib.timeout_add
     x.source_remove = self.glib.source_remove
     x.init(opts)
     conn = AdHocStruct()
     conn.filename = "/fake/path/to/nowhere"
     x.setup_connection(conn)
     x.send = self.send
     x.send_now = self.send
     x.init_authenticated_packet_handlers()
     caps = self.make_caps(caps)
     x.parse_server_capabilities(caps)
     x.process_ui_capabilities(caps)
     assert x.get_caps() is not None
     assert x.get_info() is not None
     return x
示例#17
0
    def test_rfb_source(self):
        #fake protocol:
        p = AdHocStruct()
        p.send = noop
        p.queue_size = lambda: 1
        #fake window:
        window = AdHocStruct()

        def get_image(x, y, w, h):
            stride = (w + 8) * 4
            pixels = b"0" * stride * h
            return ImageWrapper(x, y, w, h, pixels, "BGRX", 24, stride, 4)

        window.get_image = get_image
        window.acknowledge_changes = noop
        for protocol in (p, None):
            s = RFBSource(protocol, True)
            assert s.get_info()
            s.get_window_info(())
            s.ping()
            s.keys_changed()
            s.set_default_keymap()
            s.send_cursor()
            s.send_server_event()
            s.update_mouse()
            s.damage(1, window, 0, 0, 1024, 768, {"polling": protocol is None})
            s.damage(1, window, 0, 0, 2, 2, {"polling": protocol is None})
            s.send_clipboard("foo")
            s.bell()
            assert not s.is_closed()
            s.close()
            #noop:
            s.damage(1, window, 0, 0, 2, 2, {"polling": protocol is None})
            assert s.is_closed()
示例#18
0
	def test_networkstate(self):
		opts = AdHocStruct()
		opts.pings = True
		opts.bandwidth_limit = 0
		opts.bandwidth_detection = True
		self._test_mixin_class(NetworkState, opts, {"start_time" : time.time()})
		x = self.mixin
		if x.server_start_time<x.start_time:
			raise Exception("invalid time: server=%s vs start=%s" % (x.server_start_time, x.start_time))
		x.uuid = get_hex_uuid()
		x.send_info_request()
		packet = ["info-response", {"foo" : "bar"}]
		self.handle_packet(packet)
		assert x.server_last_info.get("foo")=="bar"
示例#19
0
 def test_webcam(self):
     from xpra.server.mixins.webcam_server import WebcamServer, log as serverlog
     from xpra.server.source.webcam_mixin import WebcamMixin, log as sourcelog
     opts = AdHocStruct()
     opts.webcam = "yes"
     with silence_info(serverlog):
         self._test_mixin_class(WebcamServer, opts, {}, WebcamMixin)
     if self.mixin.get_info(self.protocol).get("webcam", {}).get("virtual-video-devices", 0)>0:
         with silence_info(sourcelog):
             self.handle_packet(("webcam-start", 0, 640, 480))
         png_hex_data = "89504e470d0a1a0a0000000d4948445200000280000001e00802000000bab34bb3000005f34944415478daedd53101000008c330c0bfe7e1029e44429f769202006e8d040060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00060c0018300018300060c00060c00080010380010300060c00060c00062c010018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300018300060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00060c00080010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c00080010380010380010300060c00060c0018300018300060c00060c000800103c0bf05fda806bd1bd7b4640000000049454e44ae426082"
         png_data = binascii.unhexlify(png_hex_data)
         self.handle_packet(("webcam-frame", 0, 0, "png", 640, 480, png_data))
         self.handle_packet(("webcam-stop", 0, "end"))
示例#20
0
 def refresh_shape(self):
     rectangles = self.get_shape_rectangles()
     if rectangles==self.rectangles:
         return  #unchanged
     self.rectangles = rectangles
     shapelog("refresh_shape() sending notify for updated rectangles: %s", rectangles)
     #notify listeners:
     pspec = AdHocStruct()
     pspec.name = "shape"
     for cb, args in self.shape_notify:
         shapelog("refresh_shape() notifying: %s", cb)
         try:
             cb(self, pspec, *args)
         except:
             shapelog.error("error in shape notify callback %s", cb, exc_info=True)
示例#21
0
    def test_windowserver(self):
        from xpra.server.mixins.window_server import WindowServer
        opts = AdHocStruct()
        opts.min_size = "10x10"
        opts.max_size = "16384x8192"

        def load_existing_windows():
            pass

        def _WindowServer():
            ws = WindowServer()
            ws.load_existing_windows = load_existing_windows
            return ws

        self._test_mixin_class(_WindowServer, opts)
示例#22
0
 def refresh_shape(self):
     rectangles = self.get_shape_rectangles()
     if rectangles==self.rectangles:
         return  #unchanged
     self.rectangles = rectangles
     shapelog("refresh_shape() sending notify for updated rectangles: %s", rectangles)
     #notify listeners:
     pspec = AdHocStruct()
     pspec.name = "shape"
     for cb, args in self.shape_notify:
         shapelog("refresh_shape() notifying: %s", cb)
         try:
             cb(self, pspec, *args)
         except:
             shapelog.error("error in shape notify callback %s", cb, exc_info=True)
示例#23
0
    def test_audio(self):
        def _ServerInfoMixin():
            x = ServerInfoMixin()

            def warn_and_quit(*_args):
                pass

            x.warn_and_quit = warn_and_quit
            return x

        opts = AdHocStruct()
        x = self._test_mixin_class(
            _ServerInfoMixin, opts, {
                "machine_id": "123",
                "uuid": "some-uuid",
                "build.version": "3.0",
                "build.revision": "23000",
                "hostname": "localhost",
                "display": ":99",
                "platform": "linux2",
                "platform.release": "dunno",
                "platform.platform": "platformX",
            })
        del x.server_capabilities["build.version"]
        assert not x.parse_server_capabilities(
        ), "should have failed when version is missing"
        version = "0.1"
        x.server_capabilities["build.version"] = version
        assert not x.parse_server_capabilities(
        ), "should have failed with version %s" % version
示例#24
0
 def test_shell(self):
     from xpra.server.source import shell_mixin
     protocol = AdHocStruct()
     protocol._conn = AdHocStruct()
     protocol._conn.options = {"shell" : "yes"}
     m = self._test_mixin_class(shell_mixin.ShellMixin, protocol=protocol)
     def noop(*_args):
         pass
     m.send = noop
     out,err = m.shell_exec("print('hello')")
     assert out.rstrip("\n")=="hello", "expected 'hello' but got '%s'" % out.rstrip("\n")
     assert not err
     with silence_error(shell_mixin):
         out,err = m.shell_exec("--not-a-statement--")
     assert not out
     assert err
示例#25
0
	def test_audio(self):
		waq = []
		def _ServerInfoMixin():
			x = ServerInfoMixin()
			def warn_and_quit(*args):
				waq.append(args)
			x.warn_and_quit = warn_and_quit
			return x
		opts = AdHocStruct()
		caps = typedict({
			"machine_id" : "123",
			"uuid"	: "some-uuid",
			"build.version"	: "3.0",
			"build.revision" : "23000",
			"hostname"	: "localhost",
			"display" : ":99",
			"platform" : "linux2",
			"platform.release" : "dunno",
			"platform.platform" : "platformX",
			"platform.linux_distribution" : ('Linux Fedora', 20, 'Heisenbug'),
			})
		x = self._test_mixin_class(_ServerInfoMixin, opts, caps)
		del caps["build.version"]
		assert not x.parse_server_capabilities(caps), "should have failed when version is missing"
		version = "0.1"
		caps["build.version"] = version
		assert not x.parse_server_capabilities(caps), "should have failed with version %s" % version
示例#26
0
 def queue_draw(self, x, y, w, h):
     b = self._backing
     if not b:
         return
     if b._backing and b.paint_screen:
         area = AdHocStruct()
         area.x = x
         area.y = y
         area.width = w
         area.height = h
         event = AdHocStruct()
         event.area = area
         b.gl_expose_event(b._backing, event)
示例#27
0
    def test_xsettings(self):
        from xpra.x11.xsettings_prop import (
            get_settings, set_settings,
            get_local_byteorder,
            XSettingsTypeInteger, XSettingsTypeString, XSettingsTypeColor,
            )
        disp = AdHocStruct()
        for DEBUG_XSETTINGS in (True, False):
            with OSEnvContext():
                os.environ["XPRA_XSETTINGS_DEBUG"] = str(int(DEBUG_XSETTINGS))
                serial = 1
                data = b""
                l = len(data)
                v = struct.pack(b"=BBBBII", get_local_byteorder(), 0, 0, 0, serial, l)+data+b"\0"
                v1 = get_settings(disp, v)
                assert v
                #get from cache:
                v2 = get_settings(disp, v)
                assert v1==v2

                #test all types, set then get:
                #setting_type, prop_name, value, last_change_serial = setting
                settings = (
                    (XSettingsTypeInteger, "int1", 1, 0),
                    (XSettingsTypeString, "str1", "1", 0),
                    (XSettingsTypeColor, "color1", (128, 128, 64, 32), 0),
                    )
                serial = 2
                data = set_settings(disp, (serial, settings))
                assert data
                #parse it back:
                v = get_settings(disp, data)
                rserial, rsettings = v
                assert rserial==serial
                assert len(rsettings)==len(settings)
        #test error handling:
        for settings in (
            (
                #invalid color causes exception
                (XSettingsTypeColor, "bad-color", (128, ), 0),
            ),
            (
                #invalid setting type is skipped with an error message:
                (255, "invalid-setting-type", 0, 0),
            ),
            ):
            serial = 3
            data = set_settings(disp, (serial, settings))
            assert data
            v = get_settings(disp, data)
            rserial, rsettings = v
            assert rserial==serial
            assert len(rsettings)==0
        #parsing an invalid data type (9) should fail:
        hexdata = b"000000000200000001000000090004007374723100000000010000003100000000"
        data = binascii.unhexlify(hexdata)
        v = get_settings(disp, data)
        rserial, rsettings = v
        assert len(rsettings)==0
示例#28
0
 def _test_opts(self):
     socket_dir = _get_test_socket_dir()
     opts = AdHocStruct()
     opts.socket_dirs = [socket_dir]
     opts.socket_dir = socket_dir
     opts.exit_ssh = False
     opts.ssh = "ssh -v "
     opts.remote_xpra = "run-xpra"
     opts.password_file = None
     return opts
示例#29
0
 def _test_mixin_class(self, mclass, opts, caps=None):
     x = self.mixin = mclass()
     fake_protocol = AdHocStruct()
     fake_protocol.get_info = lambda: {}
     fake_protocol.set_compression_level = lambda _x: None
     x._protocol = fake_protocol
     x.add_packet_handlers = self.add_packet_handlers
     x.add_packet_handler = self.add_packet_handler
     x.idle_add = self.glib.idle_add
     x.timeout_add = self.glib.timeout_add
     x.source_remove = self.glib.source_remove
     x.init(opts)
     conn = AdHocStruct()
     conn.filename = "/tmp/fake"
     x.setup_connection(conn)
     x.send = self.send
     x.send_now = self.send
     x.add_packet_handlers = self.add_packet_handlers
     x.add_packet_handler = self.add_packet_handler
     x.init_authenticated_packet_handlers()
     x.server_capabilities = typedict(caps or {})
     x.parse_server_capabilities()
     x.process_ui_capabilities()
     assert x.get_caps() is not None
     return x
示例#30
0
 def test_input(self):
     if os.environ.get("DISPLAY") and POSIX and not OSX and os.environ.get(
             "GDK_BACKEND", "x11") == "x11":
         from xpra.x11.gtk_x11.gdk_display_source import init_gdk_display_source
         init_gdk_display_source()
     from xpra.server.mixins.input_server import InputServer
     from xpra.server.source.input_mixin import InputMixin
     opts = AdHocStruct()
     self._test_mixin_class(InputServer, opts, {}, InputMixin)
示例#31
0
 def _test_mixin_classes(self, mixin_classes, server_props=None, client_caps=None, protocol=None, test_fn=None):
     assert mixin_classes
     for mixin_class in mixin_classes:
         assert mixin_class.is_needed(typedict(client_caps or {})) in (True, False)
     if len(mixin_classes)==1:
         mixin_class = mixin_classes[0]
     else:
         mixin_class = type("Mixin-%s" % (mixin_classes,), mixin_classes, {})
     #test the instance:
     #fake server object:
     server = AdHocStruct()
     if server_props:
         for k,v in server_props.items():
             setattr(server, k, v)
     #fake client caps object (as a typedict):
     d = typedict()
     if client_caps:
         for k,v in client_caps.items():
             d[k] = v
     m = mixin_class()
     m.source_remove = GLib.source_remove
     m.idle_add = GLib.idle_add
     m.timeout_add = GLib.timeout_add
     m.packet_queue = []
     m.protocol = protocol
     def encode_queue_size():
         return 0
     m.encode_queue_size = encode_queue_size
     for c in mixin_classes:
         c.__init__(m)
     for c in mixin_classes:
         try:
             c.init_from(m, m.protocol, server)
         except Exception:
             print("failed to initialize from %s" % (server,))
             raise
     for c in mixin_classes:
         c.init_state(m)
     for c in mixin_classes:
         assert not c.is_closed(m)
         c.parse_client_caps(m, d)
     for c in mixin_classes:
         assert c.get_info(m) is not None
         assert c.get_caps(m) is not None
         assert not c.is_closed(m)
     for c in mixin_classes:
         c.user_event(m)
         c.may_notify(m)
         c.queue_encode(m, ("item",))
         c.send_more(m, ("packet-type", 0))
         c.send_async(m, ("packet-type", 0))
     for c in mixin_classes:
         if test_fn:
             test_fn(c, m)
     for c in mixin_classes:
         c.cleanup(m)
     return m
示例#32
0
 def test_encoder_dimensions(self):
     encoder_spec = AdHocStruct()
     encoder_spec.width_mask = 0xfffe
     encoder_spec.height_mask = 0xfffe
     w, h = get_encoder_dimensions(encoder_spec, 101, 101)
     assert w == 100 and h == 100
     encoder_spec = AdHocStruct()
     encoder_spec.width_mask = 0xfffe
     encoder_spec.height_mask = 0xfffe
     w, h = get_encoder_dimensions(encoder_spec, 102, 102, (1, 2))
     assert w == 50 and h == 50
示例#33
0
	def test_webcam(self):
		opts = AdHocStruct()
		opts.webcam = "on"
		self._test_mixin_class(WebcamForwarder, opts, {
			"webcam" : True,
			"webcam.encodings" : ("png", "jpeg"),
			"virtual-video-devices" : 1,
			})
		x = self.mixin
		if not x.webcam_device:
			print("no webcam device found, test skipped")
			return
		self.glib.timeout_add(2500, x.stop_sending_webcam)
		self.glib.timeout_add(5000, self.stop)
		self.main_loop.run()
		assert len(self.packets)>2
		self.verify_packet(0, ("webcam-start", 0, ))
		self.verify_packet(1, ("webcam-frame", 0, ))
		self.verify_packet(-1, ("webcam-stop", 0, ))
示例#34
0
def start_sending_sound(plugins, sound_source_plugin, device, codec, volume, want_monitor_device, remote_decoders, remote_pulseaudio_server, remote_pulseaudio_id):
    log("start_sending_sound%s", (plugins, sound_source_plugin, device, codec, volume, want_monitor_device, remote_decoders, remote_pulseaudio_server, remote_pulseaudio_id))
    try:
        #info about the remote end:
        remote = AdHocStruct()
        remote.pulseaudio_server = remote_pulseaudio_server
        remote.pulseaudio_id = remote_pulseaudio_id
        remote.remote_decoders = remote_decoders
        plugin, options = parse_sound_source(plugins, sound_source_plugin, device, want_monitor_device, remote)
        if not plugin:
            log.error("failed to setup '%s' sound stream source", (sound_source_plugin or "auto"))
            return  None
        log("parsed '%s':", sound_source_plugin)
        log("plugin=%s", plugin)
        log("options=%s", options)
        return source_subprocess_wrapper(plugin, options, remote_decoders, volume, options)
    except Exception as e:
        log.error("error setting up sound: %s", e, exc_info=True)
        return None
示例#35
0
def start_sending_sound(plugins, sound_source_plugin, device, codec, volume, want_monitor_device, remote_decoders, remote_pulseaudio_server, remote_pulseaudio_id):
    log("start_sending_sound%s", (plugins, sound_source_plugin, device, codec, volume, want_monitor_device, remote_decoders, remote_pulseaudio_server, remote_pulseaudio_id))
    try:
        #info about the remote end:
        remote = AdHocStruct()
        remote.pulseaudio_server = remote_pulseaudio_server
        remote.pulseaudio_id = remote_pulseaudio_id
        remote.remote_decoders = remote_decoders
        plugin, options = parse_sound_source(plugins, sound_source_plugin, device, want_monitor_device, remote)
        if not plugin:
            log.error("failed to setup '%s' sound stream source", (sound_source_plugin or "auto"))
            return  None
        log("parsed '%s':", sound_source_plugin)
        log("plugin=%s", plugin)
        log("options=%s", options)
        return source_subprocess_wrapper(plugin, options, remote_decoders, volume, options)
    except Exception as e:
        log.error("error setting up sound: %s", e, exc_info=True)
        return None
示例#36
0
 def test_unhandled_types(self):
     from xpra.dbus.helper import dbus_to_native, native_to_dbus
     o = AdHocStruct()
     r = dbus_to_native(o)
     assert r == o and type(r) == type(
         o), "%s (%s) got converted to %s (%s)" % (o, type(o), r, type(r))
     r = native_to_dbus(o)
     #we don't know what else to do,
     #so we convert to a string:
     assert r == str(o)
示例#37
0
文件: gui.py 项目: svn2github/Xpra
def main():
    from xpra.platform import program_context
    with program_context("Platform-Events", "Platform Events Test"):
        if "-v" in sys.argv or "--verbose" in sys.argv:
            from xpra.platform.win32.win32_events import log as win32_event_logger
            log.enable_debug()
            win32_event_logger.enable_debug()

        import gobject
        gobject.threads_init()      #@UndefinedVariable

        log.info("Event loop is running")
        loop = gobject.MainLoop()

        def suspend():
            log.info("suspend event")
        def resume():
            log.info("resume event")
        fake_client = AdHocStruct()
        fake_client.window_with_grab = None
        fake_client.suspend = suspend
        fake_client.resume = resume
        fake_client.keyboard_helper = None
        def signal_quit(*args):
            loop.quit()
        fake_client.signal_disconnect_and_quit = signal_quit
        ClientExtras(fake_client, None)

        try:
            loop.run()
        except KeyboardInterrupt:
            log.info("exiting on keyboard interrupt")
示例#38
0
 def queue_draw(self, x, y, w, h):
     b = self._backing
     if not b:
         return
     if b._backing and b.paint_screen:
         area = AdHocStruct()
         area.x = x
         area.y = y
         area.width = w
         area.height = h
         event = AdHocStruct()
         event.area = area
         b.gl_expose_event(b._backing, event)
示例#39
0
 def SetWorkarea(self, x, y, w, h):
     self.log(".SetWorkarea%s", (x, y, w, h))
     workarea = AdHocStruct()
     workarea.x, workarea.y, workarea.width, workarea.height = ni(x), ni(y), ni(w), ni(h)
     self.server.set_workarea(workarea)