def size2(self, bstr): '''Get the size of a string. @param bstr: The string (C{str}, C{bytes} or L{Str}). @return: 2-Tuple (width, height) in (C{float} or C{int}). ''' if isinstance(bstr, Str): ns = bstr.NS elif isinstance(bstr, _ByteStrs): ns = release(NSStr(bstr)) elif isinstanceOf(bstr, NSStr, name='bstr'): ns = bstr return flint(self.NS.widthOfString_(ns)), self.height
def pull_command(self, command, session): cursor = self._conn.cursor() since = utils.flint(command['SINCE']) cursor.execute('SELECT * FROM files WHERE received>?', [since]) new_files = cursor.fetchall() cursor.execute('SELECT * FROM deleted WHERE del_time>?', [since]) del_files = cursor.fetchall() l = [] for record in new_files: l.append({'ID': record['id'], 'TYPE': 'NEW'}) for record in del_files: l.append({'ID': record['file_id'], 'TYPE': 'DELETE'}) resp = {'ACTION': 'LLUP', 'CHANGES': l} return resp, session
def slant(self): '''Get the italic angle (C{float}, C{int} or C{None}). ''' return flint(self.NS.italicAngle()) if self.NS else None
def heightX(self): '''Get the C{x} height (C{float} or C{int}). ''' return flint(self.NS.xHeight())
def heightLeading(self): '''Get the C{leading} height (C{float} or C{int}). ''' return flint(self.NS.leading())
def heightCap(self): '''Get the C{cap} height (C{float} or C{int}). ''' return flint(self.NS.capHeight())
def heightBaseline(self): '''Get the C{baseline} offset (C{float} or C{int}). ''' return flint(NSMain.LayoutManager.defaultBaselineOffsetForFont_(self.NS))
def __init__(self, family_or_font, size=0, traits=0, weight=5): '''New L{Font}. @param family_or_font: Generic font name (C{str}, L{Str}, L{NSStr}) like "Times" or "Helvetica" or a L{Font}, C{NSFont} or C{NSFontDescriptor} instance. @keyword size: Desired point size (C{int}), zero for any. @keyword traits: Desired font traits (C{str} or C{FontTrait}C{s mask}). @keyword weigth: Desired book weight (C{int}) in range 0..15, where 0=light, 5=regular, 9=bold and 15=heavy. @raise FontError: No such I{family_or_font}. @raise FontTraitError: Mutually exclusive I{traits}. @raise TypeError: Invalid I{family_or_font}. @raise ValueError: Invalid I{weight}. @note: The new L{Font} may not exhibit the desired I{traits} and I{weight}. The I{weight} is ignored if I{traits} include C{FontTrait.Bold}, both I{traits} and I{weight} are ignored if I{family_or_font} is C{NSFontDescriptor}. @see: Function L{fontsof} to obtain all available fonts of a particular font family. ''' if isinstance(family_or_font, Str): ns, py = family_or_font.NS, str(family_or_font) elif isinstance(family_or_font, _ByteStrs): ns, py = release(NSStr(family_or_font)), bytes2str(family_or_font) elif isinstance(family_or_font, NSStr): ns, py = family_or_font, nsString2str(family_or_font) # elif isObjCInstanceOf(family_or_font, NSFontDescriptor): # <http://Developer.Apple.com/documentation/appkit/nsfont/1525386-init> # ignore traits and weight # ns, py = NSFont.alloc().init_(family_or_font, size), None elif isObjCInstanceOf(family_or_font, NSFont, name='family_or_font'): ns, py = family_or_font, None if size == 0: size = ns.pointSize() if traits == 0: traits = NSMain.FontManager.traitsOfFont_(ns) if not (size == ns.pointSize() and traits == NSMain.FontManager.traitsOfFont_(ns)): ns = ns.familyName() py = nsString2str(ns) if py is not None: # <http://Developer.Apple.com/documentation/appkit/ # nsfontmanager/1462332-fontwithfamily> self._traits = _traitsin(traits) self._weight = _weightin(weight) ns = NSMain.FontManager.fontWithFamily_traits_weight_size_( ns, self._traits, self._weight, size) if isNone(ns): self._family = py self._size = flint(size) raise FontError('no such %s: %s' % ('font', self._argstr())) self._NS = ns # _RO # <http://Developer.Apple.com/library/content/documentation/ # TextFonts/Conceptual/CocoaTextArchitecture/FontHandling/FontHandling.html> self._family = nsString2str(ns.familyName()) self._height = flint(NSMain.LayoutManager.defaultLineHeightForFont_(ns) + 1) self._name = nsString2str(ns.fontName()) self._size = flint(ns.pointSize()) # traits not always reflect actual traits self._traits = NSMain.FontManager.traitsOfFont_(ns) or 0 # update with the family traits, if any self._traits |= _traitsin(self._family, raiser=False) if ns.isFixedPitch() and not self.isMonoSpace: self._traits |= FontTrait.MonoSpace self._weight = NSMain.FontManager.weightOfFont_(ns)