manipulate svg-grafic in QDialog

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

manipulate svg-grafic in QDialog

Post by Chri1 »

Hi

I have a dialog (created with QT) with svg graphics (created with Inkscape), the grahics are integrated by styleSheet-property of an label.
Pressing various buttons in the dialog box also changes the used SVG files.
But:
I don't want to use a lot of SVG files, I want to draw everything in one file at different layers.
And in the dialog I want to change the visibility of the layers by code.

Or in general:
How can I change an svg by code (without changing the file itself) and use it in the dialog ?

Thanks.
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

Re: manipulate svg-grafic in QDialog

Post by Chri1 »

Firstly the code to manipulate the svg-file:

Code: Select all

import xml.etree.ElementTree as ET
what = ..... svg     # Path and filename
tree=ET.parse(what)
#Also possible:  tree=ET.fromstring(svg - code)
root=tree.getroot()

for ding in root.iter('{http://www.w3.org/2000/svg}g'):
    #print(ding.attrib, ding.get('style'))
    ding.set('style','display:inline')  # or unvisible:   display:none
    print(ding.get('style'))
tree.write(what)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: manipulate svg-grafic in QDialog

Post by openBrain »

What are you (at the end) trying to achieve ? Can you give details/example/moke-up ?
ATM I'm not sure tampering the SVG DOM is the best approach.
Chri1
Posts: 86
Joined: Wed Oct 17, 2018 9:00 am

Re: manipulate svg-grafic in QDialog

Post by Chri1 »

Trying to achieve:

I have a Dialog with some buttons. Every Button should show an explaining picture (always in the same label).
On the whole, the pictures are relative similar. the differences I lied on different layers and can be shown by switching the layers.
This works now by manipulating the svg-file by code and reload it in the dialog.
It is definitely easier than managing a lot of pictures (if I improve the design, I don't have to edit a lot of pictures. And it opens up further possibilities by manipulating the individual elements of the graphic)

But maybe its possible, to do this without always changing the file.
I just tried in QT to put the svg-code directly in the stylsheet-property - QT crashed......
I don't know if that would be really an advantage, there is also a little sporting ambition ;)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: manipulate svg-grafic in QDialog

Post by openBrain »

Sorry for sparse replies. This isn't clear yet. Could you provide an example SVG and a simple mock up ?
Post Reply