def start_taskbar(): t = NSStatusBar.systemStatusBar() icon = t.statusItemWithLength_(NSVariableStatusItemLength) icon.setHighlightMode_(1) menuitems = [] labels = ["Open", "Logout", "Quit"] if patch.current.current == "DEV" or patch.config.branch == "master": labels = ["Open", "Logout", "Restart", "Test", "Quit"] for label in labels: item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( localize._X(label), label.lower().replace(" ", "").split(" ")[0] + ":", "") iconpath = os.path.join(settings.menuiconfolder, label.lower() + ".icns") if os.path.exists(iconpath): img = NSImage.alloc().initByReferencingFile_(iconpath) img.setSize_(NSSize(16, 16)) item.setImage_(img) menuitems.append(item) menu = NSMenu.alloc().init() menu.setAutoenablesItems_(True) icon.setMenu_(menu) for m in menuitems: menu.addItem_(m) def set_image(path): taskbarimg = NSImage.alloc().initByReferencingFile_(path) taskbarimg.setSize_(NSSize(18, 18)) icon.setImage_(taskbarimg) # taskbar icon switching @event.register("api:connected") def set_active(*_): set_image(settings.taskbaricon) @event.register("api:disconnected") @event.register("api:connection_error") def set_inactive(*_): set_image(settings.taskbaricon_inactive) set_image(settings.taskbaricon_inactive) icon.setEnabled_(True) @login.config.register('username') def _(): item = menu.itemAtIndex_(0) item.setTitle_(login.config.username or "Open")
def __init__(self, value=50, min_value=0, max_value=100, callback=None, dimensions=(180, 15)): self._slider = NSSlider.alloc().init() self._slider.setMinValue_(min_value) self._slider.setMaxValue_(max_value) self._slider.setDoubleValue_(value) self._slider.setFrameSize_(NSSize(*dimensions)) self._slider.setTarget_(NSApp) self._menuitem = NSMenuItem.alloc().init() self._menuitem.setTarget_(NSApp) self._menuitem.setView_(self._slider) self.set_callback(callback)
def build_menu(labels): menu = NSMenu.alloc().init() menu.setAutoenablesItems_(True) for label in labels: item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( localize._X(label), label.lower().replace(" ", "").split(" ")[0] + ":", "") iconpath = os.path.join(settings.menuiconfolder, label.lower() + ".icns") if os.path.exists(iconpath): img = NSImage.alloc().initByReferencingFile_(iconpath) img.setSize_(NSSize(16, 16)) item.setImage_(img) menu.addItem_(item) return menu
def zoom(self, z): self.getCanvasView().scaleUnitSquareToSize_((z, z)) self.width = z * self.width self.height = z * self.height newSize = NSSize(self.width, self.height) self.getCanvasView().setFrameSize_(newSize)
def set_image(path): taskbarimg = NSImage.alloc().initByReferencingFile_(path) taskbarimg.setSize_(NSSize(18, 18)) icon.setImage_(taskbarimg)