Exemplo n.º 1
0
 def test_from_system_argument(self):
     # Test the optional from_system argument of Clipboard.__init__
     text = "something"
     Clipboard.set_system_text(text)
     c = Clipboard(from_system=True)
     self.assertEqual(c.text, text)
     self.assertTrue(c.has_text())
Exemplo n.º 2
0
def tinyurl():
    selection = read_selected(True)
    url = "http://tinyurl.com/api-create.php?url=" + selection
    request = Request(url)
    response = urlopen(request)
    tiny = response.read()
    Clipboard.set_system_text(tiny)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
 def test_non_ascii(self):
     text = u"""
     ૱ ꠸ ┯ ┰ ┱ ┲ ❗ ► ◄ Ă ă 0 1 2 3 4 5 6 7 8 9 Ǖ ǖ Ꞁ ¤ ­ Ð ¢ ℥ Ω ℧ K ℶ
     ℷ ℸ ⅇ ⅊ ⚌ ⚍ ⚎ ⚏ ⚭ ⚮ ⌀ ⏑ ⏒ ⏓ ⏔ ⏕ ⏖ ⏗ ⏘ ⏙ ⏠ ⏡ ⏦ ᶀ ᶁ ᶂ ᶃ ᶄ ᶆ ᶇ ᶈ
     ᶉ ᶊ ᶋ ᶌ ᶍ ᶎ ᶏ ᶐ ᶑ ᶒ ᶓ ᶔ ᶕ ᶖ ᶗ ᶘ ᶙ ᶚ ᶸ ᵯ ᵰ ᵴ ᵶ ᵹ ᵼ ᵽ ᵾ ᵿ
     """
     Clipboard.set_system_text(text)
     self.assertEqual(Clipboard.get_system_text(), text)
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
def _select_and_cut_text(wordCount):
    """Selects wordCount number of words to the left of the cursor and cuts
    them out of the text. Returns the text from the system clip board.

    """
    clipboard = Clipboard()
    clipboard.set_system_text('')
    Key('cs-left/3:%s/10, c-x/10' % wordCount).execute()
    return clipboard.get_system_text()
Exemplo n.º 7
0
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
Exemplo n.º 8
0
    def test_clear_clipboard(self):
        # Put something on the system clipboard.
        Clipboard.set_system_text("something")

        # Clear it.
        Clipboard.clear_clipboard()

        # Then test that it has been cleared.
        self.assertEqual(Clipboard.get_system_text(), "")
Exemplo n.º 9
0
def _select_and_cut_text(wordCount):
    """Selects wordCount number of words to the left of the cursor and cuts
    them out of the text. Returns the text from the system clip board.

    """
    clipboard = Clipboard()
    clipboard.set_system_text('')
    Key('cs-left/3:%s/10, c-x/10' % wordCount).execute()
    return clipboard.get_system_text()
Exemplo n.º 10
0
        def set_system_text(cls, content):
            # Set the server's clipboard content if possible.
            try:
                aenea.communications.server.copy(content)
            except ProtocolError as e:
                print("ProtocolError caught when calling server.copy(): %s"
                      % e)
                print("Only setting local clipboard content.")

            # Set this system's clipboard content.
            DragonflyClipboard.set_system_text(content)
Exemplo n.º 11
0
        def set_system_text(cls, content):
            # Set the server's clipboard content if possible.
            try:
                aenea.communications.server.copy(content)
            except ProtocolError as e:
                print("ProtocolError caught when calling server.copy(): %s" %
                      e)
                print("Only setting local clipboard content.")

            # Set this system's clipboard content.
            DragonflyClipboard.set_system_text(content)
Exemplo n.º 12
0
 def get_system_text(cls):
     # Get the server's clipboard content if possible and update this
     # system's clipboard.
     try:
         server_text = aenea.communications.server.paste()
         DragonflyClipboard.set_system_text(server_text)
         return server_text
     except ProtocolError as e:
         print("ProtocolError caught when calling server.paste(): %s" %
               e)
         print("Only getting local clipboard content.")
         return DragonflyClipboard.get_system_text()
Exemplo n.º 13
0
    def test_set_text(self):
        c = Clipboard()
        text = "test"
        c.set_text(text)
        self.assertTrue(c.has_text())
        self.assertEqual(c.get_text(), text)
        self.assertEqual(c.text, text)

        # Setting the text to None clears the stored text.
        c.set_text(None)
        self.assertFalse(c.has_text())
        self.assertIs(c.get_text(), None)
Exemplo n.º 14
0
 def get_system_text(cls):
     # Get the server's clipboard content if possible and update this
     # system's clipboard.
     try:
         server_text = aenea.communications.server.paste()
         DragonflyClipboard.set_system_text(server_text)
         return server_text
     except ProtocolError as e:
         print("ProtocolError caught when calling server.paste(): %s"
               % e)
         print("Only getting local clipboard content.")
         return DragonflyClipboard.get_system_text()
Exemplo n.º 15
0
def selection_to_bib(ref_type, bib_path):
    Key("c-c/20").execute()
    cb = Clipboard.get_system_text()
    if ref_type == "book":
        ref = book_citation_generator.citation_from_name(cb)
    elif ref_type == "paper":
        ref = bibtexer.bib_from_title(cb)
    elif ref_type == "link":
        ref = bibtexer.bibtex_from_link(cb)
    with codecs.open(bib_path, encoding="utf-8", mode="a") as f:
        f.write(ref)
    print("Reference added:\n" + ref)
    Clipboard.set_system_text(bibtexer.get_tag(ref))
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
def drop(nnavi500, nexus):
    key = str(nnavi500)
    while True:
        failure = False
        try:
            if key in nexus.clip:
                Clipboard.set_system_text(nexus.clip[key])
                Key("c-v").execute()
            else:
                dragonfly.get_engine().speak("slot empty")
            time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                       1000.)
        except Exception:
            failure = True
        if not failure:
            break
Exemplo n.º 18
0
def _select_and_cut_text(wordCount):
    """Selects wordCount number of words to the left of the cursor and cuts
    them out of the text. Returns the text from the system clip board.

    """
    clipboard = Clipboard()
    clipboard.set_system_text('')
    try:  # Try selecting n number of words.
        Key('ctrl:down, shift:down').execute()
        Key('left:%s' % wordCount).execute()
        Key('shift:up').execute()
    finally:
        # It is important to make sure that the buttons are released.
        # Otherwise you get stuck in an unpleasant situation.
        Key('shift:up, ctrl:up').execute()
    Pause("10").execute()
    Key('c-x').execute()  # Cut out the selected words.
    Pause("20").execute()
    return clipboard.get_system_text()
Exemplo n.º 19
0
    def test_get_format(self):
        # Test with an empty Clipboard instance.
        c = Clipboard()
        self.assertRaises(ValueError, c.get_format, format_unicode)
        self.assertRaises(ValueError, c.get_format, format_text)

        # Test with one format.
        text1 = u"unicode text"
        c = Clipboard(contents={format_unicode: text1})
        self.assertEqual(c.get_format(format_unicode), text1)
        self.assertRaises(ValueError, c.get_format, format_text)

        # Test with two formats.
        text2 = b"text"
        c = Clipboard(contents={format_unicode: text1, format_text: text2})
        self.assertEqual(c.get_format(format_unicode), text1)
        self.assertEqual(c.get_format(format_text), text2)
Exemplo n.º 20
0
 def test_set_text(self):
     c = Clipboard()
     text = "test"
     c.set_text(text)
     self.assertTrue(c.has_text())
     self.assertEqual(c.get_text(), text)
     self.assertEqual(c.text, text)
Exemplo n.º 21
0
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
Exemplo n.º 22
0
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
Exemplo n.º 23
0
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
Exemplo n.º 24
0
    def test_non_strings(self):
        # Using non-string objects for text formats raises errors.
        self.assertRaises(TypeError, Clipboard, {format_text: 0})
        self.assertRaises(TypeError, Clipboard, {format_unicode: 0})
        self.assertRaises(TypeError, Clipboard, {format_text: object()})
        self.assertRaises(TypeError, Clipboard, {format_unicode: object()})
        self.assertRaises(TypeError, Clipboard, {format_text: None})
        self.assertRaises(TypeError, Clipboard, {format_unicode: None})

        c = Clipboard()
        self.assertRaises(TypeError, c.set_text, 0)
        self.assertRaises(TypeError, c.set_text, object())
        self.assertRaises(TypeError, c.set_format, format_text, 0)
        self.assertRaises(TypeError, c.set_format, format_text, object())
        self.assertRaises(TypeError, c.set_format, format_unicode, 0)
        self.assertRaises(TypeError, c.set_format, format_unicode, object())
        self.assertRaises(TypeError, c.set_system_text, 0)
        self.assertRaises(TypeError, c.set_system_text, object())
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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()
Exemplo n.º 27
0
    def test_get_set_system_text(self):
        # Test with an empty system clipboard.
        Clipboard.clear_clipboard()
        self.assertEqual(Clipboard.get_system_text(), u"")

        # Test setting a Unicode string on the system clipboard.
        text1 = u"Unicode text"
        Clipboard.set_system_text(text1)
        self.assertEqual(Clipboard.get_system_text(), text1)

        # Test setting a binary string on the system clipboard.
        # get_system_text() should return the equivalent Unicode string, as
        # format_unicode is preferred.
        Clipboard.set_system_text(b"text")
        self.assertEqual(Clipboard.get_system_text(), u"text")

        # Test that setting the text using None clears the clipboard.
        Clipboard.set_system_text(None)
        self.assertEqual(Clipboard.get_system_text(), u"")
Exemplo n.º 28
0
 def setUp(self):
     # Clear the clipboard before each test.
     Clipboard.clear_clipboard()
Exemplo n.º 29
0
    def test_flexible_string_types(self):
        # This is similar to the clipboard format conversion that Windows
        # performs when necessary. The Clipboard class should do this
        # regardless of platform/implementation.

        # Binary strings used with format_unicode are converted for us.
        c = Clipboard(contents={format_unicode: b"text"})
        self.assertEqual(c.get_format(format_unicode), u"text")
        c = Clipboard()
        c.set_format(format_unicode, b"text")
        self.assertEqual(c.get_format(format_unicode), u"text")

        # Text strings used with format_text (ANSI) are converted for us.
        c = Clipboard(contents={format_text: u"text"})
        self.assertEqual(c.get_format(format_text), b"text")
        c = Clipboard()
        c.set_format(format_text, u"text")
        self.assertEqual(c.get_format(format_text), b"text")
Exemplo n.º 30
0
 def setUpClass(cls):
     # Save the current contents of the clipboard.
     cls.clipboard = Clipboard(from_system=True)
Exemplo n.º 31
0
    def test_has_text(self):
        # Test with an empty Clipboard instance.
        c = Clipboard()
        self.assertFalse(c.has_text())

        # Test with format_unicode only.
        c = Clipboard(contents={format_unicode: u"unicode text"})
        self.assertTrue(c.has_text())

        # Test with both text formats.
        c = Clipboard(contents={format_unicode: u"unicode text",
                                format_text: b"text"})
        self.assertTrue(c.has_text())

        # Test with format_text only.
        c = Clipboard(contents={format_text: b"text"})
        self.assertTrue(c.has_text())

        # Test with format_hdrop only.
        with NamedTemporaryFile() as f:
            c = Clipboard(contents={format_hdrop: f.name})
            self.assertFalse(c.has_text())
Exemplo n.º 32
0
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()
Exemplo n.º 33
0
def _get_clipboard_text():
    """Returns the text contents of the system clip board."""
    clipboard = Clipboard()
    return clipboard.get_system_text()
Exemplo n.º 34
0
 def convert(format, content):  # pylint: disable=redefined-builtin
     return Clipboard.convert_format_content(format, content)
Exemplo n.º 35
0
    def test_get_text(self):
        # Test with an empty Clipboard instance.
        c = Clipboard()
        self.assertIsNone(c.get_text())

        # Test with Unicode text.
        text1 = u"test"
        c.set_text(text1)
        self.assertEqual(c.get_text(), text1)

        # Test with text set to None.
        c.set_text(None)
        self.assertIsNone(c.get_text())

        # Test with binary text.
        text2 = b"test"
        c.set_text(text2)
        self.assertEqual(c.get_text(), text2)

        # Test with format_hdrop.
        with NamedTemporaryFile() as f:
            c = Clipboard(contents={format_hdrop: f.name})
            self.assertIsNone(c.get_text())