I get "19:56:14 During initialization the error "No module named 'TranslateUtils'" occurred in /home/wile/.local/share/FreeCAD/Mod/FreeCAD_Electric/InitGui.py" at start up.
Where do I find "TranslateUtils"?
This is for the future. I have removed this module. The repository has been updated. It should work now.
After the addition,wandererfan wrote: ↑Fri Dec 02, 2022 7:50 pm That definitely looks like BoundingRect issue to me. If the BR is too small, the old graphic doesn't get erased completely.
Code: Select all
super().mousePressEvent(event);
I haven't looked at the code. But if I understood everything correctly:edi wrote: ↑Thu Dec 01, 2022 1:36 pm Find attached a script creating a new MDI view, adding a scene showing some geometric stuff.Everything is made in Qt. The problem is, how to announce FreeCAD what happened ? That means to create an item in the Combo view, which can be selected/deselected/deleted.Code: Select all
'' Create a new Tab in the main window, an do some graphic stuff ''' from PySide import QtGui def createTestScene(): '''create test scene''' scene = QtGui.QGraphicsScene() scene.line1 = scene.addLine(-10,-115,90,-116) scene.ellipse = scene.addEllipse(20,20,100,50) pen = QtGui.QPen(QtGui.Qt.red) scene.rect = scene.addRect(-20,-20,40,40,pen) scene.rect.setFlag(QtGui.QGraphicsItem.ItemIsMovable) scene.line2 = scene.addLine(0,0,50,50) scene.line2.setFlag(QtGui.QGraphicsItem.ItemIsSelectable) scene.text = scene.addText('Hello world') return scene def addMDIView(view,tabText): '''add new MDIView and set tab text''' mainWindow = FreeCADGui.getMainWindow() mdiArea = mainWindow.findChild(QtGui.QMdiArea) subWindow = mdiArea.addSubWindow(view) subWindow.show() mdiArea.setActiveSubWindow(subWindow) tab = mainWindow.findChildren(QtGui.QTabBar)[0] tab.setTabText(tab.count()-1,tabText) scene = createTestScene() view = QtGui.QGraphicsView() view.setScene(scene) addMDIView(view,'New tab')
Using
Code: Select all
subWindow = mdiArea.addSubWindow(view)
Code: Select all
subList = mainWindow.findChildren(QtGui.QMdiSubWindow)
edi wrote: ↑Sun Dec 04, 2022 9:14 amyou receive a list of all existing subwindows (exact: a list of pointers). Check, using a loop, if your saved object is existing in the list.Code: Select all
subList = mainWindow.findChildren(QtGui.QMdiSubWindow)
Code: Select all
class MDIViewBluePrint(QtGui.QMdiSubWindow):
def __init__(self, obj):
super().__init__()
self.obj = obj
self.setMouseTracking(True)
self.setWindowTitle(self.obj.Name)
def closeEvent(self, event):
#print("Tab is closed")
setattr(self.obj, "Visibility", False)
super().closeEvent(event)
Code: Select all
void MDIViewPage::print()
{
// Base::Console().Message("MDIVP::print()\n");
getPaperAttributes();
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter));
} else {
printer.setPageSize(QPageSize(m_paperSize));
}
printer.setPageOrientation(m_orientation);
QPrintDialog dlg(&printer, this);
if (dlg.exec() == QDialog::Accepted) {
print(&printer);
}
}
This code is slightly incorrect. No need to search for QTabBar and change the text via setTabText().edi wrote: ↑Thu Dec 01, 2022 1:36 pmCode: Select all
... def addMDIView(view,tabText): '''add new MDIView and set tab text''' mainWindow = FreeCADGui.getMainWindow() mdiArea = mainWindow.findChild(QtGui.QMdiArea) subWindow = mdiArea.addSubWindow(view) subWindow.show() mdiArea.setActiveSubWindow(subWindow) tab = mainWindow.findChildren(QtGui.QTabBar)[0] tab.setTabText(tab.count()-1,tabText)
Code: Select all
tab = mainWindow.findChildren(QtGui.QTabBar)[0]
tab.setTabText(tab.count()-1,tabText)
Code: Select all
self.frame = QtGui.QMdiSubWindow()
self.frame.setWindowTitle(Name)
self.frame.setWidget(Widget)
Code: Select all
//called by ViewProvider when Page feature Label changes
void MDIViewPage::setTabText(std::string tabText)
{
if (!isPassive() && !tabText.empty()) {
QString cap = QString::fromLatin1("%1 [*]")
.arg(QString::fromUtf8(tabText.c_str()));
setWindowTitle(cap);
}
}
It has been a while since I looked at this area, but from what I remember, the print preview command sends a message to the MDIView, which calls a print preview method (does nothing in the base MDIView, but is overridden in MDIViewPage) to do the work.
It is just the regular Qt print dialog. This works the same way as print preview. The print command sends a message to the MDIView, which calls the print() method defined in that MDIView (in our case the override method in MDIViewPage).