[Improvement, partially SOLVED] Pages always display the internal name

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

[Improvement, partially SOLVED] Pages always display the internal name

Post by vocx »

If I have a document and create several TechDraw pages, they are initially named Page, Page001, Page002, etc. However, it makes sense to rename the pages, for example, Page.front_view, Page.isometric, Page.elevations, whatever.

Despite the pages being renamed, the tabs that show the names are still shown with the internal name.
Screenshot from 2018-10-18 17-46-44.png
Screenshot from 2018-10-18 17-46-44.png (64.62 KiB) Viewed 2535 times
Also, it's not possible to arrange which page goes first and which comes second. This is not a problem when you only have two pages, but if you have ten or more, it becomes cumbersome if you decide to create new pages and views later on.

So the improvement would be to be able to see the new names in the tabs, and to order the pages as you wish.

OS: Ubuntu 18.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14979 (Git)
Build type: Release
Branch: master
Hash: 47536dcd3729d3db106af628d62f2bf449e68c49
Python version: 2.7.15rc1
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Last edited by vocx on Thu Oct 25, 2018 6:34 pm, edited 2 times in total.
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.
chrisb
Veteran
Posts: 54274
Joined: Tue Mar 17, 2015 9:14 am

Re: [Improvement] Pages always display the internal name

Post by chrisb »

A group is perfect for ordering the pages. Insert them in the order you want and collapse the view to keep the tree view tidy, if they are not needed.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Pages always display the internal name

Post by vocx »

chrisb wrote: Fri Oct 19, 2018 6:01 am A group is perfect for ordering the pages. Insert them in the order you want and collapse the view to keep the tree view tidy, if they are not needed.
Yes, Std_Groups do help you organize the pages but it doesn't address the underlying issue. I think by now most users who've been following the development of FreeCAD since 0.16 know to use a lot of groups to keep the Model tree simple and logically organized; however, I think new users experience a bit of confusion when TechDraw Pages seem to behave in an odd way, not respecting name changes, and not being able to be ordered by dragging the tabs.

Besides, if you have many Pages, they are all opened when you first open your file in FreeCAD. Maybe the default should be to not open all TechDraw Pages?
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.
chrisb
Veteran
Posts: 54274
Joined: Tue Mar 17, 2015 9:14 am

Re: [Improvement] Pages always display the internal name

Post by chrisb »

vocx wrote: Fri Oct 19, 2018 7:43 am Besides, if you have many Pages, they are all opened when you first open your file in FreeCAD. Maybe the default should be to not open all TechDraw Pages?
That has been discussed here before; please search the forum, probably the big TechDraw topic.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
wandererfan
Veteran
Posts: 6324
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Pages always display the internal name

Post by wandererfan »

vocx wrote: Thu Oct 18, 2018 11:11 pm Despite the pages being renamed, the tabs that show the names are still shown with the internal name.
I've been meaning to fix this for a while. Will try to get this into v0.18 before release.
vocx wrote: Thu Oct 18, 2018 11:11 pm Also, it's not possible to arrange which page goes first and which comes second. This is not a problem when you only have two pages, but if you have ten or more, it becomes cumbersome if you decide to create new pages and views later on.
Not really sure how to go about this. I believe the mainWindow arranges the tabs in the order they are created. I'm not sure if there is a convenient way to reorder the tabs. No promises on this one.
User avatar
wandererfan
Veteran
Posts: 6324
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Pages always display the internal name

Post by wandererfan »

vocx wrote: Fri Oct 19, 2018 7:43 am Besides, if you have many Pages, they are all opened when you first open your file in FreeCAD. Maybe the default should be to not open all TechDraw Pages?
If you set "Preferences->TechDraw1->KeepPagesUpToDate" to OFF, Pages will be created, but not drawn at startup. If you want to see a particular Page after startup, change the Page's KeepUpdated property. If you have big complicated drawings, this is the way to go.
chrisb
Veteran
Posts: 54274
Joined: Tue Mar 17, 2015 9:14 am

Re: [Improvement] Pages always display the internal name

Post by chrisb »

wandererfan wrote: Fri Oct 19, 2018 1:09 pm Not really sure how to go about this. I believe the mainWindow arranges the tabs in the order they are created. I'm not sure if there is a convenient way to reorder the tabs. No promises on this one.
Perhaps you can reuse the code from PartDesign's "Move object after other object".
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Pages always display the internal name

Post by vocx »

wandererfan wrote: Fri Oct 19, 2018 1:17 pm If you set "Preferences->TechDraw1->KeepPagesUpToDate" to OFF, Pages will be created, but not drawn at startup. If you want to see a particular Page after startup, change the Page's KeepUpdated property. If you have big complicated drawings, this is the way to go.
I see. To me this is not very intuitive. In my mind KeepUpdated should keep the 3D model and the projected views synchronized, but it should not affect whether the Pages appear at startup or not. Maybe it's possible to add another property, ShowAtStartup, to each page?
Last edited by vocx on Fri Oct 19, 2018 10:36 pm, edited 1 time in total.
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.
User avatar
wandererfan
Veteran
Posts: 6324
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Pages always display the internal name

Post by wandererfan »

vocx wrote: Fri Oct 19, 2018 9:33 pm In my mind KeepUdated should keep the 3D model and the projected views synchronized, but it should not affect whether the Pages appear at startup or not.
That is the intended purpose of "KeepUpdated". Not drawing the Page(s) at startup was just a side effect that turned out to be useful. Not intuitive, perhaps not even documented. Have to look into that.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Improvement] Pages always display the internal name

Post by vocx »

wandererfan wrote: Fri Oct 19, 2018 1:09 pm
vocx wrote: Thu Oct 18, 2018 11:11 pm Also, it's not possible to arrange which page goes first and which comes second. This is not a problem when you only have two pages, but if you have ten or more, it becomes cumbersome if you decide to create new pages and views later on.
Not really sure how to go about this. I believe the mainWindow arranges the tabs in the order they are created. I'm not sure if there is a convenient way to reorder the tabs. No promises on this one.
I don't know much Qt but I suspect it's one of the easiest things to do. Many programs nowadays use tabs whether using Gtk+ or Qt, like Gedit, DoubleCommander, Firefox and many others, and changing the order of the tabs is the most normal thing to do. Users practically expect to be able to do this in modern applications.

I searched online and it seems the component that does this is QTabWidget, https://stackoverflow.com/questions/167 ... tab-window, https://forum.qt.io/topic/30974/setting ... qtabwidget

In this thread the users demonstrate a simple program that subclasses QTabWidget, https://forum.qt.io/topic/67542/drag-ta ... bwidgets/6 They mention needing to define a couple of functions like mouseMoveEvent(), dragMoveEvent(), dropEvent(), etc., to know what to do with the tab when the mouse drags it.

The example from the aforementioned thread creates two panes with two tabs in each pane. The tabs can be moved with the left mouse button. To move a tab from one pane to the other pane, use the right mouse button.

This is the code

Code: Select all

import sys

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class Tabs(QTabWidget):
    def __init__(self, parent):
        super().__init__(parent)
        self.parent = parent
        self.setAcceptDrops(True)
        self.tabBar = self.tabBar()
        self.tabBar.setMouseTracking(True)
        self.indexTab = None
        self.setMovable(True)

        self.addTab(QWidget(self), 'Tab One')
        self.addTab(QWidget(self), 'Tab Two')

    def mouseMoveEvent(self, e):
        if e.buttons() != Qt.RightButton:
            return

        globalPos = self.mapToGlobal(e.pos())
        tabBar = self.tabBar
        posInTab = tabBar.mapFromGlobal(globalPos)
        self.indexTab = tabBar.tabAt(e.pos())
        tabRect = tabBar.tabRect(self.indexTab)

        pixmap = QPixmap(tabRect.size())
        tabBar.render(pixmap,QPoint(),QRegion(tabRect))
        mimeData = QMimeData()
        drag = QDrag(tabBar)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        cursor = QCursor(Qt.OpenHandCursor)
        drag.setHotSpot(e.pos() - posInTab)
        drag.setDragCursor(cursor.pixmap(),Qt.MoveAction)
        dropAction = drag.exec_(Qt.MoveAction)


    def dragEnterEvent(self, e):
        e.accept()
        if e.source().parentWidget() != self:
            return

        print(self.indexOf(self.widget(self.indexTab)))
        self.parent.TABINDEX = self.indexOf(self.widget(self.indexTab))


    def dragLeaveEvent(self,e):
        e.accept()


    def dropEvent(self, e):
        print(self.parent.TABINDEX)
        if e.source().parentWidget() == self:
            return

        e.setDropAction(Qt.MoveAction)
        e.accept()
        counter = self.count()

        if counter == 0:
            self.addTab(e.source().parentWidget().widget(self.parent.TABINDEX),e.source().tabText(self.parent.TABINDEX))
        else:
            self.insertTab(counter + 1 ,e.source().parentWidget().widget(self.parent.TABINDEX),e.source().tabText(self.parent.TABINDEX))


class Window(QWidget):
    def __init__(self):

        super().__init__()

        self.TABINDEX = 0
        tabWidgetOne = Tabs(self)
        tabWidgetTwo = Tabs(self)

        layout = QHBoxLayout()

        self.moveWidget = None

        layout.addWidget(tabWidgetOne)
        layout.addWidget(tabWidgetTwo)

        self.setLayout(layout)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
Save it as window_tabs.py and you can test it (in Ubuntu 18.04) with

Code: Select all

python3 window_tabs.py
The code works with python2 but you need to modify the calls to super(), whose syntax apparently changed from Python 2 to 3. In Python 2 use

Code: Select all

line  9: super(Tabs, self).__init__(parent)
line 73: super(Window, self).__init__()
And then you can run

Code: Select all

python2 window_tabs.py
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