def select_string(include_quotes): mouse("left/3").execute() clipboard = Clipboard() saved_text = clipboard.get_system_text() clipboard.set_system_text('') left_counter = 0 while left_counter < 50: key("s-left, c-c/3").execute() left_counter += 1 if clipboard.get_system_text().startswith("\""): break key("left").execute() move_right = left_counter if not include_quotes: move_right -= 1 key("right").execute() key("s-right:%s" % move_right).execute() right_counter = 0 while right_counter < 50: key("s-right, c-c/3").execute() right_counter += 1 if clipboard.get_system_text().endswith("\""): break if not include_quotes: key("s-left").execute() clipboard.set_text(saved_text) clipboard.copy_to_system()
def stoosh_keep_clipboard(nnavi500, nexus): if nnavi500 == 1: Key("c-c").execute() else: max_tries = 20 cb = Clipboard(from_system=True) Key("c-c").execute() key = str(nnavi500) for i in range(0, max_tries): failure = False try: # time for keypress to execute time.sleep( settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) nexus.clip[key] = Clipboard.get_system_text() utilities.save_json_file( nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) except Exception: failure = True utilities.simple_log() if not failure: break cb.copy_to_system()
def test_copy_to_system(self): # Test with format_unicode. text1 = u"unicode text" c = Clipboard(contents={format_unicode: text1}) c.copy_to_system(clear=True) self.assertEqual(Clipboard.get_system_text(), text1) # Test with format_text. Text string used deliberately here; # get_system_text() should returns those. text2 = u"text" c = Clipboard(contents={format_text: text2}) c.copy_to_system(clear=True) self.assertEqual(Clipboard.get_system_text(), text2) # Test with text. text3 = u"testing" c = Clipboard(text=text3) c.copy_to_system(clear=True) self.assertEqual(Clipboard.get_system_text(), text3) # Test with an empty Clipboard instance. c = Clipboard() c.copy_to_system(clear=False) self.assertEqual(Clipboard.get_system_text(), text3) c.copy_to_system(clear=True) self.assertEqual(Clipboard.get_system_text(), u"")
def duple_keep_clipboard(nnavi50): cb = Clipboard(from_system=True) Key("escape, home, s-end, c-c, end").execute() time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) for i in range(0, nnavi50): Key("enter, c-v").execute() time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) cb.copy_to_system()
def get_selected_text(): clipboard = Clipboard() previous = clipboard.get_system_text() clipboard.set_system_text("") Key("c-c/3").execute() selected = clipboard.get_system_text() clipboard.set_text(previous) clipboard.copy_to_system() return selected
def paste_string(content): time.sleep(0.05) cb = Clipboard(from_system=True) try: Clipboard.set_system_text(str(content)) Key("c-v").execute() time.sleep(0.05) cb.copy_to_system() except Exception: return False return True
def paste_string(content): cb = Clipboard(from_system=True) time.sleep(SETTINGS["keypress_wait"]) try: Clipboard.set_system_text(str(content)) time.sleep(SETTINGS["keypress_wait"]) Key("c-v").execute() time.sleep(SETTINGS["keypress_wait"]) cb.copy_to_system() except Exception: return False return True
def test_backwards_compatibility(self): # The multi-platform class should be backwards compatible with the # Windows-only Clipboard class, at least for the constructor. text = u"unicode text" c = Clipboard(contents={13: text}) c.copy_to_system() self.assertEqual(Clipboard.get_system_text(), text) # Test with the CF_TEXT format (1) text = "text" c = Clipboard(contents={1: text}) c.copy_to_system() self.assertEqual(Clipboard.get_system_text(), text)
def read_selected(same_is_okay=False): time.sleep(SETTINGS["keypress_wait"]) cb = Clipboard(from_system=True) temporary = None prior_content = None try: prior_content = Clipboard.get_system_text() Clipboard.set_system_text("") Key("c-c").execute() time.sleep(SETTINGS["keypress_wait"]) temporary = Clipboard.get_system_text() cb.copy_to_system() except Exception: return None if prior_content == temporary and not same_is_okay: return None return temporary
def read_selected(same_is_okay=False): '''Returns a tuple: (0, "text from system") - indicates success (1, None) - indicates no change (2, None) - indicates clipboard error ''' time.sleep(0.05) cb = Clipboard(from_system=True) temporary = None prior_content = None try: prior_content = Clipboard.get_system_text() Clipboard.set_system_text("") Key("c-c").execute() time.sleep(0.05) temporary = Clipboard.get_system_text() cb.copy_to_system() except Exception: return 2, None if prior_content == temporary and not same_is_okay: return 1, None return 0, temporary
def drop_keep_clipboard(nnavi500, nexus): if nnavi500 == 1: Key("c-v").execute() else: max_tries = 20 key = str(nnavi500) cb = Clipboard(from_system=True) for i in range(0, max_tries): failure = False try: if key in nexus.clip: Clipboard.set_system_text(nexus.clip[key]) Key("c-v").execute() time.sleep( settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) else: dragonfly.get_engine().speak("slot empty") except Exception: failure = True if not failure: break cb.copy_to_system()
def test_copy_from_system(self): text = "testing" Clipboard.set_system_text(text) c = Clipboard() # Test the method with clear=False (default). c.copy_from_system(clear=False) self.assertEqual(c.text, text) self.assertEqual(Clipboard.get_system_text(), text) # Test again with clear=True. c = Clipboard() c.copy_from_system(clear=True) self.assertEqual(c.text, text) self.assertEqual(Clipboard.get_system_text(), "") # Test formats=format_unicode. # Set the system clipboard before testing. text1 = u"unicode text" c1 = Clipboard(contents={format_unicode: text1}) c1.copy_to_system() c2 = Clipboard() c2.copy_from_system(formats=format_unicode) self.assertTrue(c2.has_format(format_unicode)) self.assertEqual(c2.get_format(format_unicode), text1) # Test formats=format_text. # Set the system clipboard before testing. text2 = b"text" c1 = Clipboard(contents={format_text: text2}) c1.copy_to_system() c2 = Clipboard() c2.copy_from_system(formats=format_text) self.assertTrue(c2.has_format(format_text)) self.assertEqual(c2.get_format(format_text), text2) # Test formats=(format_unicode, format_text). # Set the system clipboard before testing. Use the same string for # both formats so the test will work on all platforms. c1 = Clipboard(contents={ format_text: b"text", format_unicode: u"text" }) c1.copy_to_system() c2 = Clipboard() c2.copy_from_system(formats=(format_unicode, format_text)) self.assertTrue(c2.has_format(format_unicode)) self.assertEqual(c2.get_format(format_unicode), u"text") self.assertTrue(c2.has_format(format_text)) self.assertEqual(c2.get_format(format_text), b"text")
def write_to_shell(text): clipboard = Clipboard() clipboard.set_text(text) clipboard.copy_to_system() Mouse("right").execute()
def _set_clipboard_text(text): """Sets the system clip board content.""" clipboard = Clipboard() clipboard.set_text(text) # Restore previous clipboard text. clipboard.copy_to_system()
def set_clipboard(text): clipboard = Clipboard() clipboard.set_text(text) clipboard.copy_to_system()
def test_copy_to_system(self): text = "testing" c = Clipboard(text=text) c.copy_to_system() self.assertEqual(Clipboard.get_system_text(), text)