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

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

I know which one you mean. I can vaguely remember that it was not in the topic's title. What a big help!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

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')?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

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

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

Post by chrisb »

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?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

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
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

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?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

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

Code: Select all

from PySide2.QtOpenGL import *
Sorry for being late: It works! Thank you.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

wmayer wrote: Sun Aug 20, 2017 2:00 pm

Code: Select all

from PySide import QtCore
from PySide import QtGui

class AboutInfo(QtCore.QObject):
  def eventFilter(self, obj, ev):
    if obj.metaObject().className() == "Gui::Dialog::AboutDialog":
      if ev.type() == ev.ChildPolished:
        print(obj.metaObject().className())
        mo = obj.metaObject()
        index = mo.indexOfMethod("on_copyButton_clicked()")
        if index > 0:
          mo.invokeMethod(obj, "on_copyButton_clicked")
          QtGui.qApp.postEvent(obj, QtGui.QCloseEvent())
    
    return False

ai=AboutInfo()
QtGui.qApp.installEventFilter(ai)
Gui.runCommand("Std_About")
QtGui.qApp.removeEventFilter(ai)
@wmayer how can I get this same output but using freecad --console ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

@wmayer how can I get this same output but using freecad --console ?
Not at all. Or how do you think to open the About dialog in CLI mode?
User avatar
dprojects
Posts: 720
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

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

Post by dprojects »

wmayer wrote: Sun Aug 20, 2017 2:00 pm

Code: Select all

from PySide import QtCore
from PySide import QtGui

class AboutInfo(QtCore.QObject):
  def eventFilter(self, obj, ev):
    if obj.metaObject().className() == "Gui::Dialog::AboutDialog":
      if ev.type() == ev.ChildPolished:
        print(obj.metaObject().className())
        mo = obj.metaObject()
        index = mo.indexOfMethod("on_copyButton_clicked()")
        if index > 0:
          mo.invokeMethod(obj, "on_copyButton_clicked")
          QtGui.qApp.postEvent(obj, QtGui.QCloseEvent())
    
    return False

ai=AboutInfo()
QtGui.qApp.installEventFilter(ai)
Gui.runCommand("Std_About")
QtGui.qApp.removeEventFilter(ai)
Oh Man !!! This is what I was looking for. I added "Std_About" to the woodworking workbench because I didn't know how to grab the info content. Can I use your code? for example to add some info that the details has been already copied or something like that.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
Post Reply