[Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Need help, or want to share a macro? Post here!
chrisb
Posts: 19505
Joined: Tue Mar 17, 2015 9:14 am

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby chrisb » Fri Nov 08, 2019 9:29 pm

I know which one you mean. I can vaguely remember that it was not in the topic's title. What a big help!
User avatar
Kunda1
Posts: 5913
Joined: Thu Jan 05, 2017 9:03 pm

Re: Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby Kunda1 » Sat Nov 09, 2019 12:20 pm

wmayer wrote:
Sun Aug 20, 2017 9:11 pm
FYI, in Qt any sub-class of QObject can re-implement the (in C++ virtual) method eventFilter() and can be installed to any other QObject-dervied instance to observe or filter the events it gets.
In C++ the class name of the About dialog including name spaces is called Gui::Dialog::AboutDialog and the class name of a QObject can be determined by its meta object. So, the event filter only looks for About dialogs and as event it uses the polish event which is called before the dialog is shown.

The name of the method of the dialog that is invoked when pressing the Copy button is called on_copyButton_clicked() and is marked as a slot function (for more information refer to the Qt docs to see what a slot function exactly is) and this allows it to allow to call it over its meta object.

By calling on_copyButton_clicked all the needed information is copied to the clipboard and the dialog can be closed again. Thus, a close event is posted to the dialog class.

The four lines at the end are needed to install the event filter to the global application object, invoke the Std_About command which internally creates the About dialog and removing the event filter again.
@wmayer
can this function be accessible without the GUI enabled (aka 'headless')?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
wmayer
Site Admin
Posts: 14989
Joined: Thu Feb 19, 2009 10:32 am

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby wmayer » Sat Nov 09, 2019 2:12 pm

No!
chrisb
Posts: 19505
Joined: Tue Mar 17, 2015 9:14 am

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby chrisb » Thu Nov 14, 2019 12:52 am

I have created a macro and have placed in my globals toolbar.
I can run the macro from the macro dialog by selecting and executing it.

However, if I run it from the toolbar I get an error message:

Code: Select all

Traceback (most recent call last):
  File "/Users/cb/panhard/coupe/sanssoupapes/copyToClipboard.FCMacro", line 2, in <module>
    from PySide import QtOpenGL
<class 'ImportError'>: cannot import name 'QtOpenGL' from 'PySide' (/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Ext/PySide/__init__.py)
I can run other macros in the same way without problems. Any ideas?
wmayer
Site Admin
Posts: 14989
Joined: Thu Feb 19, 2009 10:32 am

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby wmayer » Thu Nov 14, 2019 12:22 pm

You may have to add the file QtOpenGL.py inside FreeCAD's Ext\PySide directory with the content:

Code: Select all

from PySide2.QtOpenGL import *
User avatar
Kunda1
Posts: 5913
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby Kunda1 » Tue Nov 26, 2019 8:33 pm

chrisb wrote:
Thu Nov 14, 2019 12:52 am
I have created a macro and have placed in my globals toolbar.
Any progress on this?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
chrisb
Posts: 19505
Joined: Tue Mar 17, 2015 9:14 am

Re: [Solved] Help firing AboutDialog::on_copyButton_clicked() wanted by n00b

Postby chrisb » Tue Nov 26, 2019 11:10 pm

wmayer wrote:
Thu Nov 14, 2019 12:22 pm

Code: Select all

from PySide2.QtOpenGL import *
Sorry for being late: It works! Thank you.