def System(self): '''Get the C{SystemFont}. ''' if self._System is None: _Fonts._System = Font(NSFont.systemFontOfSize_(0)) return self._System
def Title(self): '''Get the C{TitleFont}. ''' if self._Title is None: _Fonts._Title = Font(NSFont.titleBarFontOfSize_(0)) return self._Title
def MonoSpace(self): '''Get the C{MonoSpaceFont}. ''' if self._MonoSpace is None: _Fonts._MonoSpace = Font(NSFont.userFixedPitchFontOfSize_(0)) return self._MonoSpace
def Palette(self): '''Get the C{PaletteFont}. ''' if self._Palette is None: _Fonts._Palette = Font(NSFont.paletteFontOfSize_(0)) return self._Palette
def MenuBar(self): '''Get the C{MenuBarFont}. ''' if self._MenuBar is None: _Fonts._MenuBar = Font(NSFont.menuBarFontOfSize_(0)) return self._MenuBar
def Message(self): '''Get the C{MessageFont}. ''' if self._Message is None: _Fonts._Message = Font(NSFont.messageFontOfSize_(0)) return self._Message
def Label(self): '''Get the C{LabelFont}. ''' if self._Label is None: _Fonts._Label = Font(NSFont.labelFontOfSize_(0)) return self._Label
def Bold(self): '''Get the C{BoldFont}. ''' if self._Bold is None: _Fonts._Bold = Font(NSFont.boldSystemFontOfSize_(0)) return self._Bold
def App(self): '''Get the C{UserFont}. ''' if self._App is None: _Fonts._App = Font(NSFont.userFontOfSize_(0)) return self._App
def __init__(self, text_or_file, font=None, title='Text', fraction=0.5, **kwds): '''Create a L{TextWindow}. @param text_or_file: The contents (C{str} or C{file}). @keyword font: Optional font (L{Font}), default C{Fonts.MonoSpace}. @keyword title: Window name or title (C{str}). @keyword fraction: Window size as fraction of the screen (C{float}). @keyword kwds: Optional, additional keyword arguments, see L{Window}. ''' text, t = _text_title2(text_or_file, title) super(TextWindow, self).__init__(title=t, frame=Screen(fraction), **kwds) if font is None: f = NSFont.userFixedPitchFontOfSize_(12) else: f = font.NS w, _, _ = nsTextSize3(text, f) # <https://Developer.Apple.com/library/content/documentation/ # Cocoa/Conceptual/TextUILayer/Tasks/CreateTextViewProg.html> # <https://Developer.Apple.com/library/content/documentation/ # Cocoa/Conceptual/TextUILayer/Tasks/TextInScrollView.html> ns = self.NS cr = ns.contentView().frame() hs = w > cr.size.width sv = NSScrollView.alloc().initWithFrame_(cr) sv.setBorderType_(Border.No) if hs: sv.setHasHorizontalScroller_(YES) sv.setAutoresizingMask_(AutoResize.Sizable) else: sv.setHasHorizontalScroller_(NO) sv.setAutoresizingMask_(AutoResize.WidthSizable) sv.setHasVerticalScroller_(YES) tv = NSTextView.alloc().initWithFrame_(cr) tv.setMaxSize_(NSSize_t(NSIntegerMax, NSIntegerMax)) tv.setMinSize_(NSSize_t(16, cr.size.height)) tc = tv.textContainer() if hs: tv.setHorizontallyResizable_(YES) tv.setAutoresizingMask_(AutoResize.Sizable) tc.setContainerSize_(NSSize_t(NSIntegerMax, NSIntegerMax)) # FLT_MAX tc.setWidthTracksTextView_(NO) # YES? else: tv.setHorizontallyResizable_(NO) tv.setAutoresizingMask_(AutoResize.WidthSizable) tc.setContainerSize_(NSSize_t(cr.size.width, NSIntegerMax)) # FLT_MAX tc.setWidthTracksTextView_(YES) # NO? tv.setVerticallyResizable_(YES) tv.setFont_(f) # XXX set font BEFORE text tv.insertText_(release(NSStr(text))) tv.setEditable_(NO) tv.setDrawsBackground_(NO) self.NSView = sv # == ns.setContentView_(sv) self.PMview = tv # XXX or sv? ns.makeKeyAndOrderFront_(None) ns.makeFirstResponder_(tv)
def show(self, text='', font=None, timeout=None): '''Show alert message iff not suppressed. @keyword text: Optional, accessory text (C{str}). @keyword font: Optional font (L{Font}), default C{Fonts.System}. @keyword timeout: Optional time limit (C{float}). @return: The button clicked (C{PanelButton}). If C{PanelButton.Suppressed} is returned, the alert panel was not shown since it was suppressed due to a previous selection of the corresponding check box. C{PanelButton.TimedOut} is returned if no button was clicked before the I{timeout} expired. ''' # <https://Developer.Apple.com/documentation/appkit/nsalert> ns = NSAlert.alloc().init() ns.setAlertStyle_(self._style) ns.setMessageText_(release(NSStr(self.title))) if self._info: # <https://Developer.Apple.com/library/content/documentation/ # Cocoa/Conceptual/Strings/Articles/stringsParagraphBreaks.html> ns.setInformativeText_(NSStr(self._info)) ns.addButtonWithTitle_(release(NSStr(self._ok))) if self._cancel: ns.addButtonWithTitle_(release(NSStr(self._cancel))) if self._other: ns.addButtonWithTitle_(release(NSStr(self._other))) if self._suppress in (False, YES): self._suppress = False ns.setShowsSuppressionButton_(YES) s = _AlertStyleStr.get(self._style, '') s = 'Do not show this %sAlert again' % (s, ) ns.suppressionButton().setTitle_(release(NSStr(s))) # <https://Developer.Apple.com/library/content/documentation/ # Cocoa/Conceptual/Dialog/Tasks/DisplayAlertHelp.html> # ns.showsHelp_(YES) # ns.helpAnchor_(HTML?) if text: t = nsTextView( text, NSFont.systemFontOfSize_(0) if font is None else font.NS) ns.setAccessoryView_(t) # <https://Developer.Apple.com/documentation/appkit/ # nsalert/1535196-showssuppressionbutton> if self._suppress is None: r = _runModal(ns, timeout) elif self._suppress is False: s = ns.suppressionButton().state() r = _runModal(ns, timeout) # XXX value of NSOnState? if ns.suppressionButton().state() != s: self._suppress = True else: r = PanelButton.Suppressed # ns.release() # XXX may crash return r