def main():
    import time
    from xpra.platform import program_context
    with program_context("OSX Clipboard Change Test"):
        log.enable_debug()

        #init UI watcher with gobject (required by pasteboard monitoring code)
        from xpra.gtk_common.gtk_util import import_gtk
        gtk = import_gtk()
        get_UI_watcher(glib.timeout_add, glib.source_remove)

        def noop(*_args):
            pass
        log.info("testing pasteboard")
        pasteboard = NSPasteboard.generalPasteboard()
        proxy = OSXClipboardProxy("CLIPBOARD", pasteboard, noop, noop)
        log.info("current change count=%s", proxy.change_count)
        clipboard = gtk.Clipboard(selection="CLIPBOARD")
        log.info("changing clipboard %s contents", clipboard)
        clipboard.set_text("HELLO WORLD %s" % time.time())
        proxy.update_change_count()
        log.info("new change count=%s", proxy.change_count)
        log.info("any update to your clipboard should get logged (^C to exit)")
        cc = proxy.change_count
        while True:
            v = proxy.change_count
            if v!=cc:
                log.info("success! the clipboard change has been detected, new change count=%s", v)
            else:
                log.info(".")
            time.sleep(1)
        if v==cc:
            log.info("no clipboard change detected")
Beispiel #2
0
def setup_watcher(get_change_count):
    global change_callbacks, update_clipboard_change_count

    #this function will update the globalcount:
    def update_change_count():
        global change_count
        change_count = get_change_count()
        return change_count

    update_clipboard_change_count = update_change_count

    #register this function to check periodically:
    def timer_clipboard_check():
        global change_count
        c = change_count
        change_count = update_change_count()
        log("timer_clipboard_check() was %s, now %s", c, change_count)
        if c != change_count:
            for x in change_callbacks:
                try:
                    x()
                except Exception as e:
                    log("error in change callback %s: %s", x, e)

    from xpra.platform.ui_thread_watcher import get_UI_watcher
    w = get_UI_watcher()
    if w is None:
        log.warn("Warning: no UI watcher instance available")
        log.warn(" cannot detect clipboard change events")
        return False
    log("UI watcher=%s", w)
    w.add_alive_callback(timer_clipboard_check)
    return True
Beispiel #3
0
def setup_watcher(get_change_count):
    global change_callbacks, update_clipboard_change_count

    #this function will update the globalcount:
    def update_change_count():
        global change_count
        change_count = get_change_count()
        return change_count
    update_clipboard_change_count = update_change_count

    #register this function to check periodically:
    def timer_clipboard_check():
        global change_count
        c = change_count
        change_count = update_change_count()
        log("timer_clipboard_check() was %s, now %s", c, change_count)
        if c!=change_count:
            for x in change_callbacks:
                try:
                    x()
                except Exception as e:
                    log("error in change callback %s: %s", x, e)

    from xpra.platform.ui_thread_watcher import get_UI_watcher
    w = get_UI_watcher()
    if w is None:
        log.warn("no UI watcher available, cannot watch for clipboard events")
        return False
    log("UI watcher=%s", w)
    w.add_alive_callback(timer_clipboard_check)
    return True
Beispiel #4
0
 def init(self, opts):
     GTKXpraClient.init(self, opts)
     self.ClientWindowClass = BorderClientWindow
     self.remote_clipboard = opts.remote_clipboard
     self.local_clipboard = opts.local_clipboard
     log("init(..) ClientWindowClass=%s", self.ClientWindowClass)
     from xpra.platform.ui_thread_watcher import get_UI_watcher
     self.UI_watcher = get_UI_watcher(self.timeout_add)
Beispiel #5
0
 def init(self, opts):
     GTKXpraClient.init(self, opts)
     self.ClientWindowClass = BorderClientWindow
     self.remote_clipboard = opts.remote_clipboard
     self.local_clipboard = opts.local_clipboard
     log("init(..) ClientWindowClass=%s", self.ClientWindowClass)
     from xpra.platform.ui_thread_watcher import get_UI_watcher
     self.UI_watcher = get_UI_watcher(self.timeout_add)
Beispiel #6
0
 def cleanup(self):
     super().cleanup()
     w = get_UI_watcher()
     if w:
         try:
             w.remove_alive_callback(self.timer_clipboard_check)
         except (KeyError, ValueError):
             pass
Beispiel #7
0
 def __init__(self, selection, pasteboard, send_clipboard_request_handler, send_clipboard_token_handler):
     self.pasteboard = pasteboard
     self.send_clipboard_request_handler = send_clipboard_request_handler
     self.send_clipboard_token_handler = send_clipboard_token_handler
     super().__init__(selection)
     self.update_change_count()
     #setup clipboard counter watcher:
     w = get_UI_watcher(GLib.timeout_add, GLib.source_remove)
     w.add_alive_callback(self.timer_clipboard_check)
Beispiel #8
0
def main():
    global change_count
    import time
    from xpra.platform import init, clean
    try:
        init("OSX Clipboard Change Test")
        log.enable_debug()

        #init UI watcher with gobject (required by pasteboard monitoring code)
        from xpra.platform.ui_thread_watcher import get_UI_watcher
        gobject.threads_init()
        import gtk.gdk
        gtk.gdk.threads_init()
        get_UI_watcher(glib.timeout_add)

        log.info("testing pasteboard")
        if not init_pasteboard():
            log.warn("failed to initialize a pasteboard!")
            return
        assert update_clipboard_change_count is not None, "cannot access clipboard change count"
        cc = update_clipboard_change_count()
        log.info("current change count=%s", cc)
        clipboard = gtk.Clipboard(selection="CLIPBOARD")
        log.info("changing clipboard %s contents", clipboard)
        clipboard.set_text("HELLO WORLD %s" % time.time())
        cc = update_clipboard_change_count()
        log.info("new change count=%s", cc)
        log.info("any update to your clipboard should get logged (^C to exit)")
        while True:
            v = update_clipboard_change_count()
            if v != cc:
                log.info(
                    "success! the clipboard change has been detected, new change count=%s",
                    v)
            else:
                log.info(".")
            time.sleep(1)
        if v == cc:
            log.info("no clipboard change detected")
    finally:
        clean()
Beispiel #9
0
def main():
    global change_count
    import time
    from xpra.platform import init, clean
    try:
        init("OSX Clipboard Change Test")
        log.enable_debug()

        #init UI watcher with gobject (required by pasteboard monitoring code)
        from xpra.platform.ui_thread_watcher import get_UI_watcher
        gobject.threads_init()
        import gtk.gdk
        gtk.gdk.threads_init()
        get_UI_watcher(glib.timeout_add)

        log.info("testing pasteboard")
        if not init_pasteboard():
            log.warn("failed to initialize a pasteboard!")
            return
        assert update_clipboard_change_count is not None, "cannot access clipboard change count"
        cc = update_clipboard_change_count()
        log.info("current change count=%s", cc)
        clipboard = gtk.Clipboard(selection="CLIPBOARD")
        log.info("changing clipboard %s contents", clipboard)
        clipboard.set_text("HELLO WORLD %s" % time.time())
        cc = update_clipboard_change_count()
        log.info("new change count=%s", cc)
        log.info("any update to your clipboard should get logged (^C to exit)")
        while True:
            v = update_clipboard_change_count()
            if v!=cc:
                log.info("success! the clipboard change has been detected, new change count=%s", v)
            else:
                log.info(".")
            time.sleep(1)
        if v==cc:
            log.info("no clipboard change detected")
    finally:
        clean()
 def __init__(self, selection, pasteboard, send_clipboard_request_handler, send_clipboard_token_handler):
     self.pasteboard = pasteboard
     self.send_clipboard_request_handler = send_clipboard_request_handler
     self.send_clipboard_token_handler = send_clipboard_token_handler
     ClipboardProxyCore.__init__(self, selection)
     self.update_change_count()
     #setup clipboard counter watcher:
     w = get_UI_watcher(glib.timeout_add, glib.source_remove)
     if w is None:
         log.warn("Warning: no UI watcher instance available")
         log.warn(" cannot detect clipboard change events")
     else:
         w.add_alive_callback(self.timer_clipboard_check)
Beispiel #11
0
 def do_run(self):
     if UI_THREAD_WATCHER:
         from xpra.platform.ui_thread_watcher import get_UI_watcher
         self.ui_watcher = get_UI_watcher(GLib.timeout_add, GLib.source_remove)
         self.ui_watcher.start()
     if server_features.windows:
         display = Gdk.Display.get_default()
         #n = display.get_n_screens()
         #assert n==1, "unsupported number of screens: %i" % n
         screen = display.get_default_screen()
         screen.connect("size-changed", self._screen_size_changed)
         screen.connect("monitors-changed", self._monitors_changed)
     log("do_run() calling %s", Gtk.main)
     Gtk.main()
     log("do_run() end of gtk.main()")
Beispiel #12
0
 def do_run(self):
     if UI_THREAD_WATCHER:
         from xpra.platform.ui_thread_watcher import get_UI_watcher
         self.ui_watcher = get_UI_watcher(glib.timeout_add,
                                          glib.source_remove)
         self.ui_watcher.start()
     if server_features.windows:
         display = display_get_default()
         i = 0
         while i < display.get_n_screens():
             screen = display.get_screen(i)
             screen.connect("size-changed", self._screen_size_changed)
             screen.connect("monitors-changed", self._monitors_changed)
             i += 1
     gtk_main_quit_on_fatal_exceptions_enable()
     log("do_run() calling %s", gtk_main)
     gtk_main()
     log("do_run() end of gtk.main()")
Beispiel #13
0
    #register this function to check periodically:
    def timer_clipboard_check():
        global change_count
        c = change_count
        change_count = update_change_count()
        log("timer_clipboard_check() was %s, now %s", c, change_count)
        if c != change_count:
            for x in change_callbacks:
                try:
                    x()
                except Exception, e:
                    log("error in change callback %s: %s", x, e)

    from xpra.platform.ui_thread_watcher import get_UI_watcher
    w = get_UI_watcher()
    if w is None:
        log.warn("no UI watcher available, cannot watch for clipboard events")
        return False
    log("UI watcher=%s", w)
    w.add_alive_callback(timer_clipboard_check)
    return True


class OSXClipboardProtocolHelper(GDKClipboardProtocolHelper):
    """
        Full of OSX quirks!
        darwin/features.py should be set
        * CLIPBOARD_GREEDY: request the other end to send tokens for all owner change events
        * CLIPBOARD_WANT_TARGETS: include targets with the tokens
    """
Beispiel #14
0
 def init(self, opts):
     GTKXpraClient.init(self, opts)
     self.ClientWindowClass = ClientWindow
     log("init(..) ClientWindowClass=%s", self.ClientWindowClass)
     from xpra.platform.ui_thread_watcher import get_UI_watcher
     self.UI_watcher = get_UI_watcher(self.timeout_add)
Beispiel #15
0
    #register this function to check periodically:
    def timer_clipboard_check():
        global change_count
        c = change_count
        change_count = update_change_count()
        log("timer_clipboard_check() was %s, now %s", c, change_count)
        if c!=change_count:
            for x in change_callbacks:
                try:
                    x()
                except Exception, e:
                    log("error in change callback %s: %s", x, e)

    from xpra.platform.ui_thread_watcher import get_UI_watcher
    w = get_UI_watcher()
    if w is None:
        log.warn("no UI watcher available, cannot watch for clipboard events")
        return False
    log("UI watcher=%s", w)
    w.add_alive_callback(timer_clipboard_check)
    return True


class OSXClipboardProtocolHelper(GDKClipboardProtocolHelper):
    """
        Full of OSX quirks!
        darwin/features.py should be set
        * CLIPBOARD_GREEDY: request the other end to send tokens for all owner change events
        * CLIPBOARD_WANT_TARGETS: include targets with the tokens
    """
Beispiel #16
0
# later version. See the file COPYING for details.

import os
import sys
import gobject
try:
    #we *have to* do this as early as possible on win32..
    gobject.threads_init()
except:
    pass
import gtk
from gtk import gdk
gtk.threads_init()

from xpra.platform.ui_thread_watcher import get_UI_watcher
UI_watcher = get_UI_watcher(gobject.timeout_add)

from xpra.gtk_common.gtk2common import gtk2main
from xpra.client.gtk_base.gtk_client_base import GTKXpraClient, xor_str
from xpra.client.gtk2.tray_menu import GTK2TrayMenu
from xpra.gtk_common.cursor_names import cursor_names
from xpra.log import Logger
log = Logger()

from xpra.client.gtk2.border_client_window import BorderClientWindow
from xpra.client.gtk2.client_window import ClientWindow
from xpra.client.gtk2.custom_client_window import CustomClientWindow
WINDOW_LAYOUTS = {
    "border": BorderClientWindow,
    "default": ClientWindow,
    "custom": CustomClientWindow,
Beispiel #17
0
import os
import sys
import gobject
try:
    #we *have to* do this as early as possible on win32..
    gobject.threads_init()
except:
    pass
import gtk
from gtk import gdk
gtk.threads_init()


from xpra.platform.ui_thread_watcher import get_UI_watcher
UI_watcher = get_UI_watcher(gobject.timeout_add)

from xpra.gtk_common.gtk2common import gtk2main
from xpra.client.gtk_base.gtk_client_base import GTKXpraClient, xor_str
from xpra.client.gtk2.tray_menu import GTK2TrayMenu
from xpra.gtk_common.cursor_names import cursor_names
from xpra.log import Logger
log = Logger()

from xpra.client.gtk2.border_client_window import BorderClientWindow
from xpra.client.gtk2.client_window import ClientWindow
from xpra.client.gtk2.custom_client_window import CustomClientWindow
WINDOW_LAYOUTS = {
                  "border"  : BorderClientWindow,
                  "default" : ClientWindow,
                  "custom"  : CustomClientWindow,