QT Creator - layout

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
TopDown
Posts: 159
Joined: Thu Jun 21, 2018 10:00 am

QT Creator - layout

Post by TopDown »

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16131 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 3129ae4296e40ed20e7b3d460b86e6969acbe1c3
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Australia (en_AU)

Hi guys,
getting into Qt Creator....

I have done a layout in Creator.
creatorPNG.PNG
creatorPNG.PNG (204.2 KiB) Viewed 1658 times
I then populate part of it from a macro.

Code: Select all

for doco in FreeCAD.listDocuments(): 
            if not self.DC.nameIsActive("doco", doco):
               continue
                        
            fromDocoName = QtGui.QLabel(doco)
            font = fromDocoName.font()
            font.setPointSize(10)
            font.setWeight(100)
            font.setStyle(QtGui.QFont.StyleItalic)
            fromDocoName.setFont(font)
            toDocoName = QtGui.QLabel(doco)
            toDocoName.setFont(fromDocoName.font())
            addDoco = True

            sheetList = FreeCAD.getDocument(doco).findObjects()
            for sheet in sheetList:   
                sheetName = sheet.Label
                
                if not self.DC.nameIsActive("sheet", sheetName):
                   continue 
 
                if addDoco == True:                        
                    self.form.sheetsFrom.addWidget(fromDocoName, x)
                    self.form.sheetsTo.addWidget(toDocoName, x)
                    addDoco = False

                fromRB = QtGui.QRadioButton(sheetName)
                fromRB.accessibleName = doco
                fromRB.clicked.connect(self.fromButtonClicked)
                self.form.sheetsFrom.addWidget(fromRB, x)
                self.DC.fromSheetsGroup.addButton(fromRB)

                toRB = QtGui.QRadioButton(sheetName)
                toRB.accessibleName = doco
                toRB.clicked.connect(self.toButtonClicked)
                self.form.sheetsTo.addWidget(toRB, x)
                self.DC.toSheetsGroup.addButton(toRB)
The code seems to be putting the correct values in.
The problem is, I am losing some of the layout from creator. Well, possibly not losing it, but it is not visible.
lost.PNG
lost.PNG (10.42 KiB) Viewed 1658 times
Also, how to eliminate the excessive spacing. I believe this is all controlled from the Creator file, and possible overwritten in the macro.
But am at a loss what is needed.

Sorry for the, probably trivial, questions.

Cheers,
Gary.
Attachments
spreadsheetassistant.ui
(9.58 KiB) Downloaded 33 times
TopDown
Posts: 159
Joined: Thu Jun 21, 2018 10:00 am

Re: QT Creator - layout

Post by TopDown »

OK,
I discovered that by changing

Code: Select all

addWidget(fromRB, x)
to (several places)

Code: Select all

addWidget(fromRB)
found.PNG
found.PNG (14.02 KiB) Viewed 1640 times
Cheers.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: QT Creator - layout

Post by Kunda1 »

good job :)
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
TopDown
Posts: 159
Joined: Thu Jun 21, 2018 10:00 am

Re: QT Creator - layout

Post by TopDown »

Thanks for the feedback.

This is my first foray into Freecad macros and Qt Creator.

Appears I have made some progress (based on other spreadsheet tools I found).

The idea isn't all that new just a bit different as a learning exercise. To use the macro, it needs a/multiple documents with one/many spreadsheets open. Selection of sheet cells, options etc. should be made before selecting the sheets via the popup menu. Can be done later (as prompted, but as a starter).

The macro code will need to be pointed at the .ui file. (line 261 n mine is -
path_to_ui = "C:\\Users\\user\\appData\\Roaming\\FreeCad\\Macro\\spreadSheetAssistant.ui"

Any feedback is welcome (I am aware the comments etc. need quite a bit of work, am mainly interested in coding suggestions).
Thanks everyone,
Gary.

PS. any suggestions for an icon would be appreciated as well.
Attachments
spreadsheetassistant.ui
(9.58 KiB) Downloaded 40 times
spreadAssistant.FCMacro
(16.38 KiB) Downloaded 51 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: QT Creator - layout

Post by Kunda1 »

I'll take a look at this soon. Thanks for your work so far!
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
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: QT Creator - layout

Post by Kunda1 »

TopDown wrote: Tue Sep 24, 2019 5:33 am PS. any suggestions
Do you mind pushing this macro up to a github repo so we can quickly kick it around. One thing would be useful is to put this macro within it's own directory along with the .ui file. And then instead of hardcoding a Windows OS path like you do on line 261,

Code: Select all

class assistantPanel:
    path_to_ui = "C:\\Users\\user\\appData\\Roaming\\FreeCad\\Macro\\spreadSheetAssistant.ui"
We can make this macro cross-platform by searching FreeCAD's default macro directory.
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
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: QT Creator - layout

Post by sgrogan »

Kunda1 wrote: Thu Oct 03, 2019 7:54 pm We can make this macro cross-platform by searching FreeCAD's default macro directory.

Code: Select all

p=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")
path_to_ui = p.GetString("MacroPath") + "/spreadSheetAssistant.ui"
"fight the good fight"
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: QT Creator - layout

Post by Kunda1 »

sgrogan wrote: Thu Oct 03, 2019 8:38 pm

Code: Select all

p=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")
path_to_ui = p.GetString("MacroPath") + "/spreadSheetAssistant.ui"
:+1: :ugeek:

Edit: though the forward slash wouldn't be Windows compliant..right ?
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
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: QT Creator - layout

Post by sgrogan »

Kunda1 wrote: Thu Oct 03, 2019 8:39 pm Edit: though the forward slash wouldn't be Windows compliant..right ?
Windows will take \, \\, /
"fight the good fight"
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: QT Creator - layout

Post by vocx »

Kunda1 wrote: Thu Oct 03, 2019 8:39 pm Edit: though the forward slash wouldn't be Windows compliant..right ?
https://en.wikipedia.org/wiki/Backslash
Wikipedia wrote: MS-DOS 2.0, released 1983, copied the hierarchical file system from Unix and thus used the (forward) slash[9] but (possibly on the insistence of IBM[10]) added the backslash to allow paths to be typed at the command line interpreter's prompt... Except for COMMAND.COM, all other parts of the operating system accept both characters in a path, but the Microsoft convention remains to use a backslash, ...

The Microsoft Windows family of operating systems inherited the MS-DOS behavior and so still support either character – but individual Windows programs and sub-systems may, wrongly, only accept the backslash as a path delimiter, or may misinterpret a forward slash if it is used as such. ...
Microsoft originally used the forward slash, like Unix. Only later the backslash became more prominent.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply