def _attrs(self, stream=None): clr, font = editor_info('colors'), editor_info('font') basic_attrs = {"NSFont":font, "NSLigature":0} attrs = { 'message':{"NSColor":clr['color']}, 'info':{"NSColor":clr['comment']}, 'err':{"NSColor":clr['error']} } for s,a in attrs.items(): a.update(basic_attrs) a.update({"stream":s}) if stream: return attrs.get(stream) return attrs
def drawRect_(self, rect): if self._wakeup: # try to minimize the f.o.u.c. while the webview starts up bgcolor = editor_info('colors')['background'] bgcolor.setFill() NSRectFillUsingOperation(rect, NSCompositeCopy) super(EditorView, self).drawRect_(rect)
def colorize(self): clr, font = editor_info('colors'), editor_info('font') self.setBackgroundColor_(clr['background']) self.setTypingAttributes_({"NSColor":clr['color'], "NSFont":font, "NSLigature":0}) self.setSelectedTextAttributes_({"NSBackgroundColor":clr['selection']}) scrollview = self.superview().superview() scrollview.setScrollerKnobStyle_(2 if editor_info('dark') else 1) # recolor previous contents attrs = self._attrs() self.ts.beginEditing() last = self.ts.length() cursor = 0 while cursor < last: a, r = self.ts.attributesAtIndex_effectiveRange_(cursor, None) self.ts.setAttributes_range_(attrs[a['stream']],r) cursor = r.location+r.length self.ts.endEditing()
def _attrs(self, stream=None): clr, font = editor_info('colors'), editor_info('font') basic_attrs = {"NSFont": font, "NSLigature": 0} attrs = { 'message': { "NSColor": clr['color'] }, 'info': { "NSColor": clr['comment'] }, 'err': { "NSColor": clr['error'] } } for s, a in attrs.items(): a.update(basic_attrs) a.update({"stream": s}) if stream: return attrs.get(stream) return attrs
def colorize(self): clr, font = editor_info('colors'), editor_info('font') self.setBackgroundColor_(clr['background']) self.setTypingAttributes_({ "NSColor": clr['color'], "NSFont": font, "NSLigature": 0 }) self.setSelectedTextAttributes_( {"NSBackgroundColor": clr['selection']}) scrollview = self.superview().superview() scrollview.setScrollerKnobStyle_(2 if editor_info('dark') else 1) # recolor previous contents attrs = self._attrs() self.ts.beginEditing() last = self.ts.length() cursor = 0 while cursor < last: a, r = self.ts.attributesAtIndex_effectiveRange_(cursor, None) self.ts.setAttributes_range_(attrs[a['stream']], r) cursor = r.location + r.length self.ts.endEditing()
def awakeFromNib(self): self.webview = DraggyWebView.alloc().initWithFrame_(self.bounds()) self.webview.setAllowsUndo_(False) self.webview.setFrameLoadDelegate_(self) self.webview.setUIDelegate_(self) self.addSubview_(self.webview) self.webview.setHidden_(True) html = bundle_path(rsrc='ui/editor.html') ui = file(html).read().decode('utf-8') baseurl = NSURL.fileURLWithPath_(os.path.dirname(html)) self.webview.mainFrame().loadHTMLString_baseURL_(ui, baseurl) # set a theme-derived background for the webview's clipview docview = self.webview.mainFrame().frameView().documentView() clipview = docview.superview() scrollview = clipview.superview() if clipview is not None: bgcolor = editor_info('colors')['background'] clipview.setDrawsBackground_(True) clipview.setBackgroundColor_(bgcolor) scrollview.setVerticalScrollElasticity_(1) scrollview.setScrollerKnobStyle_(2) nc = NSNotificationCenter.defaultCenter() nc.addObserver_selector_name_object_(self, "themeChanged", "ThemeChanged", None) nc.addObserver_selector_name_object_(self, "fontChanged", "FontChanged", None) nc.addObserver_selector_name_object_(self, "bindingsChanged", "BindingsChanged", None) nc.addObserver_selector_name_object_(self, "insertDroppedFiles:", "DropOperation", self.webview) self._wakeup = set_timeout(self, '_jostle', .05, repeat=True) self._queue = [] self._edits = 0 self.themeChanged() self.fontChanged() self.bindingsChanged() mm = NSApp().mainMenu() self._doers = mm.itemWithTitle_('Edit').submenu().itemArray()[1:3] self._undo_mgr = None
def awakeFromNib(self): self.webview = DraggyWebView.alloc().initWithFrame_(self.bounds()) self.webview.setAllowsUndo_(False) self.webview.setFrameLoadDelegate_(self) self.webview.setUIDelegate_(self) self.addSubview_(self.webview) self.webview.setHidden_(True) html = bundle_path(rsrc='ui/editor.html') ui = file(html).read().decode('utf-8') baseurl = NSURL.fileURLWithPath_(os.path.dirname(html)) self.webview.mainFrame().loadHTMLString_baseURL_(ui, baseurl) # set a theme-derived background for the webview's clipview docview = self.webview.mainFrame().frameView().documentView() clipview = docview.superview() scrollview = clipview.superview() if clipview is not None: bgcolor = editor_info('colors')['background'] clipview.setDrawsBackground_(True) clipview.setBackgroundColor_(bgcolor) scrollview.setVerticalScrollElasticity_(1) scrollview.setScrollerKnobStyle_(2) nc = NSNotificationCenter.defaultCenter() nc.addObserver_selector_name_object_(self, "themeChanged", "ThemeChanged", None) nc.addObserver_selector_name_object_(self, "fontChanged", "FontChanged", None) nc.addObserver_selector_name_object_(self, "bindingsChanged", "BindingsChanged", None) nc.addObserver_selector_name_object_(self, "insertDroppedFiles:", "DropOperation", self.webview) self._wakeup = set_timeout(self, '_jostle', .05, repeat=True) self._queue = [] self._edits = 0 self.themeChanged() self.fontChanged() self.bindingsChanged() mm=NSApp().mainMenu() self._doers = mm.itemWithTitle_('Edit').submenu().itemArray()[1:3] self._undo_mgr = None
def fontChanged(self, note=None): self.setFont_(editor_info('font')) self.colorize()
def themeChanged(self, note=None): info = editor_info() clipview = self.webview.mainFrame().frameView().documentView().superview() clipview.setBackgroundColor_(info['colors']['background']) self.js('editor.theme', args(info['module']))
def fontChanged(self, note=None): info = editor_info() self.js('editor.font', args(info['family'], info['px']))
def themeChanged(self, note=None): info = editor_info() clipview = self.webview.mainFrame().frameView().documentView( ).superview() clipview.setBackgroundColor_(info['colors']['background']) self.js('editor.theme', args(info['module']))