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


Python NSString.stringWithString_方法代码示例

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


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

示例1: handle_notification

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
    def handle_notification(self, notification):
        handler = getattr(self, '_NH_%s' % notification.name, Null)
        handler(notification)

        if notification.name in ('SIPEngineSIPTrace', 'SIPEngineLog', 'MSRPLibraryLog', 'MSRPTransportTrace'):
            return

        # notifications text view
        if self.notificationsCheckBox.state() == NSOnState:
            attribs = notification.data.__dict__.copy()

            # remove some data that would be too big to log
            if notification.name == "MSRPTransportTrace":
                if len(attribs["data"]) > 30:
                    attribs["data"] = "<%i bytes>"%len(attribs["data"])
            elif notification.name in ("FileTransferStreamGotChunk", "ScreenSharingStreamGotData"):
                attribs["content"] = "..."
                if attribs.has_key("data"):
                    attribs["data"] = "..."

            attribs = ", ".join("%s=%s" % (k, v) for k, v in attribs.iteritems())
            ts = notification.datetime
            ts = ts.replace(microsecond=0) if type(ts) == datetime else ""

            self.notificationsBytes += len(notification.name) + len(str(notification.sender)) + len(attribs) + len(str(ts))
            self.notifications_unfiltered.append((NSString.stringWithString_(notification.name),
                                            NSString.stringWithString_(str(notification.sender)),
                                            NSString.stringWithString_(attribs),
                                            NSString.stringWithString_(str(ts))))
            self.renderNotifications()
开发者ID:uditha-atukorala,项目名称:blink,代码行数:32,代码来源:DebugWindow.py

示例2: drawHashMarksAndLabelsInRect_

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
    def drawHashMarksAndLabelsInRect_(self, rect):
        bounds = self.bounds()
        view = self.clientView()

        rulerBackgroundColor = self.rulerBackgroundColor()
        if rulerBackgroundColor is not None:
            rulerBackgroundColor.set()
            NSRectFill(bounds)

        if not isinstance(view, NSTextView):
            return

        layoutManager = view.layoutManager()
        container = view.textContainer()
        text = view.string()
        nullRange = NSMakeRange(NSNotFound, 0)
        yinset = view.textContainerInset().height
        visibleRect = self.scrollView().contentView().bounds()
        textAttributes = self.textAttributes()

        lines = self.lineIndices()

        glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(visibleRect, container)
        _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(glyphRange, None)[0]
        _range.length += 1

        count = len(lines)
        index = 0

        lineNumber = self.lineNumberForCharacterIndex_inText_(_range.location, text)

        for line in range(lineNumber, count):
            index = lines[line]
            if NSLocationInRange(index, _range):
                rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_(
                    NSMakeRange(index, 0),
                    nullRange,
                    container,
                    None
                )
                if rectCount > 0:
                    ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect)
                    labelText = NSString.stringWithString_("%s" % (line + 1))
                    stringSize = labelText.sizeWithAttributes_(textAttributes)

                    x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN
                    y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0
                    w = NSWidth(bounds) - self.RULER_MARGIN * 2.0
                    h = NSHeight(rects[0])

                    labelText.drawInRect_withAttributes_(NSMakeRect(x, y, w, h), textAttributes)

            if index > NSMaxRange(_range):
                break

        path = NSBezierPath.bezierPath()
        path.moveToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y))
        path.lineToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height))
        NSColor.grayColor().set()
        path.stroke()
开发者ID:typemytype,项目名称:drawbot,代码行数:62,代码来源:lineNumberRulerView.py

示例3: load_dictionaries

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def load_dictionaries(context_ref, language_list):
    # The function is a bit picky about making sure we pass a clean NSArray with NSStrings
    langs = NSMutableArray.array()
    for x in language_list:
        langs.addObject_(NSString.stringWithString_(x))
    # The True argument is for whether the language string objects are already retained
    SFPWAContextLoadDictionaries(context_ref, langs, True)
开发者ID:chilcote,项目名称:pylab,代码行数:9,代码来源:password_generator.py

示例4: _GetSystemProfile

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
 def _GetSystemProfile(self, sp_type):
   # pylint: disable=global-statement
   if sp_type not in self._cache:
     logging.debug('%s not cached', sp_type)
     sp_xml = self._GetSystemProfilerOutput(sp_type)
     self._cache[sp_type] = NSString.stringWithString_(sp_xml).propertyList()
   return self._cache[sp_type]
开发者ID:AaronBurchfield,项目名称:imagr,代码行数:9,代码来源:systemconfig.py

示例5: DSQuery

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def DSQuery(dstype, objectname, attribute):
  """DirectoryServices query.

  Args:
	dstype: The type of objects to query. user, group.
	objectname: the object to query.
	attribute: the attribute to query.
  Returns:
	the value of the attribute. If single-valued array, return single value.
  Raises:
	DSException: Cannot query DirectoryServices.
  """
  ds_path = '/%ss/%s' % (dstype.capitalize(), objectname)
  cmd = [_DSCL, '-plist', '.', '-read', ds_path, attribute]
  task = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  (stdout, stderr) = task.communicate()
  if task.returncode:
	raise DSException('Cannot query %s for %s: %s' % (ds_path,
													  attribute,
													  stderr))
  plist = NSString.stringWithString_(stdout).propertyList()
  if 'dsAttrTypeStandard:%s' % attribute in plist:
	value = plist['dsAttrTypeStandard:%s' % attribute]
	if len(value) == 1:
	  return value[0]
	else:
	  return value
  else:
	return None
开发者ID:Huron-City-Schools,项目名称:Huron-City-Schools-Python-Scripts,代码行数:31,代码来源:__init__.py

示例6: _update_view_with_string

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
 def _update_view_with_string(self, str_data):
     ns_str = NSString.stringWithString_(str_data.decode('latin-1'))
     data = ns_str.dataUsingEncoding_(NSISOLatin1StringEncoding)
     url = NSURL.URLWithString_('about:blank')
     frame = self.web_view.mainFrame()
     frame.loadData_MIMEType_textEncodingName_baseURL_(data, 'text/plain',
                                                       'latin-1', url)
开发者ID:ziz,项目名称:tinymail,代码行数:9,代码来源:message_view.py

示例7: show_text

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
    def show_text(self, text):
        x, y = self._ns_path.currentPoint()
        font = self._font
        ns_font = font._ns_font
        ns_color = self._textcolor._ns_color
        ns_string = NSString.stringWithString_(text)
        ns_attrs = {
            NSFontAttributeName: ns_font,
            NSForegroundColorAttributeName: ns_color,
        }
#		print "Canvas.show_text:", repr(text) ###
#		print "family:", ns_font.familyName() ###
#		print "size:", ns_font.pointSize() ###
#		print "ascender:", ns_font.ascender() ###
#		print "descender:", ns_font.descender() ###
#		print "capHeight:", ns_font.capHeight() ###
#		print "leading:", ns_font.leading() ###
#		print "matrix:", ns_font.matrix() ###
#		print "defaultLineHeightForFont:", ns_font.defaultLineHeightForFont() ###
        h = ns_font.defaultLineHeightForFont()
        d = -ns_font.descender()
        dy = h - d
        if ns_font.familyName() == "Courier New":
            dy += ns_font.pointSize() * 0.229167
        ns_point = NSPoint(x, y - dy)
        #print "drawing at:", ns_point ###
        ns_string.drawAtPoint_withAttributes_(ns_point, ns_attrs)
        dx = ns_font.widthOfString_(ns_string)
        #self._ns_path.relativeMoveToPoint_(NSPoint(x + dx, y))
        self._ns_path.relativeMoveToPoint_((dx, 0))
开发者ID:skykooler,项目名称:Lightningbeam,代码行数:32,代码来源:Canvas.py

示例8: requiredThickness

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
    def requiredThickness(self):
        lineCount = len(self.lineIndices())
        digits = int(math.log10(lineCount) + 1)

        sampleString = NSString.stringWithString_("8" * digits)
        stringSize = sampleString.sizeWithAttributes_(self.textAttributes())
        return math.ceil(max([self.DEFAULT_THICKNESS, stringSize.width + self.RULER_MARGIN * 2]))
开发者ID:typemytype,项目名称:drawbot,代码行数:9,代码来源:lineNumberRulerView.py

示例9: DSQuery

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def DSQuery(dstype, objectname, attribute=None):
    """DirectoryServices query.

  Args:
    dstype: The type of objects to query. user, group.
    objectname: the object to query.
    attribute: the optional attribute to query.
  Returns:
    If an attribute is specified, the value of the attribute. Otherwise, the
    entire plist.
  Raises:
    DSException: Cannot query DirectoryServices.
  """
    ds_path = "/%ss/%s" % (dstype.capitalize(), objectname)
    cmd = [_DSCL, "-plist", ".", "-read", ds_path]
    if attribute:
        cmd.append(attribute)
    (stdout, stderr, returncode) = RunProcess(cmd)
    if returncode:
        raise DSException("Cannot query %s for %s: %s" % (ds_path, attribute, stderr))
    plist = NSString.stringWithString_(stdout).propertyList()
    if attribute:
        value = None
        if "dsAttrTypeStandard:%s" % attribute in plist:
            value = plist["dsAttrTypeStandard:%s" % attribute]
        elif attribute in plist:
            value = plist[attribute]
        try:
            # We're copying to a new list to convert from NSCFArray
            return value[:]
        except TypeError:
            # ... unless we can't
            return value
    else:
        return plist
开发者ID:Dangeranger,项目名称:pymacadmin,代码行数:37,代码来源:__init__.py

示例10: setLabel_

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
 def setLabel_(self, label):
     if type(label) == NSString:
         self.label = label
     else:
         self.label = NSString.stringWithString_(label)
     frame = self.frame()
     frame.size.width = self.idealWidth()
     self.setFrame_(frame)
开发者ID:bitsworking,项目名称:blink-cocoa,代码行数:10,代码来源:FancyTabSwitcher.py

示例11: init_with_url

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def init_with_url(url):
	contents = urlopen(url).read()
	start = contents.find("<?xml ")
	plist = NSString.stringWithString_(contents[start:]).propertyList()
	
	if not isinstance(plist, NSDictionary):
		raise Exception("Invalid URL contents.", url, contents)
	
	return plist["meta"], plist["data"]
开发者ID:piaoapiao,项目名称:XPlist,代码行数:11,代码来源:XPlist.py

示例12: DSSearch

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def DSSearch(path, key, value, node='.'):
  cmd = [_DSCL, node, '-search', path, key, value]
  (stdout, stderr, returncode) = gmacpyutil.RunProcess(cmd)
  if returncode:
    raise DSException('Cannot search %s for %s:%s. %s' % (path,
                                                          key,
                                                          value,
                                                          stderr))
  return NSString.stringWithString_(stdout)
开发者ID:AaronBurchfield,项目名称:imagr,代码行数:11,代码来源:ds.py

示例13: drawTextAtSize

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
 def drawTextAtSize(self, text, s):
   if s != 16:
     docerator.TextRenderer.drawTextAtSize(self, text, s)
     return
   text = NSString.stringWithString_(text.lower()[0:3])  # at most 3 chars
   attribs = self.attribsAtSize(s)
   if len(text) <= 2:
     attribs[NSKernAttributeName] = 0  # we have some space
   else:
     attribs[NSKernAttributeName] = -1  # we need all the room we can get
   text.drawInRect_withAttributes_( ((1, 2), (15, 11)), attribs)
开发者ID:11liju,项目名称:macvim,代码行数:13,代码来源:make_icons.py

示例14: getOutline

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
def getOutline(page, label):
	# Create Destination
	myPage = myPDF.pageAtIndex_(page)
	pageSize = myPage.boundsForBox_(Quartz.kCGPDFMediaBox)
	x = 0
	y = Quartz.CGRectGetMaxY(pageSize)
	pagePoint = Quartz.CGPointMake(x,y)
	myDestination = Quartz.PDFDestination.alloc().initWithPage_atPoint_(myPage, pagePoint)
	myLabel = NSString.stringWithString_(label)
	myOutline = Quartz.PDFOutline.alloc().init()
	myOutline.setLabel_(myLabel)
	myOutline.setDestination_(myDestination)
	return myOutline
开发者ID:benwiggy,项目名称:PDFsuite,代码行数:15,代码来源:createPDFoutlines.py

示例15: _send_message

# 需要导入模块: from Foundation import NSString [as 别名]
# 或者: from Foundation.NSString import stringWithString_ [as 别名]
 def _send_message(self, event_type, *arguments):
     if not self._port:
         self._connect_port()
     message_type = bytearray([event_type])
     message_args = [ NSString.stringWithString_(arg).dataUsingEncoding_(NSUTF16StringEncoding) for arg in arguments ]
     components = [message_type] + message_args
     try:
         message = NSPortMessage.alloc().initWithSendPort_receivePort_components_(self._port, None, components)
         if not message.sendBeforeDate_(NSDate.dateWithTimeIntervalSinceNow_(self.EVENT_TIMEOUT)):
             raise Exception('Failed to send the port message.')
     except Exception:
         TRACE('Mach port became invalid.')
         self._port = None
         raise
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:16,代码来源:finder.py


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