Ejemplo n.º 1
0
 def got_token(self,
               targets,
               target_data=None,
               claim=True,
               _synchronous_client=False):
     # the remote end now owns the clipboard
     self.cancel_emit_token()
     if not self._enabled:
         return
     self._got_token_events += 1
     log(
         "got token, selection=%s, targets=%s, target data=%s, claim=%s, can-receive=%s",
         self._selection, targets, target_data, claim, self._can_receive)
     if self._can_receive:
         self.targets = _filter_targets(targets or ())
         self.target_data = target_data or {}
         if targets:
             self.got_contents("TARGETS", "ATOM", 32, targets)
         if target_data:
             for target, td_def in target_data.items():
                 dtype, dformat, data = td_def
                 dtype = bytestostr(dtype)
                 self.got_contents(target, dtype, dformat, data)
         #since we claim to be greedy
         #the peer should have sent us the target and target_data,
         #if not then request it:
         if not targets:
             self.send_clipboard_request_handler(self, self._selection,
                                                 "TARGETS")
     if not claim:
         log("token packet without claim, not setting the token flag")
         return
     self._have_token = True
     if self._can_receive:
         self.claim()
Ejemplo n.º 2
0
 def got_contents(self, target, dtype=None, dformat=None, data=None):
     #if this is the special target 'TARGETS', cache the result:
     if target=="TARGETS" and dtype=="ATOM" and dformat==32:
         self.targets = _filter_targets(data)
         #TODO: tell system what targets we have
         log("got_contents: tell OS we have %s", csv(self.targets))
     if dformat==8 and dtype in TEXT_TARGETS:
         log("we got a byte string: %s", data)
         self.set_clipboard_text(data)
Ejemplo n.º 3
0
 def got_contents(self, target, dtype=None, dformat=None, data=None):
     #if this is the special target 'TARGETS', cache the result:
     if target=="TARGETS" and dtype=="ATOM" and dformat==32:
         self.targets = _filter_targets(data)
         log("got_contents: tell OS we have %s", csv(self.targets))
         image_types = tuple(t for t in IMAGE_FORMATS if t in self.targets)
         log("image_types=%s, dtype=%s (is text=%s)",
                  image_types, dtype, dtype in TEXT_TARGETS)
         if image_types and dtype not in TEXT_TARGETS:
             #request image:
             self.send_clipboard_request_handler(self, self._selection, image_types[0])
         return
     if dformat==8 and dtype in TEXT_TARGETS:
         log("we got a byte string: %s", data)
         self.set_clipboard_text(net_utf8(data))
     if dformat==8 and dtype in IMAGE_FORMATS:
         log("we got a %s image", dtype)
         self.set_image_data(dtype, data)
Ejemplo n.º 4
0
 def got_contents(self, target, dtype=None, dformat=None, data=None):
     #if this is the special target 'TARGETS', cache the result:
     if target=="TARGETS" and dtype=="ATOM" and dformat==32:
         self.targets = _filter_targets(data)
         #TODO: tell system what targets we have
         log("got_contents: tell OS we have %s", csv(self.targets))
         image_formats = tuple(x for x in ("image/png", "image/jpeg") if x in self.targets)
         if image_formats:
             #request it:
             self.send_clipboard_request_handler(self, self._selection, image_formats[0])
     elif dformat==8 and dtype in TEXT_TARGETS:
         log("we got a byte string: %s", data)
         self.set_clipboard_text(data)
     elif dformat==8 and dtype.startswith("image/"):
         img_format = dtype.split("/")[-1]   #ie: 'png'
         self.set_clipboard_image(img_format, data)
     else:
         log("no handling: target=%s, dtype=%s, dformat=%s, data=%s",
             target, dtype, dformat, ellipsizer(data))
Ejemplo n.º 5
0
 def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):
     if encoding == "atoms":
         return _filter_targets(data)
     return super()._munge_wire_selection_to_raw(encoding, dtype, dformat,
                                                 data)
Ejemplo n.º 6
0
def filter_targets(targets):
    return _filter_targets(TARGET_TRANS.get(x, x) for x in targets)
Ejemplo n.º 7
0
 def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):
     if encoding=="atoms":
         return _filter_targets(data)
     return ClipboardTimeoutHelper._munge_wire_selection_to_raw(self, encoding, dtype, dformat, data)
Ejemplo n.º 8
0
 def _munge_raw_selection_to_wire(self, target, dtype, dformat, data):
     if dformat == 32 and dtype in ("ATOM", "ATOM_PAIR"):
         return "atoms", _filter_targets(xatoms_to_strings(data))
     return super()._munge_raw_selection_to_wire(target, dtype, dformat,
                                                 data)
Ejemplo n.º 9
0
 def _munge_raw_selection_to_wire(self, target, dtype, dformat, data):
     if dtype == "ATOM":
         assert isinstance(data, (tuple, list))
         return "atoms", _filter_targets(data)
     return ClipboardTimeoutHelper._munge_raw_selection_to_wire(
         self, target, dtype, dformat, data)
Ejemplo n.º 10
0
 def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):
     if encoding == "atoms":
         return strings_to_xatoms(_filter_targets(data))
     return ClipboardProtocolHelperCore._munge_wire_selection_to_raw(
         self, encoding, dtype, dformat, data)
Ejemplo n.º 11
0
 def _munge_raw_selection_to_wire(self, target, dtype, dformat, data):
     if dformat == 32 and dtype in ("ATOM", "ATOM_PAIR"):
         return "atoms", _filter_targets(xatoms_to_strings(data))
     return ClipboardProtocolHelperCore._munge_raw_selection_to_wire(
         self, target, dtype, dformat, data)