def select(sender: rumps.MenuItem): index = None _options = [] if isinstance(options, dict): _options = list(options.keys()) index = osa_api.choose_from_list(sender.title, description, _options, multi) elif isinstance(options, list): index = osa_api.choose_from_list(sender.title, description, options, multi) if index is not None: content = None if isinstance(options, dict): content = options[_options[index]] elif isinstance(options, list): content = options[index] setattr(self.config, key, content) if empty_state: sender.state = content != '' self.config.save() return True return False
def update_zone_menu(self): players = [] for z in self.zones: menuitem = MenuItem(z.player_name, callback=self.select_zone) menuitem.state = 1 if self.zone == z else 0 players.append(menuitem) players.append(MenuItem('Update zones', callback=self.update_zones_fork)) if self.menu['Zones']: self.menu['Zones'].clear() self.menu['Zones'].update(players)
def add_local_clock(self): # add local zone by default local_zone = get_localzone().zone self.add_clock(local_zone) if self.timezones_menu.has_key(local_zone): self.timezones_menu[local_zone].state = 1 else: item = MenuItem(local_zone, callback=self.switch_clock_callback) item.state = 1 self.timezones_menu.add(item)
def set_input(sender: rumps.MenuItem): content = osa_api.dialog_input(sender.title, getattr(self.lang, description), str(getattr(self.config, key, '')), hidden=hidden) if content is not None: if to_int: if isinstance(content, str) and content.replace('-', '', 1).isnumeric(): setattr(self.config, key, int(content)) else: setattr(self.config, key, content) if empty_state: sender.state = content != '' self.config.save() return True return False
def init_menu(self): # add timezones menu self.timezones_menu = MenuItem('Time Zones') for tz in TIMEZONES: self.timezones_menu.add(MenuItem(tz, callback=self.switch_clock_callback)) # recently added menu self.recent_menu = MenuItem('Add Recent') # add interval menu self.interval_menu = MenuItem('Update Time') for secs in INTVLS: item = MenuItem(secs, callback=self.update_interval) if secs == DEFAULT_INTVL_STR: item.state = 1 self.interval_menu.add(item) self.about_btn = MenuItem('About', callback=self.open_about) self.quit_btn = MenuItem('Quit', callback=self.quit_app) self.menu = [self.timezones_menu, self.recent_menu, self.interval_menu, self.about_btn, self.quit_btn]
def set_input(sender: rumps.MenuItem): content = osa_api.dialog_input(sender.title, getattr(self.lang, description), str(getattr(self.config, key, '')), hidden=hidden) if content is not None: if convertor is not None: content = convertor(content) if content is not None: setattr(self.config, key, content) if empty_state: sender.state = content != '' self.config.save() return True return False
def switch(sender: rumps.MenuItem): sender.state = not sender.state setattr(self.config, key, bool(sender.state)) self.config.save()