Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write a FilePickerCtrl component #11

Closed
jamesdbrock opened this issue Sep 27, 2022 · 4 comments · Fixed by #12
Closed

write a FilePickerCtrl component #11

jamesdbrock opened this issue Sep 27, 2022 · 4 comments · Fixed by #12

Comments

@jamesdbrock
Copy link
Collaborator

I want to write a FilePickerCtrl component. Any advice?

It seems like writing new primitive components is a bit awkward because the re.widgets.set_basic_props function has no way to amend the exclusions map. So I have to either fork re-wx or make a new set_basic_props function. Do I have that right?

@jamesdbrock
Copy link
Collaborator Author

Ah, actually, the only way to add new primitive components is to fork the re-wx repo, right? Because core.py gets the mount and update decorator registries from widgets.py.

@jamesdbrock
Copy link
Collaborator Author

I take it back, the @mount.register and @update.register decorators work anywhere in user code.

@jamesdbrock
Copy link
Collaborator Author

I'm pretty sure this is essentially an implementation of Haskell or PureScript “typeclasses” in Python.

def dispatch(func):
"""
Constructs a registry for performing single dispatch based on
the class (not instance) type
"""

@chriskiehl
Copy link
Owner

I take it back, the @mount.register and @update.register decorators work anywhere in user code.

Yeah, correct. You can see a few examples of it in use in Gooey.

I'm pretty sure this is essentially an implementation of Haskell or PureScript “typeclasses” in Python.

Oh, interesting. I hadn't thought of it that way. The motivation here was primarily multi-methods from Clojure. They're definitely clumsier than typeclasses because of how Python treats its objects. There's actually a builtin version of this dispatch thing in functools called @singledispatch. However, it only works correctly for instances of types, which have the Type you'd expect (int, string, MyObject, etc..) whereas the type of a class, is type (which I think is sort of like Kind in Purecsript).

class Foo:
    pass  

print(type(Foo())  # <class '__main__.Foo'>
print(type(Foo))   # <class 'type'>

This quirk breaks the builtin singledispatch because everything bottoms out on Type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants