def show_url(self, url=None): safe_assert(url is not None) if not self.config.get('external_browser'): webview = self._get_webview() if webview: return webview.show_url(url) webbrowser.open(url)
def command(self): ctx = self.data.get('context') if 'reset' in self.args: safe_assert(self.data.get('_method', 'POST') == 'POST') ts = self.timestamps() for k in ts.keys(): del ts[k] ts['initial'] = self._today() elif 'next' in self.args: safe_assert(self.data.get('_method', 'POST') == 'POST') self.timestamps()['last_displayed'] = 0 self.timestamps()['initial'] -= 30 if 'now' in self.args or 'now' in self.data: hint = self._choose_hint(ctx) if hint: if 'POST' == self.data.get('_method', 'POST'): self._postpone_hint(hint) return self._success(hint[3], result={ 'hints': [self._hint_event(ctx, hint)]}) else: return self._success(_('Nothing Happened'), result={ 'hints': []}) else: return self._success(_('Did you know') + ' ...', result={ 'today': self._today(), 'days': self._days(), 'ts': self.timestamps(), 'hints': [self._hint_event(ctx, h) for h in self.ALL_HINTS]})
def _mk_command(self): if self.state == self.STATE_RAW_DATA: return None elif self.decryptor is not None: return None elif self.state == self.STATE_PGP_DATA: safe_assert(self.gpgi is not None) if self.gpg_pass: return self.gpgi.common_args(will_send_passphrase=True) else: return self.gpgi.common_args() return [OPENSSL_COMMAND(), "enc", "-d", "-a", "-%s" % self.cipher, "-pass", "stdin", "-md", self.md_alg]
def __init__(self, cooked_fp=None, binary_fp=None, flags=None): safe_assert((cooked_fp or binary_fp) and not (cooked_fp and binary_fp)) if cooked_fp: if isinstance(cooked_fp, FilePath): self.raw_fp = cooked_fp.raw_fp flags = cooked_fp.flags if (flags is None) else flags elif (isinstance(cooked_fp, (str, unicode)) and cooked_fp[-2:] == '=!'): self.raw_fp = self.unalias(cooked_fp[:-2].decode('base64')) elif isinstance(cooked_fp, unicode): self.raw_fp = self.unalias(cooked_fp.encode('utf-8')) else: self.raw_fp = self.unalias(str(cooked_fp)) else: self.raw_fp = binary_fp self.flags = flags
def MacOSXIndicator(): safe_assert(objc is not None) class MacOSXThing(NSObject): indicator = None def applicationDidFinishLaunching_(self, notification): self.indicator._menu_setup() self.indicator._ind_setup() self.indicator.ready = True def activate_(self, notification): for i, v in self.indicator.items.iteritems(): if notification == v: if i in self.indicator.callbacks: self.indicator.callbacks[i]() return print 'activated an unknown item: %s' % notification class MailpileIndicator(Indicator): ICON_THEME = 'osx' # OS X has its own theme because it is too # dumb to auto-resize menu bar icons. def _menu_setup(self): # Build a very simple menu self.menu = NSMenu.alloc().init() self.menu.setAutoenablesItems_(objc.NO) self.items = {} self.callbacks = {} self._create_menu_from_config() def _add_menu_item(self, item='item', label='Menu item', sensitive=False, op=None, args=None, **ignored_kwarg): # For now, bind everything to the notify method menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( label, 'activate:', '') menuitem.setEnabled_(sensitive) self.menu.addItem_(menuitem) self.items[item] = menuitem if op: def activate(o, a): return lambda: self._do(o, a) self.callbacks[item] = activate(op, args or []) def _ind_setup(self): # Create the statusbar item self.ind = NSStatusBar.systemStatusBar().statusItemWithLength_( NSVariableStatusItemLength) # Load all images, set initial self.images = {} for s, p in self.config.get('indicator_icons', {}).iteritems(): p = self._theme_image(p) self.images[s] = NSImage.alloc().initByReferencingFile_(p) if self.images: self.ind.setImage_(self.images['normal']) self.ind.setHighlightMode_(1) #self.ind.setToolTip_('Sync Trigger') self.ind.setMenu_(self.menu) self.set_status_startup() def _set_status(self, status): self.ind.setImage_(self.images.get(status, self.images['normal'])) def set_menu_label(self, item=None, label=None): if item and item in self.items: self.items[item].setTitle_(label) def set_menu_sensitive(self, item=None, sensitive=True): if item and item in self.items: self.items[item].setEnabled_(sensitive) def notify_user(self, message=None): pass # FIXME def run(self): app = NSApplication.sharedApplication() osxthing = MacOSXThing.alloc().init() osxthing.indicator = self app.setDelegate_(osxthing) try: AppHelper.runEventLoop() except: traceback.print_exc() return MailpileIndicator
def register_alias(name, prefix): global VFS_ALIASES safe_assert(name[:1] == '/') VFS_ALIASES[name] = prefix