def checkUpdater(self): sparkle_path = bundle_path(fmwk="Sparkle") if os.path.exists(sparkle_path): # if this is a sparkle build, hook the ui elements up to the sharedUpdater objc.loadBundle("Sparkle", globals(), bundle_path=sparkle_path) sparkle = objc.lookUpClass("SUUpdater").sharedUpdater() self.updateDaily.bind_toObject_withKeyPath_options_("value", sparkle, "automaticallyChecksForUpdates", None) self.updateNow.setTarget_(sparkle) self.updateNow.setAction_("checkForUpdates:") else: # otherwise hide the Software Update box and resize the window updater_box = self.updateNow.superview().superview() updater_box.setHidden_(True) frame = self.window().frame() frame.size.height -= 52 self.window().setFrame_display_(frame, True)
def editor_info(name=None): if not _editor_info: global THEMES if THEMES is None: THEMES = json.load(open(bundle_path(rsrc="ui/themes.json"))) info = dict(family=get_default("font-name"), px=get_default("font-size")) info.update(THEMES.get(get_default("theme"))) info["colors"] = {k: _hex_to_nscolor(v) for k, v in info["colors"].items()} fm = NSFontManager.sharedFontManager() info["font"] = fm.fontWithFamily_traits_weight_size_( info["family"], NSFixedPitchFontMask | NSUnboldFontMask | NSUnitalicFontMask, 6, info["px"] ) _editor_info.clear() _editor_info.update(info) if name: return _editor_info.get(name) return dict(_editor_info)
def checkUpdater(self): sparkle_path = bundle_path(fmwk='Sparkle') if os.path.exists(sparkle_path): # if this is a sparkle build, hook the ui elements up to the sharedUpdater objc.loadBundle('Sparkle', globals(), bundle_path=sparkle_path) sparkle = objc.lookUpClass('SUUpdater').sharedUpdater() self.updateDaily.bind_toObject_withKeyPath_options_( 'value', sparkle, "automaticallyChecksForUpdates", None) self.updateNow.setTarget_(sparkle) self.updateNow.setAction_("checkForUpdates:") else: # otherwise hide the Software Update box and resize the window updater_box = self.updateNow.superview().superview() updater_box.setHidden_(True) frame = self.window().frame() frame.size.height -= 52 self.window().setFrame_display_(frame, True)
def finishInstallation_(self, sender): should_install = sender.tag() if should_install: console_py = bundle_path("Contents/SharedSupport/plotdevice") pth = self.toolInstallMenu.selectedItem().title().replace("~", os.environ["HOME"]) dirname = os.path.dirname(pth) try: if os.path.exists(pth) or os.path.islink(pth): os.unlink(pth) elif not os.path.exists(dirname): os.makedirs(dirname) os.symlink(console_py, pth) except OSError: SysAdmin = objc.lookUpClass("SysAdmin") SysAdmin.createSymlink_(pth) self.checkTool() NSApp().endSheet_(self.toolInstallSheet) self.toolInstallSheet.orderOut_(self)
def finishInstallation_(self, sender): should_install = sender.tag() if should_install: console_py = bundle_path('Contents/SharedSupport/plotdevice') pth = self.toolInstallMenu.selectedItem().title().replace( '~', os.environ['HOME']) dirname = os.path.dirname(pth) try: if os.path.exists(pth) or os.path.islink(pth): os.unlink(pth) elif not os.path.exists(dirname): os.makedirs(dirname) os.symlink(console_py, pth) except OSError: SysAdmin = objc.lookUpClass('SysAdmin') SysAdmin.createSymlink_(pth) self.checkTool() NSApp().endSheet_(self.toolInstallSheet) self.toolInstallSheet.orderOut_(self)
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 editor_info(name=None): if not _editor_info: global THEMES if THEMES is None: THEMES = json.load(file(bundle_path(rsrc='ui/themes.json'))) info = dict(family=get_default('font-name'), px=get_default('font-size')) info.update(THEMES.get(get_default('theme'))) info['colors'] = {k:_hex_to_nscolor(v) for k,v in info['colors'].items()} fm = NSFontManager.sharedFontManager() info['font'] = fm.fontWithFamily_traits_weight_size_( info['family'], NSFixedPitchFontMask|NSUnboldFontMask|NSUnitalicFontMask, 6, info['px'] ) _editor_info.clear() _editor_info.update(info) if name: return _editor_info.get(name) return dict(_editor_info)
def _tool(self): broken = [] for path in possibleToolLocations(): if os.path.islink(path): # if it's a symlink, make sure it points to this bundle tool_path = os.path.realpath(path) found = path valid = tool_path.startswith(bundle_path()) if valid: action = "reveal" break broken.append(path) if os.path.exists(path): # if it's a normal file, something went wrong broken.append(path) else: # didn't find any working symlinks in the $PATH found = broken[0] if broken else None valid = False action = "install" if not found else "repair" return found, valid, action
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 editor_info(name=None): if not _editor_info: global THEMES if THEMES is None: THEMES = json.load(open(bundle_path(rsrc='ui/themes.json'))) info = dict(family=get_default('font-name'), px=get_default('font-size')) info.update(THEMES.get(get_default('theme'))) info['colors'] = { k: _hex_to_nscolor(v) for k, v in info['colors'].items() } fm = NSFontManager.sharedFontManager() info['font'] = fm.fontWithFamily_traits_weight_size_( info['family'], NSFixedPitchFontMask | NSUnboldFontMask | NSUnitalicFontMask, 6, info['px']) _editor_info.clear() _editor_info.update(info) if name: return _editor_info.get(name) return dict(_editor_info)
def _tool(self): broken = [] for path in possibleToolLocations(): if os.path.islink(path): # if it's a symlink, make sure it points to this bundle tool_path = os.path.realpath(path) found = path valid = tool_path.startswith(bundle_path()) if valid: action = 'reveal' break broken.append(path) if os.path.exists(path): # if it's a normal file, something went wrong broken.append(path) else: # didn't find any working symlinks in the $PATH found = broken[0] if broken else None valid = False action = 'install' if not found else 'repair' return found, valid, action