当前位置: 首页>>代码示例>>Python>>正文


Python AppKit.NSStringPboardType方法代码示例

本文整理汇总了Python中AppKit.NSStringPboardType方法的典型用法代码示例。如果您正苦于以下问题:Python AppKit.NSStringPboardType方法的具体用法?Python AppKit.NSStringPboardType怎么用?Python AppKit.NSStringPboardType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AppKit的用法示例。


在下文中一共展示了AppKit.NSStringPboardType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_osx_pyobjc_clipboard

# 需要导入模块: import AppKit [as 别名]
# 或者: from AppKit import NSStringPboardType [as 别名]
def init_osx_pyobjc_clipboard():
    def copy_osx_pyobjc(text):
        '''Copy string argument to clipboard'''
        text = _stringifyText(text) # Converts non-str values to str.
        newStr = Foundation.NSString.stringWithString_(text).nsstring()
        newData = newStr.dataUsingEncoding_(Foundation.NSUTF8StringEncoding)
        board = AppKit.NSPasteboard.generalPasteboard()
        board.declareTypes_owner_([AppKit.NSStringPboardType], None)
        board.setData_forType_(newData, AppKit.NSStringPboardType)

    def paste_osx_pyobjc():
        "Returns contents of clipboard"
        board = AppKit.NSPasteboard.generalPasteboard()
        content = board.stringForType_(AppKit.NSStringPboardType)
        return content

    return copy_osx_pyobjc, paste_osx_pyobjc 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:19,代码来源:__init__.py

示例2: setClipboard

# 需要导入模块: import AppKit [as 别名]
# 或者: from AppKit import NSStringPboardType [as 别名]
def setClipboard( self, myText ):
		"""
		Sets the contents of the clipboard to myText.
		Returns True if successful, False if unsuccessful.
		"""
		from AppKit import NSPasteboard, NSStringPboardType
		try:
			myClipboard = NSPasteboard.generalPasteboard()
			myClipboard.declareTypes_owner_( [NSStringPboardType], None )
			myClipboard.setString_forType_( myText, NSStringPboardType )
			return True
		except Exception as e:
			import traceback
			print(traceback.format_exc())
			print()
			print(e)
			return False 
开发者ID:huertatipografica,项目名称:HTLetterspacer,代码行数:19,代码来源:HT_LetterSpacer_script.py

示例3: run

# 需要导入模块: import AppKit [as 别名]
# 或者: from AppKit import NSStringPboardType [as 别名]
def run(options):
    elapsed_time = 0
    monitor_time = int(options["monitor_time"])
    output_file = options["output_file"]

    previous = ""

    while elapsed_time <= monitor_time:
        try:
            pasteboard = NSPasteboard.generalPasteboard()
            pasteboard_string = pasteboard.stringForType_(NSStringPboardType)

            if pasteboard_string != previous:
                if output_file:
                    with open(output_file, "a+") as out:
                        out.write(pasteboard_string + "\n")
                else:
                    st = datetime.fromtimestamp(time()).strftime("%H:%M:%S")
                    print("[clipboard] " + st + " - '%s'" % str(pasteboard_string).encode("utf-8"))

            previous = pasteboard_string

            sleep(1)
            elapsed_time += 1
        except Exception as ex:
            print(str(ex))

    if output_file:
        print("Clipboard written to: " + output_file) 
开发者ID:Marten4n6,项目名称:EvilOSX,代码行数:31,代码来源:clipboard.py

示例4: generate

# 需要导入模块: import AppKit [as 别名]
# 或者: from AppKit import NSStringPboardType [as 别名]
def generate(self):

        outFile = self.options['OutFile']['Value']
        monitorTime = self.options['MonitorTime']['Value']

        # the Python script itself, with the command to invoke
        #   for execution appended to the end. Scripts should output
        #   everything to the pipeline for proper parsing.
        #
        # the script should be stripped of comments, with a link to any
        #   original reference script included in the comments.
        script = """
def func(monitortime=0):
    from AppKit import NSPasteboard, NSStringPboardType
    import time
    import datetime
    import sys

    sleeptime = 0
    last = ''
    outFile = '%s'

    while sleeptime <= monitortime:
        try:
            pb = NSPasteboard.generalPasteboard()
            pbstring = pb.stringForType_(NSStringPboardType)

            if pbstring != last:
                if outFile != "":
                    f = file(outFile, 'a+')
                    f.write(pbstring)
                    f.close()
                    print "clipboard written to",outFile
                else:
                    ts = time.time()
                    st = datetime.datetime.fromtimestamp(ts).strftime('%%Y-%%m-%%d %%H:%%M:%%S')
                    print st + ": %%s".encode("utf-8") %% repr(pbstring)
            last = pbstring
            time.sleep(1)
            sleeptime += 1
        except Exception as e:
            print e

func(monitortime=%s)""" % (outFile,monitorTime)

        return script 
开发者ID:EmpireProject,项目名称:EmPyre,代码行数:48,代码来源:clipboard.py


注:本文中的AppKit.NSStringPboardType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。