dialog box will not show

Need help, or want to share a macro? Post here!
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

dialog box will not show

Postby mfasano » Wed Sep 11, 2019 12:05 am

I am trying to create a script where it opens a dialog box for user input. I used Qt creator to make a UI file and pyside2-uic to make a python file for the dialog box. When I run it, the dialog box does not show.

Thanks.

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

Code: Select all

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'init_val_prob.ui',
# licensing of 'init_val_prob.ui' applies.
#
# Created: Wed Aug 14 12:55:13 2019
#      by: pyside2-uic  running on PySide2 5.13.0
#
# WARNING! All changes made in this file will be lost!




from PySide2 import QtCore, QtGui, QtWidgets
import FreeCADGui as Gui
import FreeCAD as App

# from init_val_prob_dia import Ui_init_val_prob_dialog



class Ui_init_val_prob_dialog(object):
    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
        init_val_prob_dialog.resize(400, 300)
        self.buttonBox = QtWidgets.QDialogButtonBox(init_val_prob_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(215, 240, 156, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.int_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.int_time_txt.setGeometry(QtCore.QRect(30, 45, 113, 20))
        self.int_time_txt.setText("")
        self.int_time_txt.setObjectName("int_time_txt")
        self.init_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.init_time_lab.setGeometry(QtCore.QRect(35, 30, 47, 13))
        self.init_time_lab.setObjectName("init_time_lab")
        self.final_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.final_time_txt.setGeometry(QtCore.QRect(30, 95, 113, 20))
        self.final_time_txt.setText("")
        self.final_time_txt.setObjectName("final_time_txt")
        self.final_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.final_time_lab.setGeometry(QtCore.QRect(35, 80, 47, 13))
        self.final_time_lab.setObjectName("final_time_lab")
        self.step_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.step_time_txt.setGeometry(QtCore.QRect(30, 145, 113, 20))
        self.step_time_txt.setText("")
        self.step_time_txt.setObjectName("step_time_txt")
        self.step_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.step_time_lab.setGeometry(QtCore.QRect(35, 130, 47, 13))
        self.step_time_lab.setObjectName("step_time_lab")
        self.tolerance_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.tolerance_lab.setGeometry(QtCore.QRect(35, 230, 47, 13))
        self.tolerance_lab.setObjectName("tolerance_lab")
        self.tolerance_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.tolerance_txt.setGeometry(QtCore.QRect(30, 245, 113, 20))
        self.tolerance_txt.setText("")
        self.tolerance_txt.setObjectName("tolerance_txt")
        self.max_iter_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.max_iter_lab.setGeometry(QtCore.QRect(35, 180, 70, 13))
        self.max_iter_lab.setObjectName("max_iter_lab")
        self.max_iter_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.max_iter_txt.setGeometry(QtCore.QRect(30, 195, 113, 20))
        self.max_iter_txt.setText("")
        self.max_iter_txt.setObjectName("max_iter_txt")

        self.retranslateUi(init_val_prob_dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), init_val_prob_dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), init_val_prob_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(init_val_prob_dialog)

    def retranslateUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setWindowTitle(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial value problem", None, -1))
        self.buttonBox.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "button box (OK cancel)", None, -1))
        self.int_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time text", None, -1))
        self.init_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time label", None, -1))
        self.init_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time", None, -1))
        self.final_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time text", None, -1))
        self.final_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time label", None, -1))
        self.final_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time", None, -1))
        self.step_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time text", None, -1))
        self.step_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time label", None, -1))
        self.step_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time", None, -1))
        self.tolerance_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance label", None, -1))
        self.tolerance_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance", None, -1))
        self.tolerance_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance text", None, -1))
        self.max_iter_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations label", None, -1))
        self.max_iter_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations", None, -1))
        self.max_iter_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations text", None, -1))

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__
        self.setupUi
        self.show

ivpDia = init_val_prob_dialog()
ivpDia.show
vocx
Posts: 1912
Joined: Thu Oct 18, 2018 9:18 pm

Re: dialog box will not show

Postby vocx » Wed Sep 11, 2019 1:04 am

mfasano wrote:
Wed Sep 11, 2019 12:05 am

Code: Select all

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__
        self.setupUi
        self.show

ivpDia = init_val_prob_dialog()
ivpDia.show
These are functions, right? So you should call them.

Code: Select all

        super(init_val_prob_dialog, self).__init__()
        self.setupUi()
        self.show()
If you don't write the parentheses, you are just treating them as variables (they return the reference to their internal object).
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: dialog box will not show

Postby mfasano » Wed Sep 11, 2019 6:43 pm

vocx wrote:
Wed Sep 11, 2019 1:04 am

These are functions, right? So you should call them.

Code: Select all

        super(init_val_prob_dialog, self).__init__()
        self.setupUi()
        self.show()
If you don't write the parentheses, you are just treating them as variables (they return the reference to their internal object).
I tried that and I got an error that says I need an argument for setupUi(). I don't know what the argument shoud be for this method.

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 100, in <module>
    ivpDia = init_val_prob_dialog()
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 95, in __init__
    self.setupUi()
<class 'TypeError'>: setupUi() missing 1 required positional argument: 'init_val_prob_dialog'
vocx
Posts: 1912
Joined: Thu Oct 18, 2018 9:18 pm

Re: dialog box will not show

Postby vocx » Wed Sep 11, 2019 7:05 pm

mfasano wrote:
Wed Sep 11, 2019 6:43 pm
I tried that and I got an error that says I need an argument for setupUi(). I don't know what the argument shoud be for this method.
Did you write this code yourself, or was it created automatically from QtCreator or something like that?

The definition of the method within the class expects one argument init_val_prob_dialog

Code: Select all

class Ui_init_val_prob_dialog(object):
    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
...
The argument init_val_prob_dialog is exactly the name of the second class, so maybe in this second class you need to pass self, which is precisely a reference to itself (the init_val_prob_dialog class).

Code: Select all

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__()
        self.setupUi(self)
        self.show()
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: dialog box will not show

Postby mfasano » Thu Sep 12, 2019 12:38 pm

Thanks vocx for the help.

The class Ui_init_val_prob_dialog(object) is generated using pyside2-uic from a UI file. the other class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog) is something I copied from somewhere.

including self as an argument in .setupUi worked. Now it has a problem with strings in the class Ui_init_val_prob_dialog(object). It is strange because this is Qt generated code. I think Qt has their prefered type for strings.

the error message i get

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 100, in <module>
    ivpDia = init_val_prob_dialog()
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 95, in __init__
    self.setupUi(self)
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 24, in setupUi
    init_val_prob_dialog.setObjectName("init_val_prob_dialog")
<class 'RuntimeError'>: '__init__' method of object's base class (init_val_prob_dialog) not called.

offending code

Code: Select all

class Ui_init_val_prob_dialog(object):
    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
        
mario52
Posts: 2693
Joined: Wed May 16, 2012 2:13 pm

Re: dialog box will not show

Postby mario52 » Thu Sep 12, 2019 1:30 pm

hi

tray this "essais"

Code: Select all

# -*- coding: utf-8 -*-
#from __future__ import unicode_literals
# Squelette du programme.py avec " setupUi "
# il faut que le widget s'appelle MainWindow
#
"""
***************************************************************************
*   Copyright (c)  xxxx <name>                      *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
**                                                                       **
*   Use at your own risk. The author assumes no liability for data loss.  *
*              It is advised to backup your data frequently.              *
*             If you do not trust the software do not use it.             *
**                                                                       **
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
#Macro_Spring_Helix_Variable 10/11/2014 /_03
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.18024 (Git)
#Build type: Release
#Branch: master
#Hash: 9cc8f6eb666b0a0ae2dc256f7bc0beb8c987710c
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
#
__title__   = "Titre"
__author__  = "Auteur"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = "http://www.freecadweb.org/wiki/index.php?title="
__version__ = "00.00"
__date__    = "04/05/2019"

import PySide2
from PySide2 import QtGui ,QtCore, QtWidgets
from PySide2.QtGui import *
from PySide2.QtCore import *

import time
import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
import math
from math import sqrt, pi, sin, cos, asin

Gui = FreeCADGui
App = FreeCAD


##############################################################################
#####paste here class Ui_MainWindow(object) begin#############################
#______________________________________________________________________________________
# mettre le code QT ici dessous #______________________________________________________
#______________________________________________________________________________________
        
class Ui_MainWindow(object):

    def __init__(self ):
        self.window = MainWindow
        #self.path  = FreeCAD.ConfigGet("AppHomePath")
        #self.path  = FreeCAD.ConfigGet("UserAppData")
        #self.path  = "your path"
        param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
        self.path = param.GetString("MacroPath","") + "/"                   # macro path
        self.path = self.path.replace("\\","/")
#        print("Path for the icons : " , self.path)

    def setupUi(self, MainWindow):
        self.window = MainWindow
#______________________________________________________________________________________
# mettre le code QT ici dessous #______________________________________________________
#______________________________________________________________________________________
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(400, 300)

        self.PB_Quit = QtWidgets.QPushButton(MainWindow)
        self.PB_Quit.setGeometry(QtCore.QRect(215, 240, 156, 32))
        self.PB_Quit.setObjectName("PB_Quit")
        self.PB_Quit.clicked.connect(self.on_PB_Quit_clicked) ###

        self.PB_Validate = QtWidgets.QPushButton(MainWindow)
        self.PB_Validate.setGeometry(QtCore.QRect(215, 200, 156, 32))
        self.PB_Validate.setObjectName("PB_Validate")
        self.PB_Validate.clicked.connect(self.on_PB_Validate_clicked) ###

        self.int_time_txt = QtWidgets.QLineEdit(MainWindow)
        self.int_time_txt.setGeometry(QtCore.QRect(30, 45, 113, 20))
        self.int_time_txt.setText("")
        self.int_time_txt.setObjectName("int_time_txt")

        self.init_time_lab = QtWidgets.QLabel(MainWindow)
        self.init_time_lab.setGeometry(QtCore.QRect(35, 30, 47, 13))
        self.init_time_lab.setObjectName("init_time_lab")

        self.final_time_txt = QtWidgets.QLineEdit(MainWindow)
        self.final_time_txt.setGeometry(QtCore.QRect(30, 95, 113, 20))
        self.final_time_txt.setText("")
        self.final_time_txt.setObjectName("final_time_txt")

        self.final_time_lab = QtWidgets.QLabel(MainWindow)
        self.final_time_lab.setGeometry(QtCore.QRect(35, 80, 47, 13))
        self.final_time_lab.setObjectName("final_time_lab")

        self.step_time_txt = QtWidgets.QLineEdit(MainWindow)
        self.step_time_txt.setGeometry(QtCore.QRect(30, 145, 113, 20))
        self.step_time_txt.setText("")
        self.step_time_txt.setObjectName("step_time_txt")

        self.step_time_lab = QtWidgets.QLabel(MainWindow)
        self.step_time_lab.setGeometry(QtCore.QRect(35, 130, 47, 13))
        self.step_time_lab.setObjectName("step_time_lab")

        self.tolerance_lab = QtWidgets.QLabel(MainWindow)
        self.tolerance_lab.setGeometry(QtCore.QRect(35, 230, 47, 13))
        self.tolerance_lab.setObjectName("tolerance_lab")

        self.tolerance_txt = QtWidgets.QLineEdit(MainWindow)
        self.tolerance_txt.setGeometry(QtCore.QRect(30, 245, 113, 20))
        self.tolerance_txt.setText("")
        self.tolerance_txt.setObjectName("tolerance_txt")

        self.max_iter_lab = QtWidgets.QLabel(MainWindow)
        self.max_iter_lab.setGeometry(QtCore.QRect(35, 180, 70, 13))
        self.max_iter_lab.setObjectName("max_iter_lab")

        self.max_iter_txt = QtWidgets.QLineEdit(MainWindow)
        self.max_iter_txt.setGeometry(QtCore.QRect(30, 195, 113, 20))
        self.max_iter_txt.setText("")
        self.max_iter_txt.setObjectName("max_iter_txt")

        self.retranslateUi(MainWindow)

    def retranslateUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setWindowTitle(QtWidgets.QApplication.translate("Ui_MainWindow", "initial value problem", None, -1))

        self.PB_Quit.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "Quit", None, -1))
        self.PB_Validate.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "Validate", None, -1))

        self.int_time_txt.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "initial time text", None, -1))
        self.init_time_lab.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "initial time label", None, -1))
        self.init_time_lab.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "initial time", None, -1))
        self.final_time_txt.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "final time text", None, -1))
        self.final_time_lab.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "final time label", None, -1))
        self.final_time_lab.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "final time", None, -1))
        self.step_time_txt.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "step time text", None, -1))
        self.step_time_lab.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "step time label", None, -1))
        self.step_time_lab.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "step time", None, -1))
        self.tolerance_lab.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "tolerance label", None, -1))
        self.tolerance_lab.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "tolerance", None, -1))
        self.tolerance_txt.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "tolerance text", None, -1))
        self.max_iter_lab.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "max iterations label", None, -1))
        self.max_iter_lab.setText(QtWidgets.QApplication.translate("Ui_MainWindow", "max iterations", None, -1))
        self.max_iter_txt.setAccessibleName(QtWidgets.QApplication.translate("Ui_MainWindow", "max iterations text", None, -1))

#______________________________________________________________________________________
# mettre le code QT ici dessus  #______________________________________________________
#______________________________________________________________________________________

        MainWindow.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", __title__+" ("+__version__+", "+__date__+")"))
#        MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)                # PySide2 cette fonction met la fenetre en avant
        MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)        # PySide2 cette fonction met la fenetre en avant

#______________________________________________________________________________________
# mettre le code PY ici dessous #______________________________________________________
#______________________________________________________________________________________

    def on_PB_Quit_clicked(self):
        self.window.hide()                                                  # hide the window and close the macro
        print("Quit ")

    def on_PB_Validate_clicked(self):
        print("Hello Welcome to FreeCAD")

#####paste here class Ui_MainWindow(object) begin#############################
##############################################################################

doc = FreeCAD.ActiveDocument
if doc == None:
    doc = FreeCAD.newDocument()

MainWindow = QtWidgets.QWidget()    #PySide2
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()


mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
vocx
Posts: 1912
Joined: Thu Oct 18, 2018 9:18 pm

Re: dialog box will not show

Postby vocx » Thu Sep 12, 2019 4:49 pm

mfasano wrote:
Thu Sep 12, 2019 12:38 pm
the error message i get

Code: Select all

    init_val_prob_dialog.setObjectName("init_val_prob_dialog")
<class 'RuntimeError'>: '__init__' method of object's base class (init_val_prob_dialog) not called.
Well, this doesn't mention anything about strings.

What I do notice is your first class doesn't have an __init__() method. Maybe define one?

Code: Select all

class Ui_init_val_prob_dialog(object):
    def __init__(self):
        pass

    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
        
The second class inherits from the first class. What the following instruction does is that inside its own __init__() function, first it calls the __init__() function of the parent class. Therefore, the parent's __init__() must exist.

Code: Select all

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__()
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: dialog box will not show

Postby mfasano » Fri Sep 13, 2019 6:29 pm

I found that the argument for .setupUi() should be QtWidgets.QDialog as Mario does.

Code: Select all

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__
        self.setupUi(QtWidgets.QDialog)
now I get this error

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 96, in <module>
    ivpDia = init_val_prob_dialog()
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 94, in __init__
    self.setupUi(QtWidgets.QDialog)
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 24, in setupUi
    init_val_prob_dialog.setObjectName("init_val_prob_dialog")
<class 'TypeError'>: descriptor 'setObjectName' requires a 'PySide2.QtCore.QObject' object but received a 'str'

I don't understand this; the argument for .setObjectName is supposed to be unicode. I thought python strings were unicode.
vocx
Posts: 1912
Joined: Thu Oct 18, 2018 9:18 pm

Re: dialog box will not show

Postby vocx » Fri Sep 13, 2019 7:15 pm

mfasano wrote:
Fri Sep 13, 2019 6:29 pm
I found that the argument for .setupUi() should be QtWidgets.QDialog as Mario does.

Code: Select all

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__
        self.setupUi(QtWidgets.QDialog)
Where did you find this information? Are you just trying things?

Forget about other code; in your code the setupUi() function needs an init_val_prob_dialog. This is the current class, so you need to use self.

Look, this runs in my system.

Code: Select all

from PySide2 import QtCore, QtGui, QtWidgets
import FreeCADGui as Gui
import FreeCAD as App

# from init_val_prob_dia import Ui_init_val_prob_dialog
class Ui_init_val_prob_dialog(object):
    def __init__(self):
        pass

    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
        init_val_prob_dialog.resize(400, 300)
        self.buttonBox = QtWidgets.QDialogButtonBox(init_val_prob_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(215, 240, 156, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.int_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.int_time_txt.setGeometry(QtCore.QRect(30, 45, 113, 20))
        self.int_time_txt.setText("")
        self.int_time_txt.setObjectName("int_time_txt")
        self.init_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.init_time_lab.setGeometry(QtCore.QRect(35, 30, 47, 13))
        self.init_time_lab.setObjectName("init_time_lab")
        self.final_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.final_time_txt.setGeometry(QtCore.QRect(30, 95, 113, 20))
        self.final_time_txt.setText("")
        self.final_time_txt.setObjectName("final_time_txt")
        self.final_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.final_time_lab.setGeometry(QtCore.QRect(35, 80, 47, 13))
        self.final_time_lab.setObjectName("final_time_lab")
        self.step_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.step_time_txt.setGeometry(QtCore.QRect(30, 145, 113, 20))
        self.step_time_txt.setText("")
        self.step_time_txt.setObjectName("step_time_txt")
        self.step_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.step_time_lab.setGeometry(QtCore.QRect(35, 130, 47, 13))
        self.step_time_lab.setObjectName("step_time_lab")
        self.tolerance_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.tolerance_lab.setGeometry(QtCore.QRect(35, 230, 47, 13))
        self.tolerance_lab.setObjectName("tolerance_lab")
        self.tolerance_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.tolerance_txt.setGeometry(QtCore.QRect(30, 245, 113, 20))
        self.tolerance_txt.setText("")
        self.tolerance_txt.setObjectName("tolerance_txt")
        self.max_iter_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.max_iter_lab.setGeometry(QtCore.QRect(35, 180, 70, 13))
        self.max_iter_lab.setObjectName("max_iter_lab")
        self.max_iter_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.max_iter_txt.setGeometry(QtCore.QRect(30, 195, 113, 20))
        self.max_iter_txt.setText("")
        self.max_iter_txt.setObjectName("max_iter_txt")

        self.retranslateUi(init_val_prob_dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), init_val_prob_dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), init_val_prob_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(init_val_prob_dialog)

    def retranslateUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setWindowTitle(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial value problem", None, -1))
        self.buttonBox.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "button box (OK cancel)", None, -1))
        self.int_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time text", None, -1))
        self.init_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time label", None, -1))
        self.init_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time", None, -1))
        self.final_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time text", None, -1))
        self.final_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time label", None, -1))
        self.final_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time", None, -1))
        self.step_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time text", None, -1))
        self.step_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time label", None, -1))
        self.step_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time", None, -1))
        self.tolerance_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance label", None, -1))
        self.tolerance_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance", None, -1))
        self.tolerance_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance text", None, -1))
        self.max_iter_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations label", None, -1))
        self.max_iter_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations", None, -1))
        self.max_iter_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations text", None, -1))

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__()
        self.setupUi(self)
        self.show()

ivpDia = init_val_prob_dialog()
ivpDia.show()
Is this what you want?
Qt_dialog.png
Qt_dialog.png (13.4 KiB) Viewed 328 times
I'm using Qt 5.9.5. Maybe your version of Qt is different and thus it fails on something.

Code: Select all

OS: Ubuntu 18.04.3 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18195 +1 (Git)
Build type: Unknown
Branch: Draft_CubicBezCurve
Hash: 329863111c71285f59db471a783b46d345688d30
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: dialog box will not show

Postby mfasano » Mon Sep 16, 2019 11:24 pm

I thought I would try reinstalling FreeCad.

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/UnitedStates (en_US)

It said no module named pyside2 at the line for import.

I tried to install pyside2 with pip install. I made the environment path so freecad python was used. I also used sys.path.append to include freecad directories.

I guess I am moving backwards.

Code: Select all

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'init_val_prob.ui',
# licensing of 'init_val_prob.ui' applies.
#
#      by: pyside2-uic  running on PySide2 5.13.0
#
# WARNING! All changes made in this file will be lost!

import os
import sys
sys.path.append('''C:\\Program Files\\FreeCAD 0.18\\bin''')



sys.path.append('''C:\\Program Files\\FreeCAD 0.18\\bin\\Scripts''')
sys.path.append('''C:\\Program Files\\FreeCAD 0.18\\Ext''')
# Created: Wed Aug 14 12:55:13 2019')
# from init_val_prob_dia import Ui_init_val_prob_dialog
import FreeCAD as App







from pyside2 import QtCore, QtGui, QtWidgets
import FreeCADGui as Gui
class Ui_init_val_prob_dialog(object):
    def setupUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setObjectName("init_val_prob_dialog")
        init_val_prob_dialog.resize(400, 300)
        self.buttonBox = QtWidgets.QDialogButtonBox(init_val_prob_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(215, 240, 156, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.int_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.int_time_txt.setGeometry(QtCore.QRect(30, 45, 113, 20))
        self.int_time_txt.setText("")
        self.int_time_txt.setObjectName("int_time_txt")
        self.init_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.init_time_lab.setGeometry(QtCore.QRect(35, 30, 47, 13))
        self.init_time_lab.setObjectName("init_time_lab")
        self.final_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.final_time_txt.setGeometry(QtCore.QRect(30, 95, 113, 20))
        self.final_time_txt.setText("")
        self.final_time_txt.setObjectName("final_time_txt")
        self.final_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.final_time_lab.setGeometry(QtCore.QRect(35, 80, 47, 13))
        self.final_time_lab.setObjectName("final_time_lab")
        self.step_time_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.step_time_txt.setGeometry(QtCore.QRect(30, 145, 113, 20))
        self.step_time_txt.setText("")
        self.step_time_txt.setObjectName("step_time_txt")
        self.step_time_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.step_time_lab.setGeometry(QtCore.QRect(35, 130, 47, 13))
        self.step_time_lab.setObjectName("step_time_lab")
        self.tolerance_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.tolerance_lab.setGeometry(QtCore.QRect(35, 230, 47, 13))
        self.tolerance_lab.setObjectName("tolerance_lab")
        self.tolerance_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.tolerance_txt.setGeometry(QtCore.QRect(30, 245, 113, 20))
        self.tolerance_txt.setText("")
        self.tolerance_txt.setObjectName("tolerance_txt")
        self.max_iter_lab = QtWidgets.QLabel(init_val_prob_dialog)
        self.max_iter_lab.setGeometry(QtCore.QRect(35, 180, 70, 13))
        self.max_iter_lab.setObjectName("max_iter_lab")
        self.max_iter_txt = QtWidgets.QLineEdit(init_val_prob_dialog)
        self.max_iter_txt.setGeometry(QtCore.QRect(30, 195, 113, 20))
        self.max_iter_txt.setText("")
        self.max_iter_txt.setObjectName("max_iter_txt")

        self.retranslateUi(init_val_prob_dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), init_val_prob_dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), init_val_prob_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(init_val_prob_dialog)

    def retranslateUi(self, init_val_prob_dialog):
        init_val_prob_dialog.setWindowTitle(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial value problem", None, -1))
        self.buttonBox.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "button box (OK cancel)", None, -1))
        self.int_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time text", None, -1))
        self.init_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time label", None, -1))
        self.init_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "initial time", None, -1))
        self.final_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time text", None, -1))
        self.final_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time label", None, -1))
        self.final_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "final time", None, -1))
        self.step_time_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time text", None, -1))
        self.step_time_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time label", None, -1))
        self.step_time_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "step time", None, -1))
        self.tolerance_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance label", None, -1))
        self.tolerance_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance", None, -1))
        self.tolerance_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "tolerance text", None, -1))
        self.max_iter_lab.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations label", None, -1))
        self.max_iter_lab.setText(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations", None, -1))
        self.max_iter_txt.setAccessibleName(QtWidgets.QApplication.translate("init_val_prob_dialog", "max iterations text", None, -1))

class init_val_prob_dialog(QtWidgets.QDialog, Ui_init_val_prob_dialog):
    def __init__(self):
        super(init_val_prob_dialog, self).__init__
        self.setupUi(self)

ivpDia = init_val_prob_dialog()
ivpDia.show()

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Matt/AppData/Roaming/FreeCAD/dialogtest.FCMacro", line 26, in <module>
    from pyside2 import QtCore, QtGui, QtWidgets
<class 'ModuleNotFoundError'>: No module named 'pyside2'