Replies: 5 comments 4 replies
-
Have you tried py2hy? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Excellent! I knew about hy2py, but not py2hy. Oh! It's eight years old and
blows-up on build.
Almost every source recommends creating a sub-class; I am not convinced
that is the best way to handle this. The previous version of UIMessageBox
has a callback argument; that's all I want.
I found only one discussion
<https://stackoverflow.com/questions/394770/override-a-method-at-instance-level>
with an answer providing a way to replace a method of an instance; see
Harshal Dhumal's answer. Here is a working example.
import types
class Dog:
def bark(self):
print("Woof")
def new_bark(self):
print("Woof Woof")
fido = Dog()
fido.bark()
# replace bark with new_bark for this object only
fido.bark = types.MethodType(new_bark, fido)
fido.bark()
# make sure I replaced the method on the one instance
print("try a new dog")
bingo = Dog()
bingo.bark()
Here is the output.
Woof
Woof Woof
try a new dog
Woof
My code is now working ... well, this part is OK - there are other problems
:-)
(setv selection_msgbox (arcade.gui.UIMessageBox
:width 240
:height 130
:message_text "Hi! Who will be playing with James today?"
:buttons ["Daddy" "Mommy"]))
; replace the on_action method
;
(setv selection_msgbox.on_action
(types.MethodType on_selection_msgbox_close selection_msgbox))
…On Sun, Jun 22, 2025 at 7:46 AM Kodi Arfer ***@***.***> wrote:
Have you tried py2hy?
—
Reply to this email directly, view it on GitHub
<#2665 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFGIHCHC2IPMZQ3A4SHSMNT3E2JRXAVCNFSM6AAAAAB72YIRV6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJUGIZDIOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Claude Marinier
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Got it, thanks.
Oh! It wants a really old version of Hy.
py2hyb 0.9.5 requires hy==0.18.0, but you have hy 1.1.0 which is
incompatible.
It could still be useful: I could downgrade Hy, use py2hy, and upgrade Hy.
I'm OK for now since I found an another approach which is easily translated
to Hy.
…On Sun, Jun 22, 2025 at 8:12 PM Kodi Arfer ***@***.***> wrote:
[py2hy is] eight years old and blows-up on build.
Wrong one. Try the one on PyPI.
—
Reply to this email directly, view it on GitHub
<#2665 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFGIHCBL25D4ULSX7ICEGF33E5A63AVCNFSM6AAAAAB72YIRV6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJUGUZTQOI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Claude Marinier
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I trusted the result of a Google search for py2hy; it pointed me to py2hyb
on PyPI. That was my mistake.
This time I searched directly on PyPI and it found py2hy-0.2.0 which was
released on 5 June 2025. That looks much better. It's the correct one,
right?
I installed it with pip without error. I am using Hy 1.1.0 and Python
3.13.3 with pip 25.1.1 on Debian 12. I then tried to translate the example
program from earlier in the conversation. It produced two exceptions. So I
tried it with a simpler program.
$ cat timestamp.py
import datetime
print( datetime.datetime.now().strftime("%Y%m%d-%H%M%S") )
This produced the same two exceptions as the other program; I checked with
diff.
$ py2hy timestamp.py
Traceback (most recent call last):
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/macros.py", line
65, in import
parse_tree = pattern.parse(args)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/funcparserlib/parser.py",
line 221, in parse
(tree, _) = self.run(tokens, State(0, 0, None))
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/claude/Python-venv/lib/python3.13/site-packages/funcparserlib/parser.py",
line 383, in _shift
(v, s2) = self.run(tokens, s)
~~~~~~~~^^^^^^^^^^^
File
"/home/claude/Python-venv/lib/python3.13/site-packages/funcparserlib/parser.py",
line 306, in _add
(v2, s3) = other.run(tokens, s2)
~~~~~~~~~^^^^^^^^^^^^
File
"/home/claude/Python-venv/lib/python3.13/site-packages/funcparserlib/parser.py",
line 534, in finished
raise NoParseError("got unexpected token", s2)
funcparserlib.parser.NoParseError: got unexpected token: hy.models.List([
hy.models.Expression([
hy.models.Symbol('.'),
hy.models.Symbol('hy'),
hy.models.Symbol('contrib'),
hy.models.Symbol('hy-repr')]),
hy.models.List([
hy.models.Symbol('hy-repr')])]), expected: end of input
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/claude/Python-venv/bin/py2hy", line 5, in <module>
from py2hyb.py2hy import main
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
File "<frozen importlib._bootstrap_external>", line 1160, in get_code
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/importer.py",
line 123, in _hy_source_to_code
data = hy_compile(hy_tree, module)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 882, in hy_compile
result = compiler.compile(tree)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 420, in compile
raise e
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 411, in compile
ret = self.compile_atom(tree)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 405, in compile_atom
return Result() + _model_compilers[type(atom)](self, atom)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 494, in _compile_branch
last = self.compile(node)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 420, in compile
raise e
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 411, in compile
ret = self.compile_atom(tree)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 405, in compile_atom
return Result() + _model_compilers[type(atom)](self, atom)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/compiler.py",
line 566, in compile_expression
expr = macroexpand(expr, self.module, self)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/macros.py", line
401, in macroexpand
obj = m(
# If the macro's first parameter is named
...<4 lines>...
else []),
*map(as_model, tree[1:]))
File
"/home/claude/Python-venv/lib/python3.13/site-packages/hy/macros.py", line
67, in import
raise _hy_compiler._syntax_error(
...<4 lines>...
)
File
"/home/claude/Python-venv/lib/python3.13/site-packages/py2hyb/py2hy.hy",
line 10
(import [hy.contrib.hy-repr [hy-repr]])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hy.errors.HySyntaxError: parse error for pattern macro 'import': got
unexpected token: hy.models.List([
hy.models.Expression([
hy.models.Symbol('.'),
hy.models.Symbol('hy'),
hy.models.Symbol('contrib'),
hy.models.Symbol('hy-repr')]),
hy.models.List([
hy.models.Symbol('hy-repr')])]), expected: end of macro call
I have no idea what I am doing wrong.
…On Sun, Jun 22, 2025 at 10:02 PM Kodi Arfer ***@***.***> wrote:
You did not get it. That's still the wrong one. Try the one on PyPI.
—
Reply to this email directly, view it on GitHub
<#2665 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFGIHCGX2GV46ZPDDY7E2YL3E5N2VAVCNFSM6AAAAAB72YIRV6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJUGU4DSNI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Claude Marinier
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi Kodi,
Yes, there was an old binary.
I apologize for all my blunders. I learned a lot: there are sometimes a few
packages with similar names and do not assume a package will run as a
command. I already know to check the README, but I failed to do so in this
case.
This will be useful as I learn more about Hy.
Thank you for your efforts in developing py2hy and your patience with me.
…On Mon, Jun 23, 2025 at 1:13 PM Kodi Arfer ***@***.***> wrote:
You installed the right package, but you're probably still running the
wrong one, since py2hy doesn't install a binary named py2hy. It's
executed as python3 -m py2hy mycode.py. See the README.
—
Reply to this email directly, view it on GitHub
<#2665 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFGIHCFIRWT7TTYR7WUROIT3FAYU7AVCNFSM6AAAAAB72YIRV6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJVGM3DGMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Claude Marinier
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
The Arcade game library has a UIMessageBox GUI widget class with an empty on_action method. They recommend overwriting that method using a syntax I do not know how to translate to Hy.
The Arcade documentation is here.
Here is my code for the previous version of Arcade (I recently upgraded); it has a callback parameter. I now have to remove the callback parameter and overwrite the on_action method.
How can I do this in Hy?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions