Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BringFileman: Dragonfly BringApp subclass for file manager applications.
import os
from dragonfly.actions.action_startapp import BringApp
class BringFileman(BringApp):
"""
Dragonfly BringApp subclass for file manager applications.
Explorer.exe usage examples::
BringFileman("explorer.exe")
BringFileman("explorer.exe", r"C:\Windows")
BringFileman("explorer.exe", "/select,", r"C:\Windows\explorer.exe")
"""
# Define acceptable window class names for each file manager.
_fileman_classes = {
"explorer": ("ExplorerWClass", "CabinetWClass"),
}
def __init__(self, *args, **kwargs):
# If the *title* argument has not been specified, then handle
# additional file manager arguments by setting the matching title
# to the name of the directory, assuming the last argument is the
# specified object.
if len(args) > 1 and "title" not in kwargs:
last_argument = args[len(args) - 1]
if os.path.isdir(last_argument):
dirname = last_argument
else:
dirname = os.path.dirname(last_argument)
kwargs["title"] = os.path.basename(dirname)
# If the *filter_func* argument has not been specified, then use it
# to filter out windows with class names other than those specified
# in *_fileman_classes*, if any.
executable = os.path.basename(args[0])
fileman = os.path.splitext(executable)[0]
fileman_classes = self._fileman_classes.get(fileman)
if fileman_classes and "filter_func" not in kwargs:
kwargs["filter_func"] = lambda w: w.classname in fileman_classes
BringApp.__init__(self, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment