📄 uibackenddelegate.py
字号:
launchedApps.append(launchInfo) elif ourEntry is not None: launchedApps.remove(entry) lwdomain = Conversion.propertyListFromPythonCollection(lwdomain) defaults.setPersistentDomain_forName_(lwdomain, 'loginwindow') defaults.synchronize() def getURLFromClipboard(self): url = NSPasteboard.generalPasteboard().stringForType_(NSStringPboardType) if url is None or not feed.validateFeedURL(url): url = "" return url @platformutils.onMainThread def showContextMenu(self, items): nsmenu = NSMenu.alloc().init() nsmenu.setAutoenablesItems_(NO) for item in items: if item.label == '': nsitem = NSMenuItem.separatorItem() else: nsitem = NSMenuItem.alloc() nsitem.initWithTitle_action_keyEquivalent_(item.label, 'processContextItem:', '') nsitem.setEnabled_(item.callback is not None) nsitem.setRepresentedObject_(item) nsitem.setTarget_(self.contextItemHandler) nsmenu.addItem_(nsitem) window = NSApplication.sharedApplication().mainWindow() view = window.contentView() event = NSEvent.mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( NSRightMouseDown, window.mouseLocationOutsideOfEventStream(), 0, 1, window.windowNumber(), NSGraphicsContext.currentContext(), 1, 1, 0.0) NSMenu.popUpContextMenu_withEvent_forView_(nsmenu, event, view)###############################################################################class ContextItemHandler (NSObject): @signature("v@:@") def processContextItem_(self, item): item.representedObject().activate()###############################################################################class ExceptionReporterController (NibClassBuilder.AutoBaseClass): def initWithMoment_log_(self, when, log): self = super(ExceptionReporterController, self).initWithWindowNibName_owner_("ExceptionReporterPanel", self) self.info = config.getAppConfig() self.info['when'] = when self.info['log'] = log return self def awakeFromNib(self): title = string.Template(self.window().title()).safe_substitute(self.info) msg1 = string.Template(self.msg1Field.stringValue()).safe_substitute(self.info) msg3 = string.Template(self.msg3View.string()).safe_substitute(self.info) nsmsg3 = NSString.stringWithString_(unicode(msg3)) msg3Data = nsmsg3.dataUsingEncoding_(NSUTF8StringEncoding) (msg3, attrs) = NSAttributedString.alloc().initWithHTML_documentAttributes_(msg3Data) logmsg = string.Template(self.logView.string()).safe_substitute(self.info) self.window().setTitle_(title) self.msg1Field.setStringValue_(msg1) self.msg3View.setBackgroundColor_(NSColor.controlColor()) self.msg3View.textContainer().setLineFragmentPadding_(0) self.msg3View.textStorage().setAttributedString_(msg3) self.logView.setString_(logmsg) def showPanel(self): platformutils.warnIfNotOnMainThread('ExceptionReporterController.showPanel') NSApplication.sharedApplication().runModalForWindow_(self.window()) def dismissPanel_(self, sender): self.window().close() NSApplication.sharedApplication().stopModal()###############################################################################class PasswordController (NibClassBuilder.AutoBaseClass): def initWithDialog_(self, dialog): NSBundle.loadNibNamed_owner_("PasswordWindow", self) self.window.setTitle_(dialog.title) self.usernameField.setStringValue_(dialog.prefillUser or "") self.passwordField.setStringValue_(dialog.prefillPassword or "") self.textArea.setStringValue_(dialog.description) self.result = None return self def getAnswer(self): """Present the dialog and wait for user answer. Returns (username, password) if the user pressed OK, or None if the user pressed Cancel.""" NSApplication.sharedApplication().runModalForWindow_(self.window) return self.result # bound to button in nib def acceptEntry_(self, sender): result = (self.usernameField.stringValue(), self.passwordField.stringValue()) self.closeWithResult(result) # bound to button in nib def cancelEntry_(self, sender): self.closeWithResult(None) def closeWithResult(self, result): self.result = result self.window.close() NSApplication.sharedApplication().stopModal()###############################################################################class TextEntryController (NibClassBuilder.AutoBaseClass): def initWithDialog_(self, dialog): self = super(TextEntryController, self).initWithWindowNibName_owner_("TextEntryWindow", self) self.dialog = dialog self.window().setTitle_(dialog.title) self.messageField.setStringValue_(dialog.description) self.entryField.setStringValue_("") self.mainButton.setTitle_(dialog.buttons[0].text) self.secondaryButton.setTitle_(dialog.buttons[1].text) self.result = None self.value = None return self def run(self): if self.dialog.fillWithClipboardURL: self.entryField.setStringValue_(app.delegate.getURLFromClipboard()) elif self.dialog.prefillCallback is not None: self.entryField.setStringValue_(self.dialog.prefillCallback() or "") NSApplication.sharedApplication().runModalForWindow_(self.window()) def acceptEntry_(self, sender): self.closeWithResult(self.dialog.buttons[0], self.entryField.stringValue()) def cancelEntry_(self, sender): self.closeWithResult(self.dialog.buttons[1], None) def closeWithResult(self, result, value): self.result = result self.value = value self.window().close() NSApplication.sharedApplication().stopModal()###############################################################################class SearchChannelController (NibClassBuilder.AutoBaseClass): def initWithDialog_(self, dialog): self = super(SearchChannelController, self).initWithWindowNibName_owner_('SearchChannelWindow', self) self.dialog = dialog self.result = None self.window().setTitle_(dialog.title) self.labelField.setStringValue_(dialog.description) self.searchTermField.setStringValue_(dialog.term or '') self.targetMatrix.selectCellWithTag_(dialog.style) self.changeTarget_(self.targetMatrix) self.channelPopup.removeAllItems() for cid, title in dialog.channels: self.channelPopup.addItemWithTitle_(title) self.enginePopup.removeAllItems() for name, title in dialog.engines: self.enginePopup.addItemWithTitle_(title) if dialog.style == dialogs.SearchChannelDialog.CHANNEL: channel = self.getChannelTitleForID(dialog.location) self.channelPopup.selectItemWithTitle_(channel) elif dialog.style == dialogs.SearchChannelDialog.ENGINE: engine = self.getEngineTitleForName(dialog.location, dialog.defaultEngine) self.enginePopup.selectItemWithTitle_(engine) self.controlTextDidChange_(nil) return self def getChannelTitleForID(self, cid): for eid, etitle in self.dialog.channels: if eid == cid: return etitle return self.dialog.channels[0][1] def getChannelIDForTitle(self, ctitle): for eid, etitle in self.dialog.channels: if etitle == ctitle: return eid return self.dialog.channels[0][0] def getEngineTitleForName(self, name, default): for ename, etitle in self.dialog.engines: if ename == name: return etitle return default def getEngineNameForTitle(self, title): for ename, etitle in self.dialog.engines: if etitle == title: return ename return self.dialog.engines[0][0] def run(self): NSApplication.sharedApplication().runModalForWindow_(self.window()) def controlTextDidChange_(self, notification): enable = (self.searchTermField.stringValue().strip() != '') if self.targetMatrix.selectedCell().tag() == dialogs.SearchChannelDialog.URL: enable = enable and (self.urlField.stringValue().strip() != '') self.createButton.setEnabled_(enable) def changeTarget_(self, sender): target = sender.selectedCell().tag() self.channelPopup.setEnabled_(target == dialogs.SearchChannelDialog.CHANNEL) self.enginePopup.setEnabled_(target == dialogs.SearchChannelDialog.ENGINE) self.urlField.setEnabled_(target == dialogs.SearchChannelDialog.URL) self.controlTextDidChange_(nil) def cancel_(self, sender): self.closeWithResult(self.dialog.buttons[1]) def create_(self, sender): self.dialog.term = self.searchTermField.stringValue() self.dialog.style = self.targetMatrix.selectedCell().tag() if self.dialog.style == dialogs.SearchChannelDialog.CHANNEL: channel = self.channelPopup.titleOfSelectedItem() self.dialog.location = self.getChannelIDForTitle(channel) elif self.dialog.style == dialogs.SearchChannelDialog.ENGINE: engine = self.enginePopup.titleOfSelectedItem() self.dialog.location = self.getEngineNameForTitle(engine) elif self.dialog.style == dialogs.SearchChannelDialog.URL: self.dialog.location = self.urlField.stringValue() self.closeWithResult(self.dialog.buttons[0]) def closeWithResult(self, result): self.result = result self.window().close() NSApplication.sharedApplication().stopModal()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -