コード例 #1
0
ファイル: action_paste.py プロジェクト: LexiconCode/dragonfly
    def _execute_events(self, events):
        original = Clipboard()
        try:
            original.copy_from_system()
        except Exception as e:
            self._log.warning(
                "Failed to store original clipboard contents:"
                " %s", e)

        # Store the contents to copy (i.e. *events*) in a Clipboard
        #  instance using the specified (or default) format.  If *events* is
        #  a dictionary, then pass it instead.
        if isinstance(events, dict):
            clipboard = Clipboard(contents=events)
        else:
            clipboard = Clipboard(contents={self.format: events})

        # Copy the contents to the system clipboard and paste using the
        #  paste action.
        clipboard.copy_to_system()
        self.paste.execute()

        # Restore the original clipboard contents afterwards.  This should
        #  clear the clipboard if we failed to store the original contents
        #  above.
        original.copy_to_system()
        return True
コード例 #2
0
    def _execute_events(self, events):
        original = Clipboard()
        original.copy_from_system()

        if self.format == win32con.CF_UNICODETEXT:
            events = unicode(events)
        elif self.format == win32con.CF_TEXT:
            events = str(events)

        clipboard = Clipboard(contents={self.format: events})
        clipboard.copy_to_system()
        self.paste.execute()

        original.copy_to_system()
        return True
コード例 #3
0
ファイル: action_paste.py プロジェクト: ismkir/dragonfly
 def _execute_events(self, events):
     original = Clipboard()
     try:
         original.copy_from_system()
     except pywintypes.error, e:
         self._log.warning("Failed to store original clipboard contents:"
                           " %s" % e)
コード例 #4
0
ファイル: temp_extra.py プロジェクト: haughki/breathe_modules
def add_close(_node):
    number = _node.words()[0]
    if number == "one":
        number = "1"
    else:
        number = "2"
    close_start = "{{c" + number + "::"

    Key("c-c/25").execute()
    Key("del").execute()
    clipboard = Clipboard()
    clipboard.copy_from_system()  # populate this clipboard instance
    print(clipboard)
    close_word = clipboard.get_text()

    last = close_word[-1]
    second_to_last = close_word[-2]

    exclude_me = [",", ".", ";", "!", "?", ")"]
    s = ""
    if last == " ":
        if second_to_last in exclude_me:
            s = close_start + close_word[:-2] + "}}" + second_to_last + " "
        else:
            s = close_start + close_word[:-1] + "}}" + " "
    elif last in exclude_me:
        s = close_start + close_word[:-1] + "}}" + last
    else:
        s = close_start + close_word + "}}"

    # Text("{{c" + number + "::" + close_word[:-2] + "}}" + second_to_last + " ").execute()
    # Text("{{c" + number + "::" + close_word[:-1] + "}} ").execute()

    if s != "":
        Paste(s).execute()
コード例 #5
0
ファイル: utils.py プロジェクト: haughki/MyDragonflyModules
def getSelectedText():
    """ Get the currently selected text by copying it to the clipboard and pulling it from there.
    Preserve the original clipboard state. """
    original = Clipboard(from_system=True)
    
    # print "original before copy: " + original.get_text()
    
    Key("c-c/5").execute()
    # note that trying to re-use this clipboard object after it's been
    # modified has caused me issues in the past -- seems to hold onto old values...
    just_copied = Clipboard()
    just_copied.copy_from_system()
    
    # print "original after copy: " + original.get_text()
    # print "just copied before original copy back: " + just_copied.get_text()
    
    original.copy_to_system()  # restore the state of the clipboard

    return just_copied.get_text()
コード例 #6
0
 def _process_recognition(self, value, extras):
     getPassword = Key(
         "w-b/10, s-tab/10, right:8/10, enter, c-f/10") + value + Key(
             'enter/10, escape/10, c-c/10, a-tab/10')
     getPassword.execute()
     clipboard = Clipboard()
     clipboard.copy_from_system(clear=True)
     password = clipboard.get_text()
     action = Text(password)
     action.execute()
コード例 #7
0
def SendCommandToClickByVoiceDragon(command):
    def go():
        temporary = Clipboard({Clipboard.format_text: command})
        temporary.copy_to_system()
        DragonKey('cs-dot/10').execute()

    try:
        original = Clipboard(from_system=True)
        go()
        original.copy_to_system()
    except Exception as e:
        go()
コード例 #8
0
def copy_modify_paste(modifying_function):
    selected_text = utils.getSelectedText()
    if not selected_text:
        print "No selected text?"
        return
    modified_text = modifying_function(str(selected_text))
    # tried to use the original clipboard here, but couldn't get it to "clear" -- some apps would
    # somehow get the original, unmodified text when the paste happened
    new_clipboard = Clipboard()
    new_clipboard.set_text(modified_text)
    new_clipboard.copy_to_system()
    Key("c-v").execute()
コード例 #9
0
ファイル: action_paste.py プロジェクト: ismkir/dragonfly
class Paste(DynStrActionBase):
    """
        Paste-from-clipboard action.

        Constructor arguments:
         - *contents* (*str*) -- contents to paste
         - *format* (*int*, Win32 clipboard format) --
           clipboard format
         - *paste* (instance derived from *ActionBase*) --
           paste action
         - *static* (boolean) --
           flag indicating whether the
           specification contains dynamic elements

        This action inserts the given *contents* into the Windows system 
        clipboard, and then performs the *paste* action to paste it into 
        the foreground application.  By default, the *paste* action is the 
        :kbd:`Control-v` keystroke.  The default clipboard format to use 
        is the *Unicode* text format.

    """

    # Default paste action.
    _default_format = win32con.CF_UNICODETEXT
    _default_paste = Key("c-v/20")

    def __init__(self, contents, format=None, paste=None, static=False):
        if not format: format = self._default_format
        if not paste: paste = self._default_paste
        if isinstance(contents, basestring):
            spec = contents
            self.contents = None
        else:
            spec = ""
            self.contents = contents
        self.format = format
        self.paste = paste
        DynStrActionBase.__init__(self, spec, static=static)

    def _parse_spec(self, spec):
        if self.contents:
            return self.contents
        else:
            return spec

    def _execute_events(self, events):
        original = Clipboard()
        try:
            original.copy_from_system()
        except pywintypes.error, e:
            self._log.warning("Failed to store original clipboard contents:"
                              " %s" % e)

        if self.format == win32con.CF_UNICODETEXT:
            events = unicode(events)
        elif self.format == win32con.CF_TEXT:
            events = str(events)

        clipboard = Clipboard(contents={self.format: events})
        clipboard.copy_to_system()
        self.paste.execute()

        original.copy_to_system()
        return True
コード例 #10
0
 def go():
     temporary = Clipboard({Clipboard.format_text: command})
     temporary.copy_to_system()
     DragonKey('cs-dot/10').execute()
コード例 #11
0
def get_clipboard_as_text():
    clipboard_instance = Clipboard()
    clipboard_instance.copy_from_system()

    return clipboard_instance.text
コード例 #12
0
def save_to_clipboard(text):
    """Stores text to the clipboard"""
    clipboard = Clipboard(from_system=True)
    clipboard.set_text(text)
    clipboard.copy_to_system()
コード例 #13
0
def reverse_clip():
    """Reverses the most recent clipboard item"""
    clip = text_clip()
    clipboard = Clipboard(from_system=True)
    clipboard.set_text(clip[::-1])
    clipboard.copy_to_system()
コード例 #14
0
def text_clip():
    """Gets the most recent item from the clipboard as text"""
    return Clipboard(from_system=True).get_text()
コード例 #15
0
def restore_clip():
    """Restores the most recent clipboard item"""
    global clip
    clipboard = Clipboard(from_system=True)
    clipboard.set_text(clip)
    clipboard.copy_to_system()
コード例 #16
0
def save_clip():
    """Stores the most recent clipboard item"""
    global clip
    clip = Clipboard(from_system=True).get_text()