### Install Rumps from Source Source: https://github.com/jaredks/rumps/blob/master/README.rst Command to install the Rumps library directly from its source code using setup.py. This may be useful for development or specific installation needs. ```bash python setup.py install ``` -------------------------------- ### Install Rumps using pip Source: https://github.com/jaredks/rumps/blob/master/README.rst Standard command to install the Rumps library using pip. This is the recommended method for most users. ```bash pip install rumps ``` -------------------------------- ### Create a Basic Rumps Status Bar App Source: https://github.com/jaredks/rumps/blob/master/README.rst This is a foundational example demonstrating how to create a simple status bar application with Rumps. It includes basic event handling for button clicks and displaying notifications. ```python import rumps class AwesomeStatusBarApp(rumps.App): @rumps.clicked("Preferences") def prefs(self, _): rumps.alert("jk! no preferences available!") @rumps.clicked("Silly button") def onoff(self, sender): sender.state = not sender.state @rumps.clicked("Say hi") def sayhi(self, _): rumps.notification("Awesome title", "amazing subtitle", "hi!!1") if __name__ == "__main__": AwesomeStatusBarApp("Awesome App").run() ``` -------------------------------- ### Run Executable from .app Bundle Source: https://github.com/jaredks/rumps/blob/master/docs/debugging.md To view debug messages from a .app bundle generated by py2app, do not use 'open'. Instead, navigate to the executable within the bundle. This example assumes the .app is in the current directory. ```bash ./{your app name}.app/Contents/MacOS/{your app name} ``` -------------------------------- ### Basic setup.py for Standalone App Source: https://github.com/jaredks/rumps/blob/master/docs/creating.md Configure `setup.py` to include `rumps` in packages and set `LSUIElement` to `True` for background applications. This is essential for creating dockless, non-tabbable status bar apps. ```python from setuptools import setup APP = ['example_class.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'plist': { 'LSUIElement': True, }, 'packages': ['rumps'], } setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) ``` -------------------------------- ### Create a Simple App with Subclassing Source: https://github.com/jaredks/rumps/blob/master/docs/examples.md Demonstrates creating a basic rumps application by subclassing rumps.App. Use this for standard menu-driven applications. ```python import rumps class AwesomeStatusBarApp(rumps.App): def __init__(self): super(AwesomeStatusBarApp, self).__init__("Awesome App") self.menu = ["Preferences", "Silly button", "Say hi"] @rumps.clicked("Preferences") def prefs(self, _): rumps.alert("jk! no preferences available!") @rumps.clicked("Silly button") def onoff(self, sender): sender.state = not sender.state @rumps.clicked("Say hi") def sayhi(self, _): rumps.notification("Awesome title", "amazing subtitle", "hi!!1") if __name__ == "__main__": AwesomeStatusBarApp().run() ``` -------------------------------- ### Build Standalone App with py2app Source: https://github.com/jaredks/rumps/blob/master/docs/creating.md Execute this command in your terminal after setting up your `setup.py` file to create the standalone application bundle. ```bash python setup.py py2app ``` -------------------------------- ### Run Executable from dist Folder Source: https://github.com/jaredks/rumps/blob/master/docs/debugging.md If your .app bundle is located in the 'dist' folder after running 'python setup.py py2app', use this command to run the executable and view debug messages. Replace {your app name} with your application's name. ```bash ./dist/{your app name}.app/Contents/MacOS/{your app name} ``` -------------------------------- ### Instantiate TextFieldMenuItem Directly Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md Use this method to create and configure a TextFieldMenuItem programmatically. Define initial values, placeholder text, and a callback function for handling user input. ```python import rumps class MyApp(rumps.App): def __init__(self): super(MyApp, self).__init__("My App") # Create a text field menu item self.search_field = rumps.TextFieldMenuItem( value='', placeholder='Search...', callback=self.on_search ) self.menu = ['Search', self.search_field] def on_search(self, sender): search_text = sender.value print(f"Search: {search_text}") ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/jaredks/rumps/blob/master/docs/debugging.md Import the rumps library and enable debug mode by setting it to True. This allows informational messages to be displayed. ```python import rumps rumps.debug_mode(True) ``` -------------------------------- ### Create a Virtual Environment with venv Source: https://github.com/jaredks/rumps/blob/master/README.rst Command to create a new virtual environment using Python's built-in venv module. This is recommended over virtualenv for Rumps due to potential compatibility issues. ```bash python3 -m venv env ``` -------------------------------- ### Run Application from Interpreter Source: https://github.com/jaredks/rumps/blob/master/docs/debugging.md Execute your Python application directly from the interpreter to see debug messages. Replace {your app name} with the actual name of your application file. ```bash python {your app name}.py ``` -------------------------------- ### New Features in Rumps 0.2.0 Source: https://github.com/jaredks/rumps/blob/master/docs/examples.md Demonstrates disabling menu items, `rumps.alert` with custom buttons, and custom quit button behavior. Ensure an alternative quit method if `quit_button` is set to `None`. ```python import rumps rumps.debug_mode(True) @rumps.clicked('Print Something') def print_something(_): rumps.alert(message='something', ok='YES!', cancel='NO!') @rumps.clicked('On/Off Test') def on_off_test(_): print_button = app.menu['Print Something'] if print_button.callback is None: print_button.set_callback(print_something) else: print_button.set_callback(None) @rumps.clicked('Clean Quit') def clean_up_before_quit(_): print 'execute clean up code' rumps.quit_application() app = rumps.App('Hallo Thar', menu=['Print Something', 'On/Off Test', 'Clean Quit'], quit_button=None) app.run() ``` -------------------------------- ### TextFieldMenuItem Methods Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md Provides methods to interact with the TextFieldMenuItem, such as setting callbacks. ```APIDOC ## TextFieldMenuItem Methods ### Methods - `set_callback(callback)`: Sets or changes the callback function for the text field. ``` -------------------------------- ### Decorate Functions with rumps.clicked Source: https://github.com/jaredks/rumps/blob/master/docs/examples.md Shows how to use the `rumps.clicked()` decorator on functions outside of an App subclass. The `sender` argument is passed correctly to all decorated functions. ```python from rumps import * @clicked('Testing') def tester(sender): sender.state = not sender.state class SomeApp(rumps.App): def __init__(self): super(SomeApp, self).__init__(type(self).__name__, menu=['On', 'Testing']) 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() ``` -------------------------------- ### TextFieldMenuItem Constructor Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md Instantiate a TextFieldMenuItem to add an editable text field to your rumps application's menu bar. ```APIDOC ## TextFieldMenuItem ### Description Creates a new menu item that embeds an NSTextField, allowing direct text input within a menu dropdown. ### Constructor Parameters - `value` (str): Initial text value for the field. Defaults to ''. - `placeholder` (str): Text displayed when the field is empty. Defaults to ''. - `callback` (callable): A function to be called when the text changes or Enter is pressed. Defaults to None. - `dimensions` (tuple): A tuple specifying the width and height of the text field in pixels (width, height). Defaults to (180, 22). - `margins` (tuple): A tuple specifying the left, top, right, and bottom margins in pixels (left, top, right, bottom). Defaults to (10, 4, 10, 4). ``` -------------------------------- ### TextFieldMenuItem Decorator Parameters Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md This snippet shows the parameters available for the @rumps.text_field decorator, including menu path, initial value, placeholder, callback, dimensions, and margins. ```python @rumps.text_field(*path, value='', placeholder='', callback=None, dimensions=(200, 24), margins=(15, 5, 15, 5)) def my_callback(self, sender): text = sender.value # Handle text change ``` -------------------------------- ### TextFieldMenuItem Properties Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md Access and modify the properties of a TextFieldMenuItem instance. ```APIDOC ## TextFieldMenuItem Properties ### Properties - `value` (str): Gets or sets the current text value of the text field. - `placeholder` (str): Gets or sets the placeholder text displayed when the field is empty. - `callback` (callable): Gets the current callback function associated with the text field. ``` -------------------------------- ### text_field Decorator Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md Use the text_field decorator to easily integrate editable text fields into your rumps application menu. ```APIDOC ## text_field Decorator ### Description Applies the text field functionality to a method, placing it within the application's menu structure. ### Parameters - `*path` (str): A variable number of string arguments defining the menu path where the text field will be created (e.g., 'Settings', 'User Info', 'Username'). - `value` (str): The initial text value for the text field. Defaults to ''. - `placeholder` (str): The placeholder text to display when the field is empty. Defaults to ''. - `callback` (callable): The callback function to execute when the text changes or Enter is pressed. If not provided, the decorated function will be used. Defaults to None. - `dimensions` (tuple): A tuple specifying the width and height of the text field in pixels (width, height). Defaults to (200, 24). - `margins` (tuple): A tuple specifying the left, top, right, and bottom margins in pixels (left, top, right, bottom). Defaults to (15, 5, 15, 5). ### Usage Example ```python @rumps.text_field('Settings', 'Username', value='admin', placeholder='Enter username') def on_username_changed(self, sender): username = sender.value print(f"Username: {username}") ``` ``` -------------------------------- ### Use text_field Decorator for Integration Source: https://github.com/jaredks/rumps/blob/master/docs/TextFieldMenuItem.md The @rumps.text_field decorator simplifies the integration of a TextFieldMenuItem into your application's menu structure. It automatically creates the menu item and links it to the decorated function, which acts as the callback. ```python import rumps class MyApp(rumps.App): @rumps.text_field('Settings', 'Username', value='admin', placeholder='Enter username') def on_username_changed(self, sender): username = sender.value print(f"Username: {username}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.