jaredks / rumps Goto Github PK
View Code? Open in Web Editor NEWRidiculously Uncomplicated macOS Python Statusbar apps
License: BSD 3-Clause "New" or "Revised" License
Ridiculously Uncomplicated macOS Python Statusbar apps
License: BSD 3-Clause "New" or "Revised" License
Hi,
I want to have app sitting in menubar (did with Rumps) and to be system handler for opening HTTP URLs. I've configured plist like this:
'CFBundleURLTypes': [{'CFBundleURLName': 'Web Location', 'CFBundleURLSchemes': ['http', 'https']}],
and I want to make the app default browser and catch the URL always some other app tries to open it.
I found this python app what can listen for URLs and do some logic: https://github.com/irq0/osx-url-open-handler but I don want how to combine it with Rumps app.
Thanks for help!
When doing something like:
class MyApp(rumps.App):
@rumps.clicked("Options", "Foo")
def foo(self, sender):
## Never gets here.
## sender is passed as the self argument, and no sender argument.
This is only a problem if you do not construct the MenuItems your self explicitly post MyApp object construction; which is a PITA to do.
The problem is with how the update sets up the sub-menu's. It ends up doing so in a way that _call_as_function_or_method() does not recognize the callback as a method.
I'm on 10.10.1, sudo pip installed rumps without problems.
Any idea why I can't import the module?
Attempted to compile py2app with default setup.py included with repo. Fails to launch with:
ValueError: NSInvalidArgumentException - Class OC_PythonObject: no such selector: methodForSelector:
If I run from the .py file it runs without an issue. Attempted on clean install of Mountain Lion with Python 2.7.2 and updated Py2App
I've replicated it on ML and 10.9
I just wrote a quick countdown timer app in rumps - awesome work, really was a cinch!
The one question I had is how easy/possible it might be to change the font (ideally to a monospaced font like Monaco)? Some menubar apps seem able to do it, but I don't know enough of the Menubar/Cocoa specifics to know if that's something that's super hacky or not.
Is it possible to start a rumps app without it stealing os focus?
File "/usr/local/lib/python3.6/site-packages/rumps/rumps.py", line 434, in insert_before
super(Menu, self).insert_before(existing_key, (key, menuitem))
File "/usr/local/lib/python3.6/site-packages/rumps/utils.py", line 30, in insert_before
self.__insertion(self._OrderedDict__map[existing_key][0], key_value)
AttributeError: 'Menu' object has no attribute '_OrderedDict__map'
I am curious if anyone has any thoughts on writing tests for this code?
We use this for a couple small apps and I am kind of at a loss on where to begin testing pyobjc code. More of a general question as we'd like to offer some tests.
getting this error after updating to EL Capitan(OSX 10.11)
Traceback (most recent call last):
File "maccontrol.py", line 42, in <module>
app.run()
File "/Users/bajaj/MacControl/env/lib/python2.7/site-packages/rumps/rumps.py", line 1059, in run
NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self._nsapp)
AttributeError: 'NoneType' object has no attribute 'setDelegate_'
Hi,
unless I missed it, it seems you can only set the title during initialisation. I'd like to update it periodically.
cheers,
Beau
Like popup quick view window for an image in memory, rather than saving it to disk before programmatically open it via "Preview" app. Is that possible now? Or would you consider implementing this feature?
Is it possible to differentiate between Left and Right clicks?
I'd like to display a progress indicator while background jobs are being performed.
I like rumps as it meets my needs for creating a simple menu bar app.
But I don't quite understand how I can customize actions to be performed when my application starts or terminates. I think I have to define a delegate that would listen to the corresponding events, but I'm not sure how and if this can be done with rumps.
I also would like to customize the menu in such a way, that I define my own "Quit" menu item. Eventually, I'd like to give it a different name or place it in a sub-menu. But this seems to be impossible, as rumps automatically defines this menu item.
Another question: How can I terminate rumps application programmatically? Can you give an example of the code to be used? Most likely I have to send a "terminate:" event, but how can I do it?
Thanks,
Leo
In the example below, the function "a" is not being called asynchronously. The UI thread is blocked during each call to time.sleep and a spinner cursor is shown for 20 seconds.
I may just be misunderstanding how Timer objects are supposed to work. If that's the case, can you let me know if rumps includes a way to execute Timer callbacks (the "a" function in this case) in a separate thread?
import rumps
import time
def a(_):
print "blah"
time.sleep(20)
if __name__ == "__main__":
app = rumps.App('TestApp', menu=('Fake', 'All timers', 'Start timer', 'Stop timer'))
global_namespace_timer = rumps.Timer(a, 30)
global_namespace_timer.start()
app.run()
This is a really great library, a joy to use! However, I managed to his an edge case that probably isn't a common one.
I was generating menus dynamically, based on the JIRA Agile boards API, refreshing the menu every 30 seconds. My original approach was a naive:
@rumps.timer(30)
def update_menu(_):
m = generate_menu()
app.menu.clear()
app.menu = m
this worked great, except that it seemed to be leaking a lot of memory. Digging in, it doesn't look like when the Python MenuItem
object is deleted, the corresponding Cocoa NSMenu
/NSMenuItem
memory isn't released?
When using fileinput from library tkinter application crashes.
Using python3.6
macOS 10.12.6
Code:
def __init__(self):
...
tk.Tk().withdraw()
@rumps.clicked("Settings")
def settings(self, _):
file_path = filedialog.askdirectory()
if self.def_wallpaper != file_path:
self.def_wallpaper = file_path
self.editor.set_loading_dir(self.def_wallpaper)
Quit application
Fatal Python error: PyEval_RestoreThread: NULL tstate
Current thread 0x00007ffff45d43c0 (most recent call first):
File "/usr/local/lib/python3.6/site-packages/PyObjCTools/AppHelper.py", line 301 in runEventLoop
File "/usr/local/lib/python3.6/site-packages/rumps/rumps.py", line 1156 in run
File "menu.py", line 84 in <module>
fish: Job 2, 'python3 menu.py' terminated by signal SIGABRT (Abort)
When I builded application:
from menu import Bar
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "menu.pyc", line 10, in <module>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "tkinter/__init__.pyc", line 36, in <module>
ValueError: character U+6573552f is not in range [U+0000; U+10ffff]
Firstly, thank you for building this amazing library. It's been a huge help to be able to build my app!
Now onto the issue. Before I spent the last month building my app, I tested your example code and saw the notification but it would only show once, or it was very intermittent. I'd like to use the feature for my app also for scenarios where alerts are too much, however it's just not working.
I've setup multiple menu items and each one of them is meant to call rumps.notification. Yet, they either never work, or one will work and the rest won't. I've been unable to find the cause.
Compiled and ran the app from example directory, and app crashed. Here is message from Console Log.
Please let me know if you need any help.
2/19/14 2:25:13.897 PM WindowServer[110]: CGXSetWindowListSystemAlpha: Invalid window 3715 (index 0/1)
2/19/14 2:25:13.919 PM example_class[2515]: Traceback (most recent call last):
2/19/14 2:25:13.919 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/__boot__.py", line 341, in <module>
2/19/14 2:25:13.920 PM example_class[2515]: _run()
2/19/14 2:25:13.920 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/__boot__.py", line 336, in _run
2/19/14 2:25:13.920 PM example_class[2515]: exec(compile(source, path, 'exec'), globals(), globals())
2/19/14 2:25:13.920 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/example_class.py", line 21, in <module>
2/19/14 2:25:13.920 PM example_class[2515]: AwesomeStatusBarApp().run()
2/19/14 2:25:13.922 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/lib/python2.7/rumps/rumps.py", line 699, in run
2/19/14 2:25:13.922 PM example_class[2515]: b(self) # we waited on registering clicks so we could pass self to access _menu attribute
2/19/14 2:25:13.922 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/lib/python2.7/rumps/rumps.py", line 150, in register_click
2/19/14 2:25:13.923 PM example_class[2515]: menuitem.set_callback(f)
2/19/14 2:25:13.923 PM example_class[2515]: File "/Users/live/Desktop/ObjectiveC/src/rumps/examples/dist/example_class.app/Contents/Resources/lib/python2.7/rumps/rumps.py", line 396, in set_callback
2/19/14 2:25:13.923 PM example_class[2515]: self._menuitem.setTarget_(type(self))
2/19/14 2:25:13.923 PM example_class[2515]: ValueError: NSInvalidArgumentException - Class OC_PythonObject: no such selector: methodForSelector:
2/19/14 2:25:14.002 PM example_class[2515]: example_class Error
2/19/14 2:25:14.003 PM example_class[2515]: 2014-02-19 14:25:14.001 example_class[2515:707] example_class Error
2/19/14 2:25:17.366 PM com.apple.launchd.peruser.501[232]: (org.pythonmac.unspecified.example_class.126224[2515]) Exited with code: 255
OS: 10.8.4
Python 2.7.5
Issue is whenever you compile the app to distribute in py2app it'll crash on launch even if it works fine in alias mode.
Resolve it by:
sudo mkdir -p /usr/include/python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/Current/include/python2.7/pyconfig.h /usr/include/python2.7/pyconfig.h
Is it possible to have a rumps menu item start on user login?
I would like to set a default icon size somehow. I'd suggest one of or both of the following, though I don't really care how it's done.
RumpsApp(debug=True, icon_size=(16, 16)).run()
rumps.set_default_icon_size((16, 16))
It would just be nice to be able to get away from the pattern I'm following right now, which is
self.menu['My Menu'].set_icon('png/an_icon.png', DEFAULT_ICON_SIZE)
Hey! Thanks for this tool, it looks great and I would like to use it. Would you mind putting it up on the Python package index so we can install it with pip install rumps
?
The current version on PyPI (rumps==0.2.1a0) does not reflect the latest version with Python 3 support available on this repo. The version number appears to be the same as installing from source with python setup.py install
(0.2.1a0), but they're not.
Hi,
I am using rumps for a toolbar app. Works great in 10.8, but I am getting the error below in 10.9 for the same project code. The messages imply that it is related to assigning the click events to the menu items.
Humberto
This is a link to the tool bar app main file
https://gist.github.com/humbertoroa/2e79633727ec4b61567e
Error Text
File "/Users/humberto/git/git-python/tool-bar-app/centric8toolbar.py", line 79, in app.run()
File "/Users/humberto/git/git-python/tool-bar-app/rumps/rumps.py", line 699, in run
b(self) # we waited on registering clicks so we could pass self to access _menu attribute
File "/Users/humberto/git/git-python/tool-bar-app/rumps/rumps.py", line 150, in register_click
menuitem.set_callback(f)
File "/Users/humberto/git/git-python/tool-bar-app/rumps/rumps.py", line 396, in set_callback
self.menuitem.setTarget(type(self))
ValueError: NSInvalidArgumentException - Class OC_PythonObject: no such selector: methodForSelector:
pasting text with keyboard shortcut (cmd-V) into a window is not possible now, for reasons explained here:
http://stackoverflow.com/questions/970707/cocoa-keyboard-shortcuts-in-dialog-without-an-edit-menu
(there is also a workaround here).
When starting example_simple.py, I get the following error (stack trace):
"Traceback (most recent call last):
File "example_simple.py", line 47, in
rumps.MenuItem('About', icon='pony.jpg', dimensions=(18, 18)), # can specify an icon to be placed near text
File "/Library/Python/2.7/site-packages/rumps/rumps.py", line 205, in init
self.set_icon(icon, dimensions)
File "/Library/Python/2.7/site-packages/rumps/rumps.py", line 250, in set_icon
image = _nsimage_from_file(icon_path, dimensions)
File "/Library/Python/2.7/site-packages/rumps/rumps.py", line 102, in _nsimage_from_file
from Foundation import NSImage # import problem with NSImage; don't want to import it until here
ImportError: cannot import name NSImage"
This can be fixed by importing NSImage from "AppKit" instead of "Foundation".
My system specifications:
System Version: OS X 10.8.4 (12E55)
Kernel Version: Darwin 12.4.0
Python 2.7.2
Model Identifier: MacBookPro6,2
from rumps import *
@clicked('Testing')
def tester(sender):
sender.state = not sender.state
sender.add('test submenu')
class SomeApp(rumps.App):
def __init__(self):
super(SomeApp, self).__init__(type(self).__name__, menu=['Testing', 'On'])
rumps.debug_mode(True)
@clicked('On')
def button(self, sender):
sender.title = 'Off' if sender.title == 'On' else 'On'
Window("I can't think of a good example app...").run()
if __name__ == "__main__":
SomeApp().run()
I am able to add a submenu to the "Testing" menu when Testing is clicked by using the menu instance from "sender" variable but how do I add submenus and windows to the submenus during init?
When I try to declare an App using python 3, an exception is thrown because of the function _require_string.
145 def _require_string(*objs):
146 for obj in objs:
--> 147 if not isinstance(obj, basestring):
148 raise TypeError('a string is required but given {0}, a {1}'.format(obj, type(obj).__name__))
149
NameError: name 'basestring' is not defined
I have made some code to fix the issue here: #58
I'm having trouble figuring out how to change or access the existing menu items when the timer triggers. Can someone provide a small example?
When I try to run the example menu bar app in a thread, I get an endless stream of this
2014-10-28 05:50:37.168 python[13952:248458] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1151.16/Misc.subproj/NSUndoManager.m:340
2014-10-28 05:50:37.168 python[13952:248458] NSInternalInconsistencyException - +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2014-10-28 05:50:37.169 python[13952:248458] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1151.16/Misc.subproj/NSUndoManager.m:340
2014-10-28 05:50:37.169 python[13952:248458] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2014-10-28 05:50:37.169 python[13952:248458] (
0 CoreFoundation 0x00007fff9b82764c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8d7bb6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff9b82742a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff99ddd5b9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 Foundation 0x00007fff99d4efef +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
5 AppKit 0x00007fff8cc82015 -[NSApplication run] + 756
6 _objc.so 0x000000010c0c0907 ffi_call_unix64 + 79
7 ??? 0x000000010e0c25c0 0x0 + 4530644416
)
until I force quit. Here's the code:
class AppThread(Thread):
def __init__(self, *args, **kwargs):
super(AppThread, self).__init__(*args, **kwargs)
self.start()
def run(self):
AwesomeStatusBarApp().run()
app_thread = AppThread()
Is this a limitation of pyobjc or a problem with rumps?
I've been trying to get one of the example programs working (the "AwesomeStatusBar" example found here). The app will open up and display the menu, but trying to click "Preferences", "Silly button", and "Say hi" all throw an "uncaught exception" error. "Quit" works like a charm, though.
Full error is:
2016-08-23 21:07:24.298 python3[30761:419083] <MenuItem: ['Preferences' -> <map object at 0x1064d7ef0>; callback: <function AwesomeStatusBarApp.prefs at 0x1064e39d8>]>
2016-08-23 21:07:24.299 python3[30761:419083] An uncaught exception was raised
2016-08-23 21:07:24.299 python3[30761:419083] <class 'AttributeError'>: 'TypeError' object has no attribute 'message'
2016-08-23 21:07:24.306 python3[30761:419083] (
0 CoreFoundation 0x00007fff9353b4f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff91986f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff9353b439 -[NSException raise] + 9
3 _objc.cpython-35m-darwin.so 0x0000000102dac71e PyObjCErr_ToObjCWithGILState + 46
4 _objc.cpython-35m-darwin.so 0x0000000102d955be method_stub + 5118
5 _objc.cpython-35m-darwin.so 0x0000000102dc12d2 ffi_closure_unix64_inner + 658
6 _objc.cpython-35m-darwin.so 0x0000000102dc0816 ffi_closure_unix64 + 70
7 AppKit 0x00007fff9299fdbd -[NSApplication sendAction:to:from:] + 460
8 AppKit 0x00007fff9299fb57 -[NSMenuItem _corePerformAction] + 336
9 AppKit 0x00007fff9299f8b7 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
10 libsystem_trace.dylib 0x00007fff951e807a _os_activity_initiate + 75
11 AppKit 0x00007fff92a31e54 -[NSMenu performActionForItemAtIndex:] + 131
12 AppKit 0x00007fff92a31dc7 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
13 AppKit 0x00007fff92a31c1f -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 107
14 AppKit 0x00007fff928d6fd9 NSSLMMenuEventHandler + 708
15 HIToolbox 0x00007fff960707be _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1231
16 HIToolbox 0x00007fff9606fc48 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 404
17 HIToolbox 0x00007fff960859e6 SendEventToEventTarget + 40
18 HIToolbox 0x00007fff960cf99a _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 411
19 HIToolbox 0x00007fff960fad5b SendMenuCommandWithContextAndModifiers + 59
20 HIToolbox 0x00007fff960fad0c SendMenuItemSelectedEvent + 188
21 HIToolbox 0x00007fff960fabe8 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 96
22 HIToolbox 0x00007fff960d9b81 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK14__CFDictionaryPK10__CFStringPP13OpaqueMenuRefPt + 1794
23 HIToolbox 0x00007fff960d8c5c _ZL26_HandlePopUpMenuSelection8P13OpaqueMenuRefP14OpaqueEventRefj5PointtjPK4RecttS6_S6_PK14__CFDictionaryPK10__CFStringPS0_Pt + 610
24 HIToolbox 0x00007fff960d8853 _HandlePopUpMenuSelectionWithDictionary + 287
25 AppKit 0x00007fff92a28c6c _NSSLMPopUpCarbonMenu3 + 6168
26 AppKit 0x00007fff92a27442 _NSPopUpCarbonMenu3 + 153
27 AppKit 0x00007fff92a2739a -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 356
28 AppKit 0x00007fff92e0eef9 +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 705
29 AppKit 0x00007fff92e0e32b -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 159
30 AppKit 0x00007fff929aeae8 -[NSControl mouseDown:] + 669
31 AppKit 0x00007fff92f033c9 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
32 AppKit 0x00007fff92f043ad -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
33 AppKit 0x00007fff92943539 -[NSWindow sendEvent:] + 517
34 AppKit 0x00007fff92e11849 -[NSStatusBarWindow sendEvent:] + 281
35 AppKit 0x00007fff928c3a38 -[NSApplication sendEvent:] + 2540
36 AppKit 0x00007fff9272adf2 -[NSApplication run] + 796
37 _objc.cpython-35m-darwin.so 0x0000000102dc0697 ffi_call_unix64 + 79
38 ??? 0x00007fff5d6025a0 0x0 + 140734759970208
)
2016-08-23 21:07:28.928 python3[30761:419083] <MenuItem: ['Quit' -> <map object at 0x1064d7f98>; callback: <function quit_application at 0x1064dcd08>]>
2016-08-23 21:07:28.928 python3[30761:419083] closing application
Python 3.5.2
Rumps 0.2.1 (installed via pip3 into a virtual environment)
PyObjC 3.1.1 (via pip3 in a VE)
Mac OS X 10.11.6 (El Capitan)
Feel like it's probably my fault, but can't for the life of me figure out what the cause is or how to fix it.
I'm using Python3 and installed rumps via pip3 but I get the no module named 'rumps' error.
Someone has an idea?
I tested the simple example in readme. It seems the notification does not work in my mac.
I got the following error, while trying to display the word "Pokémon®" in a rumps app:
2015-02-25 16:01:37.003 Python[36982:781751] <type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc2 in position 28: ordinal not in range(128)
2015-02-25 16:01:37.004 Python[36982:781751] (
0 CoreFoundation 0x00007fff8ba1866c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8f18876e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ba18209 -[NSException raise] + 9
3 _objc.so 0x000000010710f3fe PyObjCErr_ToObjCWithGILState + 46
4 _objc.so 0x0000000107117030 -[OC_PythonObject forwardInvocation:] + 784
5 CoreFoundation 0x00007fff8b9628a6 ___forwarding___ + 518
6 CoreFoundation 0x00007fff8b962618 _CF_forwarding_prep_0 + 120
7 Foundation 0x00007fff875e2db3 __NSFireTimer + 95
8 CoreFoundation 0x00007fff8b96bb64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
9 CoreFoundation 0x00007fff8b96b7f3 __CFRunLoopDoTimer + 1059
10 CoreFoundation 0x00007fff8b9dedbd __CFRunLoopDoTimers + 301
11 CoreFoundation 0x00007fff8b928288 __CFRunLoopRun + 2024
12 CoreFoundation 0x00007fff8b927858 CFRunLoopRunSpecific + 296
13 HIToolbox 0x00007fff954dbaef RunCurrentEventLoopInMode + 235
14 HIToolbox 0x00007fff954db76e ReceiveNextEventCommon + 179
15 HIToolbox 0x00007fff954db6ab _BlockUntilNextEventMatchingListInModeWithFilter + 71
16 AppKit 0x00007fff88642f81 _DPSNextEvent + 964
17 AppKit 0x00007fff88642730 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
18 AppKit 0x00007fff88636593 -[NSApplication run] + 594
19 _objc.so 0x0000000107124797 ffi_call_unix64 + 79
20 ??? 0x00007fff58ee0490 0x0 + 140734685381776
)
Process finished with exit code 137
Is this something you can do anything about?
(PS, rumps is AMAZING! I can't believe I could get a full program working in like, two hours with config and options and everything so easily!)
If you create a (transparent) dark/black menu-bar icon, which will look decent in the default (light) os x menu bar theme, it will not/barely be visible when using a dark menu bar. (The same is true, when using a light/white menu bar icon on the light theme).
OS X has a fix for this and in Swift
it looks something like this:
var icon = NSImage(named: "menu-bar")
icon?.setTemplate(true)
I assume this could be done in the set_icon
method, but I am not sure how to do that through python - any idea?
It would probably go here: https://github.com/jaredks/rumps/blob/master/rumps/rumps.py#L513
I'm not sure if this is an issue with rumps, or just with what I'm trying to do with it.
But here's a snippet of my app:
commands = OrderedDict([
('Play', ('play', 'play39.png')),
('Pause', ('pause', 'pause14.png')),
('Play / Pause', ('playpause', 'play40.png')),
('Next track', ('next track', 'step.png')),
('Previous track', ('previous track', 'step1.png')),
])
def _run_osascript(command, application='Spotify'):
return subprocess.check_output([
'osascript', '-e',
'if application "{0}" is running then tell application "{0}" to {1}'.format(application, command)
]).strip()
self.menu = [rumps.MenuItem(title, icon=os.path.join('png', action[1]), dimensions=DEFAULT_ICON_SIZE,
callback=lambda x: self._run_osascript(action)) for title, action in commands.iteritems()]
The problem is that for every command that is added to the menu, they all have the correct label from the commands
dictionary, but they all execute the lambda that was generated for the last command added. Thus, clicking any of them executes the applescript to tell Spotify to go the previous track.
my application rebuilds menu each two seconds (i need to display some changing progress percentage in first menu item).
this approach works if user didn't open menu by clicking on application in statusbar
but if menu changed while it's opened by user - python crashes with following backtrace:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff8dc920dd objc_msgSend + 29
1 com.apple.HIToolbox 0x00007fff95bdd8e5 ZN18HIStandardMenuView8DrawSelfEsPK9__HIShapeP9CGContext_block_invoke + 39
2 com.apple.HIToolbox 0x00007fff95bc09c7 HIStandardMenuView::DrawSelf(short, HIShape const, CGContext) + 975
3 com.apple.HIToolbox 0x00007fff95b6057d HIView::DrawCacheOrSelf(short, HIShape const, CGContext) + 343
4 com.apple.HIToolbox 0x00007fff95b603e6 HIView::SendDraw(short, OpaqueGrafPtr, HIShape const, CGContext) + 382
5 com.apple.HIToolbox 0x00007fff95b5fd42 HIView::RecursiveDrawComposited(HIShape const, HIShape const, unsigned int, HIView, CGContext, unsigned char, double) + 710
6 com.apple.HIToolbox 0x00007fff95b5ffbe HIView::RecursiveDrawComposited(HIShape const, HIShape const, unsigned int, HIView, CGContext, unsigned char, double) + 1346
7 com.apple.HIToolbox 0x00007fff95b5ffbe HIView::RecursiveDrawComposited(HIShape const, HIShape const, unsigned int, HIView, CGContext, unsigned char, double) + 1346
8 com.apple.HIToolbox 0x00007fff95b5ecdb HIView::DrawComposited(short, OpaqueGrafPtr, HIShape const, unsigned int, HIView, CGContext) + 965
9 com.apple.HIToolbox 0x00007fff95b5e904 HIView::Render(unsigned int, CGContext_) + 54
10 com.apple.HIToolbox 0x00007fff95b6ca7c FlushWindowObject(WindowData_, void__, unsigned char) + 763
11 com.apple.HIToolbox 0x00007fff95b76114 FlushAllBuffers(CFRunLoopObserver, unsigned long, void*) + 228
12 com.apple.CoreFoundation 0x00007fff8e703127 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
13 com.apple.CoreFoundation 0x00007fff8e703080 CFRunLoopDoObservers + 368
14 com.apple.CoreFoundation 0x00007fff8e6f4bbf CFRunLoopRunSpecific + 271
15 com.apple.HIToolbox 0x00007fff95b6e56f RunCurrentEventLoopInMode + 235
16 com.apple.HIToolbox 0x00007fff95b6e2ea ReceiveNextEventCommon + 431
17 com.apple.HIToolbox 0x00007fff95bc768a AcquireNextEventInMode + 54
18 com.apple.HIToolbox 0x00007fff95bc4e2b IsUserStillTracking(MenuSelectData, unsigned char) + 173
19 com.apple.HIToolbox 0x00007fff95bc4a41 TrackMenuCommon(MenuSelectData&, unsigned char) + 1661
20 com.apple.HIToolbox 0x00007fff95badbf2 PopUpMenuSelectCore(MenuData_, Point, double, Point, unsigned short, unsigned int, Rect const_, unsigned short, unsigned int, Rect const_, Rect const_, CFDictionary const, CFString const, OpaqueMenuRef, unsigned short_) + 1670
21 com.apple.HIToolbox 0x00007fff95bacd74 HandlePopUpMenuSelection8(OpaqueMenuRef, OpaqueEventRef_, unsigned int, Point, unsigned short, unsigned int, Rect const_, unsigned short, Rect const_, Rect const_, CFDictionary const, CFString const, OpaqueMenuRef, unsigned short_) + 633
22 com.apple.HIToolbox 0x00007fff95bac93b _HandlePopUpMenuSelectionWithDictionary + 287
23 com.apple.AppKit 0x00007fff9093c71d _NSSLMPopUpCarbonMenu3 + 5810
24 com.apple.AppKit 0x00007fff9093b059 _NSPopUpCarbonMenu3 + 153
25 com.apple.AppKit 0x00007fff9093afb1 -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 350
26 com.apple.AppKit 0x00007fff90d14448 +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 682
27 com.apple.AppKit 0x00007fff90d1387d -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 159
28 com.apple.AppKit 0x00007fff90892366 -[NSControl mouseDown:] + 714
29 com.apple.AppKit 0x00007fff90dfc2dc -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125
30 com.apple.AppKit 0x00007fff9078bc86 -[NSWindow sendEvent:] + 470
31 com.apple.AppKit 0x00007fff90d16dee -[NSStatusBarWindow sendEvent:] + 242
32 com.apple.AppKit 0x00007fff90788212 -[NSApplication sendEvent:] + 2504
33 com.apple.AppKit 0x00007fff906b1b68 -[NSApplication run] + 711
34 libffi.dylib 0x00007fff9b3c5f44 ffi_call_unix64 + 76
35 libffi.dylib 0x00007fff9b3c6781 ffi_call + 853
36 _objc.so 0x0000000109f3dacb PyObjCFFI_Caller + 2321
37 _objc.so 0x0000000109f50a2b 0x109f23000 + 186923
38 org.python.python 0x000000010915c50a PyObject_Call + 99
39 org.python.python 0x00000001091d9399 PyEval_EvalFrameEx + 11795
40 org.python.python 0x00000001091d6352 PyEval_EvalCodeEx + 1409
41 org.python.python 0x00000001091dcbf1 0x109152000 + 568305
42 org.python.python 0x00000001091d99a6 PyEval_EvalFrameEx + 13344
43 org.python.python 0x00000001091d6352 PyEval_EvalCodeEx + 1409
44 org.python.python 0x00000001091dcbf1 0x109152000 + 568305
45 org.python.python 0x00000001091d99a6 PyEval_EvalFrameEx + 13344
46 org.python.python 0x00000001091d6352 PyEval_EvalCodeEx + 1409
47 org.python.python 0x00000001091d5dcb PyEval_EvalCode + 54
48 org.python.python 0x00000001091f600e 0x109152000 + 671758
49 org.python.python 0x00000001091f60b1 PyRun_FileExFlags + 133
50 org.python.python 0x00000001091f5c4e PyRun_SimpleFileExFlags + 769
51 org.python.python 0x0000000109207437 Py_Main + 3051
52 libdyld.dylib 0x00007fff8f0d65c9 start + 1
Sorry if this is a really silly question, but I'm looking to write a little application that periodically updates it's title in the status bar. The App.title(self, new_title) function appears to be exactly what I'm looking for, however I can't get it to work right. Here is a tiny mockup of my code:
import rumps
class AwesomeStatusBarApp(rumps.App):
def __init__(self):
super(AwesomeStatusBarApp, self).__init__("Awesome App")
self.menu = ["updating"]
@rumps.timer(1)
def sayhi(self, _):
super(AwesomeStatusBarApp, self).title(self,"Hi")
if __name__ == "__main__":
AwesomeStatusBarApp().run()
However whenever I run this code I get the following error:
2014-06-17 11:27:24.676 Python[87027:1107] <type 'exceptions.TypeError'>: 'NoneType' object is not callable
2014-06-17 11:27:24.677 Python[87027:1107] (
0 CoreFoundation 0x00007fff9220025c exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8b096e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff921ffe09 -[NSException raise] + 9
3 _objc.so 0x000000010e478fbf _objc.so + 28607
4 CoreFoundation 0x00007fff9215e0f4 __forwarding + 452
5 CoreFoundation 0x00007fff9215dea8 _CF_forwarding_prep_0 + 120
6 Foundation 0x00007fff962c50f4 __NSFireTimer + 96
7 CoreFoundation 0x00007fff92167494 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20
8 CoreFoundation 0x00007fff92166fcf __CFRunLoopDoTimer + 1151
9 CoreFoundation 0x00007fff921d85aa __CFRunLoopDoTimers + 298
10 CoreFoundation 0x00007fff92122755 __CFRunLoopRun + 1525
11 CoreFoundation 0x00007fff92121f25 CFRunLoopRunSpecific + 309
12 HIToolbox 0x00007fff96e52a0d RunCurrentEventLoopInMode + 226
13 HIToolbox 0x00007fff96e527b7 ReceiveNextEventCommon + 479
14 HIToolbox 0x00007fff96e525bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
15 AppKit 0x00007fff8e48226e _DPSNextEvent + 1434
16 AppKit 0x00007fff8e4818bb -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
17 AppKit 0x00007fff8e4759bc -[NSApplication run] + 553
18 libffi.dylib 0x00007fff93e92f9c ffi_call_unix64 + 76
19 ??? 0x00007fa084c3a5f0 0x0 + 140327398909424
Which is odd. The super call in the init function appears to work fine, however it gets some sort of NoneType error when I try and call it in a function. Is this an error? is there something more subtle going on here that I've messed up?
This happened after upgrading OS X.
Traceback (most recent call last):
File "<Application Path>", line 389, in <module>
main(headless=args.headless)
File "<Application Path>", line 374, in main
menu=(summary, refresh, None))
File "/Library/Python/2.7/site-packages/rumps/rumps.py", line 628, in __init__
self._application_support = application_support(self._name)
File "/Library/Python/2.7/site-packages/rumps/rumps.py", line 85, in application_support
os.mkdir(app_support_path)
OSError: [Errno 2] No such file or directory: '/var/root/Library/Application Support/<Application Name>'
When trying to run any of the examples, I'm running into this error:
Traceback (most recent call last):
File "queue_client.py", line 57, in
app.run()
File "/Users/danielschales/Envs/queue_client/lib/python2.7/site-packages/rumps/rumps.py", line 703, in run
NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self.nsapp)
AttributeError: 'NoneType' object has no attribute 'setDelegate'
This is on a fresh install of Mavericks 10.9.1, using Homebrew installed Python 2.7.6, and installed PyObjC using pip all in a virtualenv. Using tito's fork as well as the official rumps repo. It was working in my previous Mavericks installation, but the system Python install was a mess, hence the reinstall and usage of a virtualenv this time around.
gubatrons-macbook-pro-3:OpenBazaar gubatron$ pip install rumps
Downloading/unpacking rumps
Downloading rumps-0.2.0.tar.gz
Running setup.py (path:/private/var/folders/lw/hr00_r6j0xjdz481gq373tbc0000gn/T/pip_build_gubatron/rumps/setup.py) egg_info for package rumps
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/var/folders/lw/hr00_r6j0xjdz481gq373tbc0000gn/T/pip_build_gubatron/rumps/setup.py", line 3, in <module>
import rumps
File "rumps/__init__.py", line 25, in <module>
from .rumps import (separator, debug_mode, alert, notification, application_support, timers, quit_application, timer,
File "rumps/rumps.py", line 15, in <module>
from Foundation import (NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSSearchPathForDirectoriesInDomains,
ImportError: No module named Foundation
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/var/folders/lw/hr00_r6j0xjdz481gq373tbc0000gn/T/pip_build_gubatron/rumps/setup.py", line 3, in <module>
import rumps
File "rumps/__init__.py", line 25, in <module>
from .rumps import (separator, debug_mode, alert, notification, application_support, timers, quit_application, timer,
File "rumps/rumps.py", line 15, in <module>
from Foundation import (NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSSearchPathForDirectoriesInDomains,
ImportError: No module named Foundation
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /private/var/folders/lw/hr00_r6j0xjdz481gq373tbc0000gn/T/pip_build_gubatron/rumps
Storing debug log for failure in /Users/gubatron/.pip/pip.log
I get this error while trying to run example_windows.py
Traceback (most recent call last):
File "example_windows.py", line 1, in
import rumps
ImportError: No module named rumps
I have done python setup.py install in the directory example before running it.
When I try to run python setup.py install in rumps-master directory I get this error :
Traceback (most recent call last):
File "setup.py", line 3, in
import rumps
File "/Users/iAkim/Downloads/rumps-master/rumps/init.py", line 40, in
from .rumps import (separator, debug_mode, alert, notification, application_support, timers, timer, clicked,
File "/Users/iAkim/Downloads/rumps-master/rumps/rumps.py", line 8, in
from Foundation import (NSUserNotification, NSUserNotificationCenter, NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode,
ImportError: No module named Foundation
If I open a python shell I can't import rumps so I guess I haven't installed but how do I install it ?
I have problem installing pyobjc because it can't find a working compiler, I guess it's related because rumps use pyobjc.
Mac config : OS X 10.9.2
Is it possible to have a super simple app that has no menu items? Just the tex/icon in the statusbar, and then events fire when that is clicked? I don't see this in the example, nor a way to decorate something other than a menu item.
It'll be nice to have icon support in the notifications that show up.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.