Question

I'm using python 2.7 and PyQt4 and Windows 7.

I have 3 python scripts:

a simple calculator one that shorts a long url: i did it with the bitly API and one that take the text in the clipboard and return the same text but without spaces (something i use at work). I have created a main app to be able to manage those 3. Open, close reopen, etc., inside a MDI area but when I open and close an app and try to open another one it send an error: "QMdiArea::addSubWindow: window is already added". And when i close the main app the system send a "python.exe stop working" error. Some light over this please.

This is the code i'm using to the main app. I take any suggestions

import sys
from PyQt4 import QtGui, QtCore
from gestor import Ui_frmPrincipal
from calculadora1 import Calc
from URL_Short import URL_Short
from sinespacios import SinEs

class Win1(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.vtn = Ui_frmPrincipal()
        self.vtn.setupUi(self)
        self.subwindow = QtGui.QMdiSubWindow()
        self.subwindow.setMinimumSize(400, 200)


        self.calc = Calc()
        self.urls = URL_Short()
        self.sine = SinEs()


        self.connect(self.vtn.btnSalir, QtCore.SIGNAL('clicked()'), QtCore.SLOT('close()'))
        self.connect(self.vtn.btnCalc, QtCore.SIGNAL('clicked()'), self.OpenCalc)
        self.connect(self.vtn.btnPegar, QtCore.SIGNAL('clicked()'), self.OpenPaster)
        self.connect(self.vtn.btnShortu, QtCore.SIGNAL('clicked()'), self.OpenShortURL)

    def OpenCalc(self):
        if self.vtn.mdiApps.activeSubWindow() is None:
            self.subwindow.setWidget(self.calc)
            self.vtn.mdiApps.addSubWindow(self.subwindow)
            self.subwindow.show()
            self.subwindow.widget().show()


    def OpenPaster(self):
        if self.vtn.mdiApps.activeSubWindow() is None:
            self.subwindow.setWidget(self.sine)
            self.vtn.mdiApps.addSubWindow(self.subwindow)
            self.subwindow.show()
            self.subwindow.widget().show()

    def OpenShortURL(self):
        if self.vtn.mdiApps.activeSubWindow() is None:
            self.subwindow.setWidget(self.urls)
            self.vtn.mdiApps.addSubWindow(self.subwindow)
            self.subwindow.show()
            self.subwindow.widget().show()



if __name__=='__main__':
    app = QtGui.QApplication(sys.argv)
    win = Win1()
    win.show()
    sys.exit(app.exec_())
Was it helpful?

Solution

Well I found the answer...

all I did was to eliminate the minimum size

self.subwindow.setMinimumSize(400, 200)

create a function for closing subwindows:

def closeIt(self):
        self.vtn.mdiApps.removeSubWindow(self.subwindow)

and modified each function, for example with the OpenCalc function:

def OpenCalc(self):

    a = self.calc.height() + 20
    b = self.calc.width()

    if self.vtn.mdiApps.activeSubWindow() is None:

        self.subwindow.setMinimumSize(b, a)
        self.subwindow.setWidget(self.calc)
        self.vtn.mdiApps.addSubWindow(self.subwindow)
        self.subwindow.show()
        self.subwindow.widget().show()

after that everything is in working order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top