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

fix: show unicode in toasts #2493

Closed
wants to merge 6 commits into from

Conversation

sanzoghenzo
Copy link
Contributor

closes #2484

Title and message with unicode chars (I tried emojis) work, actions and sounds don't.

Now that I think of it, we could use the Microsoft.Toolkit.Uwp.Notifications .NET package for that instead of relying on a powershell script...

@jmcouffin jmcouffin changed the title fix: show uncode in toasts fix: show unicode in toasts Dec 27, 2024
@sanzoghenzo
Copy link
Contributor Author

I should have tried it inside pyRevit before submitting it 😅 I simplified some things and made the function signature compatible with pyrevit.forms.toast, so that I could drop it (I still import the toast function inside forms __init__, so nothing changed for the user).

The problem now is... IronPython's ElementTree doesn't seem to work with unicode, so I'm back at square one 😓

@dosymep I saw that you wrote a comment about the dependency, do you think that using an UWP component will break things?

@dosymep
Copy link
Member

dosymep commented Dec 28, 2024

do you think that using an UWP component will break things?

yep
how it is work? why do you use powershell?

@sanzoghenzo
Copy link
Contributor Author

do you think that using an UWP component will break things?

yep

Would it be better to use Windows.UI.Notifications?

how it is work? why do you use powershell?

Because I just ported the go code of the previous pyrevit-toaster.exe, or to be precise a fork that should have solved the unicode issue (but used string templating instead of an xml library to build the configuration).
I just removed a step, I call directly powershell instead of a go binary that in turn calls powershell.
The powershell calls in fact the Windows.UI.Notifications.ToastNotificationManager to display the toast.

@dosymep
Copy link
Member

dosymep commented Dec 28, 2024

go binary that in turn calls powershell

oh okay :)

@sanzoghenzo
Copy link
Contributor Author

sanzoghenzo commented Dec 28, 2024

I am so close... but I don't know how to solve it!

I switched to string templates to avoid unwanted etree string escaping;
I also fixed the flashing powershell window (i forgot to add a flag to subcommand)

Now the Test Button in DevTools shows a "??" instead of the rocket, but if I copy the script from the debug log and paste into powershell with powershell -NoProfile -NonInteractive -Command prepended, the toast correctly shows the emoji (even thow it is shown as "??" in the powershell window)...

I tried to encode/decode the strings, but no combination works... As always, ChatGPT is full of shit.
Any Ideas how to properly pass the unicode text to powershell as-is?

BTW, I also tried using Windows.UI.Notification, but obviously it needed an assembly that is not referenced, and I'm too lazy to try to add it (where? should it be pyRevitLabs.Runtime?) and recompile 😅

EDIT: oh, python 2.7 subprocess doesn't work with unicode on windows....
There's a pathced subprocess that should do the work, not sure if I want to add yet another custom thing to solve a silly problem

@dosymep
Copy link
Member

dosymep commented Dec 28, 2024

I would help you, but for some reason notifications don't work on my version of the operating system

@sanzoghenzo
Copy link
Contributor Author

I tried to add the patch for windows subprocess, it shows the correct toast but subprocess.check_output throws an exception.
I tried various iterations with Popen, call and check_call, they give me a TypeError that I can't understand (something related to the ctypes).

Since this isn't an high priority task, I'm giving up on this and remove the issue form the pyrevit 5 RC milestone, if someone else wants to pick it up it's more than welcome to do so!

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 this pull request may close these issues.

[Bug]: forms.toast() does not support Unicode characters. (Enhancement)
2 participants