Package: hoptex
HoptexIf you are Vim user you heard aboutEasyMotionandHop. This library is exactly this concept but forTextual!
Just type your shortcut and focus/press widget you want. No mouse needed!Please always pin version of this library as API may change rapidly. It is experimental project and some staff may be modified.DemoInstallationJust simply install viapip:pip3installhoptexDocumentationHoptexallow to focus object and additionaly press it.
By default:spacewill highlightfocusablewidgets and allow to focus choosen onectrl+owill focus and press widgets that arefocusableand haveon_clickor_on_clickmethod.UsageThe most basic usage is just adding decorator on yourTextualapp like this:fromtextual.appimportAppfromhopteximporthoptex@hoptex()classNewTextualApp(App):...That is all. Super easy, right?Allow and Block listTo choose which widgets will be highlightedHoptexchecks for three condition:Widget have propertyfocusable=True.Widget is in allow list (then will be forced to be highlighted)Widget is in blocked list (it have priority to exclude widget over allow list)This parameters can be changed in@hoptexparameterfilter_listsusingHoptexFilterWidgetsConfig.
By defaultallow_listandblock_listare empty andinclude_focusable=True.
Example can be like this:fromtextual.demoimportDemoApp,LocationLink# Tested on Texutal 0.30.0 Demo Appfromtextual.widgetsimportTextLogfromhopteximporthoptexfromhoptex.configsimportHoptexWidgetsFiltersConfigwidgets_filters=HoptexWidgetsFiltersConfig(allow_list=[LocationLink],block_list=[TextLog])@hoptex(widgets_filters=widgets_filters)classWrappedDemoApp(DemoApp):...Custom bindingsIf you do not like default bindings you can change them withHoptexBindingConfig.
It has four fields, which you can replace with keybinding like inTextual:focus, default tospace-> RunHoptexscreen to focus widgetpress, default toctrl+p-> RunHoptexscreen to focus and press/click widgetquit, default toescape-> Quits fromHoptexscreenunfocus, default toescape-> Unfocuses from any widgets (if you are in e.x. text window, you need first to unfocus to usespace)and also four config fields, that takes dictionary that will be injected in standard Binding field:focus_conf, default to{"description": "Hop Focus"}press_conf, default to{"description": "Hop Press"}quit_conf, default to{"description": "Hop Quit", "show": False}unfocus_conf, default to{"description": "Hop Unfocus", "show": False}fromtextual.demoimportDemoAppfromhopteximporthoptexfromhoptex.configsimportHoptexBindingConfigbindings=HoptexBindingConfig(press="ctrl+g",press_conf={"description":"Another description"})@hoptex(bindings=bindings)classDemoAppMy(DemoApp):...Custom AppearanceYou can also inject custom label appearance, bylabelvalue. It should inherit fromStaticand allow for one argument (the letter that will be displayed).
However easier way is to change CSS ofHopLabel, which default is to:HopLabel{width:1;height:1;color:yellow;text-style:bold;background:black;}TODOSupport more widgets on screenAllow to use hoptex as wrapper for application (open any app with hoptex support)If no place to jump, returnColor changelist of characterscustom Widget to markhttps://github.com/python/typing/issues/213