Closed kendonB closed 4 years ago
Ok funccontext was not it. This seems to work. Is this right?
class LinuxContext(Context):
def __init__(self):
self._str = "Test for linux"
def matches(self, executable, title, handle):
return sys.platform == "linux"
Hi @kendonB. It's good you're working on cross-platforming Caster.
Your Context
class should work I think. You can do platform contexts with FuncContext
like this:
import os
import sys
from dragonfly import FuncContext
windows_context = FuncContext(lambda: sys.platform == "win32")
darwin_context = FuncContext(lambda: sys.platform == "darwin") # Darwin == MacOS
linux_context = FuncContext(lambda: sys.platform.startswith("linux"))
x11_context = FuncContext(lambda: os.environ.get("XDG_SESSION_TYPE") == "x11")
As for the slightly different key combinations, this has come up before in this discussion in the Caster gitter channel involving @amatveie, @LexiconCode and myself. Implementing an extensible way of solving this problem is quite complicated, as cross-platform support usually is. I have some notes on it, but I can't really commit to developing it myself. I'll try to put my notes up here soon.
Those commands above will work fine - will close. Thanks!
I'm starting to do some cross platforming for Caster. There are many places where the same action just has a slightly different key combination depending on the platform. Something like
WindowsContext
,MacOSContext
, andLinuxContext
functions would be really helpful. I've been trying to write these based onFuncContext
andsys.platform == "win32"
,sys.platform == "darwin"
andsys.platform == "linux"
but haven't figured it out. Any help?