def exit_full_screen(self, windows): opts = NSMutableDictionary.alloc().init() opts.setObject(NSNumber.numberWithBool(True), forKey="NSFullScreenModeAllScreens") for window in windows: window.content._impl.native.exitFullScreenModeWithOptions(opts)
def make_dictionary(self, contents=None): d = NSMutableDictionary.alloc().init() if contents is not None: for key, value in contents.items(): d.setObject_forKey_(value, key) return NSDictionary.dictionaryWithDictionary(d)
def write_text(self, text, x, y, font, *args, **kwargs): # Set font family and size if font: write_font = font elif self.native.font: write_font = self.native.font else: raise ValueError("No font to write with") width, height = write_font.measure(text) textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = write_font._impl.native if "stroke_color" in kwargs and "fill_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) # Apply negative NSStrokeWidthAttributeName to get stroke and fill textAttributes[ NSStrokeWidthAttributeName] = -1 * kwargs["text_line_width"] textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) elif "stroke_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) textAttributes[NSStrokeWidthAttributeName] = kwargs[ "text_line_width"] elif "fill_color" in kwargs: textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) else: raise ValueError("No stroke or fill of write text") text_string = NSAttributedString.alloc().initWithString_attributes_( text, textAttributes) text_string.drawAtPoint(NSPoint(x, y - height))
def measure(self, text, tight=False): textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = self.native text_string = NSAttributedString.alloc().initWithString_attributes_(text, textAttributes) size = text_string.size() size.width += 3 return size.width, size.height
def write_text(self, text, x, y, font, *args, **kwargs): width, height = self.measure_text(text, font) textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = font.bind(self.interface.factory).native if "stroke_color" in kwargs and "fill_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"] ) # Apply negative NSStrokeWidthAttributeName to get stroke and fill textAttributes[NSStrokeWidthAttributeName] = -1 * kwargs["text_line_width"] textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"] ) elif "stroke_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"] ) textAttributes[NSStrokeWidthAttributeName] = kwargs["text_line_width"] elif "fill_color" in kwargs: textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"] ) else: raise ValueError("No stroke or fill of write text") text_string = NSAttributedString.alloc().initWithString_attributes_( text, textAttributes ) text_string.drawAtPoint(NSPoint(x, y - height))
def measure(self, text, tight=False): textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = self.native text_string = NSAttributedString.alloc().initWithString_attributes_( text, textAttributes) size = text_string.size() # TODO: This is a magic fudge factor... # Replace the magic with SCIENCE. size.width += 3 return size.width, size.height
def enter_full_screen(self, windows): # If we're already in full screen mode, exit so that # we can re-assign windows to screens. if self.interface.is_full_screen: self.interface.exit_full_screen() opts = NSMutableDictionary.alloc().init() opts.setObject(NSNumber.numberWithBool(True), forKey="NSFullScreenModeAllScreens") for window, screen in zip(windows, NSScreen.screens): window.content._impl.native.enterFullScreenMode(screen, withOptions=opts)
def enter_full_screen(self, windows): # If we're already in full screen mode, exit so that # we can re-assign windows to screens. if self.interface.is_full_screen: self.interface.exit_full_screen() opts = NSMutableDictionary.alloc().init() opts.setObject(NSNumber.numberWithBool(True), forKey="NSFullScreenModeAllScreens") for window, screen in zip(windows, NSScreen.screens): window.content._impl.native.enterFullScreenMode(screen, withOptions=opts) # Going full screen causes the window content to be re-homed # in a NSFullScreenWindow; teach the new parent window # about it's Toga representations. window.content._impl.native.window._impl = window._impl window.content._impl.native.window.interface = window