pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.28k stars 331 forks source link

Balloon forms in lieu of toast (due to pyRevit 5) #2352

Open aussieBIMguru opened 4 weeks ago

aussieBIMguru commented 4 weeks ago

Looks like the toast got burnt in pyRevit5!

Just leaving this here if it helps. I noticed in pyRevit 5 toast forms do not seem to trigger. From what I understand of the toast form it depends on another code library packaged into pyRevit that I suspect isn't netcore compatible.

I found the windows balloonforms work and can generate a pretty similar outcome, maybe below code might help the team if the toast form is difficult to reimplement. The main drawback is it's a bit less pretty and doesn't support the dictionary list for buttons like toast did.

The on click function is a bit rudimentary that I've built - attempts to support filepath/urlpath open on clicking the form generally vs giving the user extra buttons with tooltip to describe this being the behavior of doing so.

import clr
import os
import webbrowser
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import System
from System.Windows.Forms import Application, ToolTipIcon, NotifyIcon

class formUtils_balloonMessage:
    def __init__(self, title, msg, warnIcon = False, filePath = None, urlPath = None):
        self.title = title
        self.msg = msg
        self.filePath = filePath
        self.urlPath = urlPath
        if warnIcon:
            self.icon = ToolTipIcon.Warning
        else:
            self.icon = ToolTipIcon.Info
    def show(self):
        balloonMessage = NotifyIcon()
        if self.filePath is not None or self.urlPath is not None:
            balloonMessage.BalloonTipClicked += self.onClick
        balloonMessage.Text = self.title
        balloonMessage.Visible = True
        balloonMessage.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath)
        balloonMessage.ShowBalloonTip(5000, self.title, self.msg, self.icon)
    def onClick(self, sender, args):
        if self.filePath is not None:
            try:
                os.startfile(self.filePath)
            except:
                pass
        elif self.urlPath is not None:
            try:
                webbrowser.open(self.urlPath)
            except:
                pass
aussieBIMguru commented 4 weeks ago

Example of the appearance vs toast.

image

jmcouffin commented 3 weeks ago

Is it possible this is not a bug @aussieBIMguru Toast notification can be deactivated in Windows (at least this is what I have done on my setup long ago) https://answers.microsoft.com/en-us/windows/forum/all/windows-10-toast-notification/39677a5b-8a73-4c27-91fb-d377c5f04a4a

aussieBIMguru commented 3 weeks ago

Yes in this case I've managed to get the toast forms triggering in lower versions on the same machine so I'm fairly sure it's pyRevit related. No errors trigger, it just doesn't show any toast notification when ran. I can get NotifyIcon() to work which is supressed similarly to toast if the user opts out of notifications.

sanzoghenzo commented 3 weeks ago

Thanks @aussieBIMguru for the code sample! Some observations:

And now that I get a better look at it, this could be turned into a function, no need to overengineer things! Just extract the show method and add the parameters there 😉

aussieBIMguru commented 2 weeks ago

Thanks! I'm not overly familiar with the pyRevit conventions and PR system but will do some research and put something forward in the forms library once I've got my head around it. It does load in some windows libraries to support dependency which have a slight speed hit in my experience, but can't see how to avoid that.

sanzoghenzo commented 2 weeks ago

There still are no pyRevit conventions per se, I just trying to enforce best practices in the python world, but I understand that, given the intersection between python and c#, there is some style mixup... for now the important thing is to be consistent within your code: there's no place for underscores when you use camelCase and PascalCase, as snake_case is all lowecase.

For the PR:

Most of this can be done in Visual Studio Code, if you use that.

aussieBIMguru commented 2 weeks ago

Yes that's moreso what I mean, need to spend some time figuring out the style of pyRevit. I've developed some habits (some good, some not) managing my own extension.

Personally I use camel after snake for functions as I find myself needing multiple words to describe the function beyond the primary object but I'll look at this when time allows to put it into a closer style at the least. Pascal for classes, camel for local variables and snake without camel for global variables. It's close to the typical but I appreciate not quite in line with industry style.

I generally use pyCharm but am familiar with VS/git systems as of late. It'll likely be a ways off as just trying to get my company code working before I get back to this but will see how I go. Thanks for the tips! I haven't found any other issues really aside from Microsoft Interop not working in NetCore forcing me back to csv for me (xlrd has issues with reading special characters), but will let the team know if I find anything else. Really nice work getting it 99% of the way there as a team!