[FEATURE REQUEST] spreadsheet zoom

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
TomB19
Posts: 161
Joined: Wed May 01, 2019 4:58 am

[FEATURE REQUEST] spreadsheet zoom

Postby TomB19 » Fri Jul 10, 2020 3:01 pm

I often wish I could shrink a spreadsheet, to get more on screen. Is there a way?

[Edit: I have created a feature request in the Bug Tracker, at Kunda1's request]

https://tracker.freecadweb.org/view.php?id=4410
Last edited by TomB19 on Sat Jul 25, 2020 6:47 pm, edited 3 times in total.
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: Is there a way to zoom a spreadsheet view?

Postby TheMarkster » Sat Jul 11, 2020 2:20 am

There is a way to shrink the row height via python.

Code: Select all

for ii in range(1,99):
    App.ActiveDocument.Spreadsheet.setRowHeight('A'+str(ii),1)
After running this in the python console, right click the document name in the tree and select Mark to recompute, then F5 to recompute.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
User avatar
Kunda1
Posts: 7674
Joined: Thu Jan 05, 2017 9:03 pm

Re: Is there a way to zoom a spreadsheet view?

Postby Kunda1 » Sat Jul 11, 2020 6:44 pm

TheMarkster wrote:
Sat Jul 11, 2020 2:20 am
There is a way to shrink the row height via python.
Would it merit a feature request to have a slider of a sort somewhere at the bottom of the spreadsheet dialog that scales the size of the spreadsheet ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: Is there a way to zoom a spreadsheet view?

Postby TheMarkster » Sat Jul 11, 2020 7:07 pm

Kunda1 wrote:
Sat Jul 11, 2020 6:44 pm
TheMarkster wrote:
Sat Jul 11, 2020 2:20 am
There is a way to shrink the row height via python.
Would it merit a feature request to have a slider of a sort somewhere at the bottom of the spreadsheet dialog that scales the size of the spreadsheet ?
I don't know. You can already adjust the row sizes individually. In the image below the red circle indicates the drag point.
Snip macro screenshot-46c9d2.png
Snip macro screenshot-46c9d2.png (4.56 KiB) Viewed 360 times
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
TomB19
Posts: 161
Joined: Wed May 01, 2019 4:58 am

Re: Is there a way to zoom a spreadsheet view?

Postby TomB19 » Sat Jul 11, 2020 8:06 pm

Thank you, TheMarkster. 8-)

For a few months, I was adding attributes to spreadsheets in a two column format. That would have been helpful, then.

That approach proved nonviable so I switched to a multi-column format. This has helped a lot.

I've attached a screen shot of the layout I use, these days. It's blurry because it's been heavily shrunk for forum upload (native 2560x1600 resolution).

Sometimes it would be nice to be able to control the size of the entire spreadsheet, something like the LibreCalc zoom slider at the bottom right (screen shot below, for those who haven't seen LibreCalc :mrgreen: ).

I doubt this feature is more important than any number of other things the team is working on, so I don't wish to request it.

resized_FC Screen Layout.png
resized_FC Screen Layout.png (115.86 KiB) Viewed 341 times
LibreCalc
LibreCalc - zoom.png
LibreCalc - zoom.png (1.71 KiB) Viewed 341 times
User avatar
Kunda1
Posts: 7674
Joined: Thu Jan 05, 2017 9:03 pm

Re: Is there a way to zoom a spreadsheet view?

Postby Kunda1 » Sat Jul 11, 2020 11:07 pm

TomB19 wrote:
Sat Jul 11, 2020 8:06 pm
Sometimes it would be nice to be able to control the size of the entire spreadsheet, something like the LibreCalc zoom slider at the bottom right (screen shot below, for those who haven't seen LibreCalc :mrgreen: ).
Yes, I was thinking of a slider like this one. I think it would be a nice UI/UX addition. For sure low priority but still good to have on the list
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
Kunda1
Posts: 7674
Joined: Thu Jan 05, 2017 9:03 pm

Re: Is there a way to zoom a spreadsheet view?

Postby Kunda1 » Sun Jul 12, 2020 12:29 pm

I'd imagine the need to use https://doc.qt.io/qt-5/qslider.html
TomB19 wrote:
Sat Jul 11, 2020 8:06 pm
LibreCalc - zoom.png
Do you mind making a gif or screencast of the slider in action and posting to this thread ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
mario52
Posts: 3030
Joined: Wed May 16, 2012 2:13 pm

Re: Is there a way to zoom a spreadsheet view?

Postby mario52 » Sun Jul 12, 2020 6:02 pm

hi
Kunda1 wrote:
Sun Jul 12, 2020 12:29 pm
Do you mind making a gif or screencast of the slider in action and posting to this thread ?
adaptation of the macro openBrain and awei adding extra info in statusbar

modify only the colon A to Z
and the row 1 to 50

for modify the text size .. ??? .. other gourou Python

spreadSheetZoom00.gif
spreadSheetZoom00.gif (202.12 KiB) Viewed 225 times

Code: Select all

#################################################
##https://forum.freecadweb.org/viewtopic.php?f=22&t=48217#p413246
##12/07/2020
##mario52
##https://forum.freecadweb.org/viewtopic.php?f=22&t=48217#p413246
##worked and based on the openBrain and awei snippet 
##
# 
import PySide2
from PySide2 import QtWidgets
import FreeCAD

def sliderVal(value):
    try:
        for i in range(26):                 # for 26 colon A .. to .. Z
            for ii in range(1, 50 + 1):     # for 50 row   1 .. to .. 50
                #print(chr(i+65)+str(ii))
                cellule = chr(i+65)+str(ii)
                App.ActiveDocument.Spreadsheet.setRowHeight(cellule, value)
                App.ActiveDocument.Spreadsheet.setColumnWidth(cellule, value * 4)
        App.ActiveDocument.Spreadsheet.touch()
        App.activeDocument().recompute()
    except Exception:
        None

pb = PySide2.QtWidgets.QSlider()
pb.setOrientation(PySide2.QtCore.Qt.Horizontal)
pb.valueChanged.connect(sliderVal)    
Gui.getMainWindow().statusBar().addWidget(pb)
pb.show()

###################################################
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
Kunda1
Posts: 7674
Joined: Thu Jan 05, 2017 9:03 pm

Re: Is there a way to zoom a spreadsheet view?

Postby Kunda1 » Mon Jul 13, 2020 12:21 am

mario52 wrote:
Sun Jul 12, 2020 6:02 pm
hi
:D
mario52 wrote:
Sun Jul 12, 2020 6:02 pm
adaptation of the macro openBrain and awei adding extra info in statusbar
:heart:
This is awesome!
mario52 wrote:
Sun Jul 12, 2020 6:02 pm
for modify the text size .. ??? .. other gourou Python
Yes! We need another python guru to chime in here for sure.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: Is there a way to zoom a spreadsheet view?

Postby TheMarkster » Mon Jul 13, 2020 3:37 am

A few modifications to Mario's macro.

Code: Select all

#################################################
##https://forum.freecadweb.org/viewtopic.php?f=22&t=48217#p413246
##12/07/2020
##mario52
##https://forum.freecadweb.org/viewtopic.php?f=22&t=48217#p413246
##worked and based on the openBrain and awei snippet 
##
# 
import PySide2
from PySide2 import QtWidgets
import FreeCAD

sheet = None
def getSelected():
    """returns a QModelIndex object or None if none are selected
   use [0] to get at first cell in the selection
   use [0].row() to get first cell's row
   use [0].column() to get first cell's column
   use [-1] to get last cell in the selection
"""
    global sheet
    from PySide import QtGui
    mw=FreeCADGui.getMainWindow()
    mdiarea=mw.findChild(QtGui.QMdiArea)
    subw=mdiarea.subWindowList()
    sel = Gui.Selection.getSelection()
    name=""
    if sel:
        name = sel[0].Name
    for i in subw:
        if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
            if not name == i.windowTitle().replace('[*]',''):
                continue
            sheet=Gui.Selection.getSelection()[0]
            return i.widget().findChild(QtGui.QTableView).selectedIndexes()
    return None
def sliderVal(value):
    try:
        ranges = getSelected()
        if not sheet:
            return
        for rr in ranges:
            cellule = chr(rr.column()+65)+str(rr.row()+1)
            sheet.setRowHeight(cellule,value)
        sheet.touch()
        App.activeDocument().recompute()
    except Exception:
        None

pb = PySide2.QtWidgets.QSlider()
pb.setMinimum(1)
pb.setMaximum(200)
pb.setOrientation(PySide2.QtCore.Qt.Horizontal)
pb.valueChanged.connect(sliderVal)    
Gui.getMainWindow().statusBar().addWidget(pb)
pb.show()

###################################################
Changes:
1) only change row heights
2) get preselected cells and apply row height to only those rows
3) set minimum to 1 (0 hides row entirely) and maximum to 200
4) allow for operation on selected spreadsheet (but it must be selected in the tree, not just in the sheet view)

Things to do:

1) add/show the slider only when the sheet view is active (unless it already exists), then hide/remove it
2) incorporate somehow into FreeCAD main (maybe modify src/Mod/Spreadsheet/InitGui.py?)
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson