View Single Post
Posts: 47 | Thanked: 41 times | Joined on Jan 2010 @ Finland
#1
Hello, I have a question about PyQt and specially about QTabWidget. I have rewriten most of my application (pyKake) from GTK to PyQt and faced a problem I can't get solved (without restarting the app) by myself. The problem is that I want to hide some of the tabs or show them after the gui is loaded (Example, if I change the camera type from settings, from Canon to Olympus, I want to show a Viewer tab, and in the reverse situation I want to hide it).

My code looks like this:

Code:
class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        # ...
        
        # Creating tabs and using tab widget as a Central widget
        self.tabs = QtGui.QTabWidget()
        self.tabs.TabShape(QtGui.QTabWidget.Rounded)
        self.tabs.addTab(BasicMode(), "Basic") # index = 0
        self.tabs.addTab(BulbMode(), "Bulb") # index = 1
        self.tabs.addTab(TimedMode(), "Timed") # index = 2
        self.tabs.addTab(ViewerMode(), "Viewer") # index = 3
        self.tabs.addTab(SystemPage(), "System") # index = 4
        self.tabHandler("startup")
        
        self.setCentralWidget(self.tabs)

    def tabHandler(self, data):
        print "Start managing tabs"
        
        if data == "startup":
            print "Managing state: StartUp"
            if USEFULLSCREEN != True:
                print "State: No Fullscreen \n   Action: Removing SystemTab"
                self.tabs.removeTab(4)
            if CURRENT_REMOTETYPE != "Olympus_RM-1":
                print "State: No olympus \n   Action: Removing ViewerTab"
                self.tabs.removeTab(3)
                
        if data == "settings":
            print "Managing state: SettingsChange"
            if CURRENT_REMOTETYPE != "Olympus_RM-1":
                print "State: No Olympus\n   Action: removing ViewerTab"
                self.tabs.removeTab(3)
            if CURRENT_REMOTETYPE == "Olympus_RM-1" and USEFULLSCREEN == True:
                print "State: is Olympus, is Fullscreen \n   Action: removing SystemTab, adding ViewerTab, adding SystemTab"
                self.tabs.removeTab(4)
                self.tabs.addTab(ViewerMode(), "Viewer")
                self.tabs.addTab(SystemPage(), "System")
            elif CURRENT_REMOTETYPE == "Olympus_RM-1" and USEFULLSCREEN != True:
                print "State: is Olympus, no Fullscreen \n   Action: adding ViewerTab"
                self.tabs.addTab(ViewerMode(), "Viewer")
        
        self.tabs.update()
        print "Managing tabs stopped!"
# ...

class SettingsDialog(QtGui.QDialog):
    def setSettings(self):
        # ...
        MainWindow().tabHandler("settings")
        settings.sync()

        self.accept()
On the startup function tabHandler work as it should work, it prints out those control messages and removes pages I don't need (or do nothing if there is no need for it). But then, when I later change settings from settings dialog nothing happens. The code itself works as it should do in tabHandler (I get all the control messages I'm waiting for) but GUI won't change, it stays the same as it was loaded in the begining. (self.update() or self.tabs.update() won't work, neither does leaving it out). Hopefully you understand what I try to say.

I know the solution is probably something very basic I just can't get it by myself.