Exemple #1
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)
 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())
Exemple #3
0
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 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)
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()
    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(), "")
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()
Exemple #8
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
Exemple #9
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)
Exemple #10
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
Exemple #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)
Exemple #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()
Exemple #13
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()
Exemple #14
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
Exemple #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))
Exemple #16
0
    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")
Exemple #17
0
    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(), "")
Exemple #18
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
Exemple #19
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
Exemple #20
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()
Exemple #21
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
Exemple #22
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()
Exemple #23
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"")
Exemple #24
0
 def test_system_text_methods(self):
     text = "testing testing"
     Clipboard.set_system_text(text)
     self.assertEqual(Clipboard.get_system_text(), text)