コード例 #1
0
 def do_selection_get(self, selection_data, info, time):
     # Either call selection_data.set() or don't, and then return.
     # In practice, send a call across the wire, then block in a recursive
     # main loop.
     def nodata():
         selectiondata_set(selection_data, "STRING", 8, "")
     if not self._enabled or not self._can_receive:
         nodata()
         return
     selection = selectiondata_get_selection(selection_data)
     target = selectiondata_get_target(selection_data)
     log("do_selection_get(%s, %s, %s) selection=%s", selection_data, info, time, selection)
     self._selection_get_events += 1
     assert str(selection) == self._selection, "selection does not match: expected %s but got %s" % (selection, self._selection)
     self._request_contents_events += 1
     result = self.emit("get-clipboard-from-remote", self._selection, target)
     if result is None or result["type"] is None:
         log("remote selection fetch timed out or empty")
         nodata()
         return
     data = result["data"]
     dformat = result["format"]
     dtype = result["type"]
     log("do_selection_get(%s,%s,%s) calling selection_data.set(%s, %s, %s:%s)",
           selection_data, info, time, dtype, dformat, type(data), len(data or ""))
     boc = self._block_owner_change
     self._block_owner_change = True
     if is_gtk3() and dtype in (b"UTF8_STRING", b"STRING") and dformat==8:
         #GTK3 workaround: can only use set_text and only on the clipboard?
         s = bytestostr(data)
         self._clipboard.set_text(s, len(s))
     else:
         selectiondata_set(selection_data, dtype, dformat, data)
     if boc is False:
         glib.idle_add(self.remove_block)
コード例 #2
0
    def do_selection_get(self, selection_data, info, time):
        # Either call selection_data.set() or don't, and then return.
        # In practice, send a call across the wire, then block in a recursive
        # main loop.
        def nodata():
            selectiondata_set(selection_data, "STRING", 8, "")

        if not self._enabled or not self._can_receive:
            nodata()
            return
        if not self._have_token:
            try:
                return gtk.Invisible.do_selection_get(self, selection_data,
                                                      info, time)
            except Exception as e:
                log("gtk.Invisible.do_selection_get", exc_info=True)
                if first_time("selection-%s-not-implemented" %
                              self._selection):
                    log.warn("Warning: limited clipboard support for %s",
                             self._selection)
                    if is_Wayland():
                        log.warn(
                            " looks like a Wayland implementation limitation")
                    log.warn(" %s", e)
                nodata()
                return
        selection = selectiondata_get_selection(selection_data)
        target = selectiondata_get_target(selection_data)
        log("do_selection_get(%s, %s, %s) selection=%s", selection_data, info,
            time, selection)
        self._selection_get_events += 1
        assert str(selection) == self._selection, "expected %s but got %s" % (
            selection, self._selection)
        self._request_contents_events += 1
        result = self.emit("get-clipboard-from-remote", self._selection,
                           target)
        if result is None or result["type"] is None:
            log("remote selection fetch timed out or empty")
            nodata()
            return
        data = result["data"]
        dformat = result["format"]
        dtype = result["type"]
        if dtype:
            dtype = bytestostr(dtype)
        log(
            "do_selection_get(%s,%s,%s) calling selection_data.set(%s, %s, %s:%s)",
            selection_data, info, time, dtype, dformat, type(data),
            len(data or ""))
        boc = self._block_owner_change
        self._block_owner_change = True
        if is_gtk3() and dtype in ("UTF8_STRING", "STRING") and dformat == 8:
            #GTK3 workaround: can only use set_text and only on the clipboard?
            s = bytestostr(data)
            self._clipboard.set_text(s, len(s))
        else:
            selectiondata_set(selection_data, dtype, dformat, data)
        if boc is False:
            glib.idle_add(self.remove_block)
コード例 #3
0
 def nodata():
     selectiondata_set(selection_data, "STRING", 8, "")