Snip macro

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Snip macro

Postby TheMarkster » Sun Aug 04, 2019 12:24 am

The Snip macro is for making it easier to post screenshots here to the forum. It can be installed via the AddonManager.

Macro_Snip


phpBB [video]


Here is the screenshot I took in the above video.
Snip macro screenshot-b118fd.png
Snip macro screenshot-b118fd.png (15.65 KiB) Viewed 577 times
The macro can take the screenshot itself (if it works on your system, so far I have only tested on Windows.) or it can use a screenshot you already took and copied to your system clipboard. If it finds an image on the clipboard it skips the first dialog, the one that takes the screenshot, and instead it uses the one it found on the clipboard. To bypass this press Shift key while invoking the macro.

The macro then takes this image and saves it to a temporary file, then opens that file in a file open dialog. You can drag and drop the file from the file open dialog. It will be deleted automatically when you close the open file dialog. If you open it in the dialog the macro will attempt to open the file in your default application for opening png files, for example it will open the file in Paint on my windows computer.

If the macro cannot work to copy the screenshots it can still be useful for screenshots you can take using other tools. Some other tools:

Windows -> Windows key + Shift + S
Linux -> gnome-screenshot utility
Mac -> Command + Shift + 4

Just use the other tool to copy the screenshot to the clipboard, and then run the Snip macro.
chrisb
Posts: 17597
Joined: Tue Mar 17, 2015 9:14 am

Re: Snip macro

Postby chrisb » Sun Aug 04, 2019 5:48 am

It works on MacOS!

Some remarks:
The macro creates for every single file a new folder in the temp directory. You should either omit the last folder in the path or put all screenshots in the same folder.
"Show Detail" resizes the dialog, and doesn't go back on "Hide Details".
If possible you may consider to open the dialog in the same position with the same size as it was used before.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Sun Aug 04, 2019 6:55 am

chrisb wrote:
Sun Aug 04, 2019 5:48 am
It works on MacOS!

Some remarks:
The macro creates for every single file a new folder in the temp directory. You should either omit the last folder in the path or put all screenshots in the same folder.
Thanks for your feedback. I'm glad to learn it works on Mac OS. You are right. I thought they (both screenshots and temp directories) were being deleted, but it looks like they are not. I need to look through the qt documentation again. There is an alternative way to make temporary files. I might end up using the alternative. My preference would be to completely remove them, but perhaps some users want to keep them? I could set a user parameter for some settings.
"Show Detail" resizes the dialog, and doesn't go back on "Hide Details".
If possible you may consider to open the dialog in the same position with the same size as it was used before.
Yes, I noticed this. I think it is a minor concern. Most users will not be opening the details very often after reading the first time I think.

Is the first dialog fully opaque or partially transparent? If it is transparent do you like the amount of transparency? I have the opacity set at 0.85. I don't think it's necessary at all, but it is a nice feature to be able to see through the dialog. On my Windows 10 it is partially transparent, but when I test inside guest Virtual Box Ubuntu VM (LXDE) it is fully opaque.
chrisb
Posts: 17597
Joined: Tue Mar 17, 2015 9:14 am

Re: Snip macro

Postby chrisb » Sun Aug 04, 2019 7:18 am

I was very surprised too that this macro worked out of the box. An improvement might be to add a filename optionally.
TheMarkster wrote:
Sun Aug 04, 2019 6:55 am
"Show Detail" resizes the dialog, and doesn't go back on "Hide Details".
If possible you may consider to open the dialog in the same position with the same size as it was used before.
these were meant to be two remarks: The "Show Detail" is in fact very very minor. On the mac the button seems to be important, as it is the preselected default.

The second note was meant to be a standalone comment. I frequently make "before" and "after" screenshots, both of the same resolution and area. If the popup would be placed as it was before it would save the moving and resizing.
Is the first dialog fully opaque or partially transparent? If it is transparent do you like the amount of transparency?
It is transparent and I can well see the model below in the standard FreeCAD colour. For my taste transparency is ok; it could be more but should not be less.

Another minor thing which can be irritating and probably a leftover from the development: If I cancel the macro an error is raised and shown in report view. As it is ok to cancel the dialog, I think it doesn't have to be reported at all.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Sun Aug 04, 2019 7:41 am

I have updated to version 1.02. I believe the temp directory and contents are now removed unless the user elects to open the file. I didn't want to delete it while it was being opened. I also now have it where it exits more gracefully when the user cancels. Please update and test.

I understand now what you meant -- to remember the previous size and location and open back to it. That makes sense to do. I can set a user parameter for that if I can work out how to place it back where it was before.

The transparency can be adjusted in the code. Line 128:

Code: Select all

    mb.setWindowOpacity(0.85)
If you find another transparency that works better for you, let me know. I think there has to be a balance between being able to see through the dialog and also being able to read the details.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Sun Aug 04, 2019 7:18 pm

Version 1.03

Macro now remembers position of first dialog, but the width and height are not yet being accepted. I would probably need to create a new dialog class rather than inheriting from QMessageBox for that. Still need to resize, but is a step in the right direction.

I also removed the QSizeGrip from the lower right corner. This has the effect of letting me resize from any edge, not just the lower right corner on my computer running Windows.

Another change was to set a window flag: Qt.Tool, which has the effect of making the window frame less opaque, while also allowing to get the frame position for remembering the previous window location.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Sun Aug 04, 2019 9:55 pm

Version 1.04

There were some issues with other version of Qt.

Now shows version number in first dialog window title.
Checks for support for screengrabbing in version of Qt installed.
Uses alternative way of creating temp folder.
Temp folder and contents now always deleted upon closing.
User avatar
DeepSOIC
Posts: 6877
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Snip macro

Postby DeepSOIC » Sun Aug 04, 2019 10:41 pm

Looks like, it can be even better... but it's not about the macro.
I can:
1. Press PrtSc on keyboard
-> (by default, the whole screen is captured. But there is a setting in Windows10 that can be tweaked to open a dialog with area selection instead)
2. select the area I want to copy
-> the screenshot is on keyboard
3. Open gmail, and paste. The picture is somehow magically attached to the message. (Edge browser, the old non-chromium one).
Step 3 doesn't work with the forum, unfortunately. But since it works with gmail, I think it must be possible to make it work with the forum.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Sun Aug 04, 2019 11:08 pm

DeepSOIC wrote:
Sun Aug 04, 2019 10:41 pm
Looks like, it can be even better... but it's not about the macro.
I can:
1. Press PrtSc on keyboard
-> (by default, the whole screen is captured. But there is a setting in Windows10 that can be tweaked to open a dialog with area selection instead)
2. select the area I want to copy
-> the screenshot is on keyboard
3. Open gmail, and paste. The picture is somehow magically attached to the message. (Edge browser, the old non-chromium one).
Step 3 doesn't work with the forum, unfortunately. But since it works with gmail, I think it must be possible to make it work with the forum.
Yes, I think this is possible -- pasting an image directly from the clipboard into a web form.

In the macro it is mentioned in the Show Details... button about the Windows snipping tool: Windows key + Shift + S. This is a very cool tool that also allows for some annotations of the image, such as highlighting or drawing on it. Simply pressing Shift + PrtSc works, but it not only gives me the whole screen it gives me 2 screens because I have 2 monitors.

There is also room to improve the macro.
TheMarkster
Posts: 1056
Joined: Thu Apr 05, 2018 1:53 am

Re: Snip macro

Postby TheMarkster » Mon Aug 05, 2019 6:20 am

Version 1.05

The snip box now can do a better job remembering its size and location last time it was used. It still sometimes resizes itself larger than it was if you had it really small for a tiny screen snip because it resizes to fit the buttons. For this reason I removed the Cancel button. There is an (X) button or you can press Esc, so that button was not really necessary.

2 new User parameters were added. These can be set via Tools menu -> Edit parameters. The parameters are in UserBase -> Preferences -> Snip_Macro. They are:

LastX, LastY, LastWidth, LastHeight
WindowOpacity
SnipDelay

The Last values are set and reset automatically by the macro each time a screenshot is taken. These are how it remembers its last location and size.

The WindowOpacity parameter is a float between 0.0 and 1.0, with the default at 0.85. The bigger this number the more opaque the snip box is.

SnipDelay is a float that represents the number of seconds to delay between the time the snip box is dismissed and the screenshot is taken. Default is 0.5 seconds. Lower numbers will be quicker, but if it's too low you might get part of the snip box in the screenshot if the system hasn't removed it yet. If you are getting the snip box in the screenshot, try increasing this setting.