I think your code is pretty messy, to start with, making it harder to work with. Take a look at some of my code, because I am sure it will help you.
main.py:
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: This is the main entry point of the oprg application
from PyQt4 import QtCore, QtGui
from os import sep
from map_engine.map_dock import MapDock
from chat_engine.chat_dock import ChatDock
from net_engine.plist_dock import PListDock
from net_engine.client_gear import ClientGear
from tree_engine.tree_dock import TreeDock
from tool_gears.path_gear import PathTool, path
PathTool().load_paths(path)
def __init__(self):
super(MainWindow, self).__init__()
self.
setWindowIcon(QtGui.
QIcon(path
['core_images'] + 'traipse-logo-2.png')) self.client = ClientGear(self)
self.createActions()
self.createDocks()
self.StatusBar('Ready')
self.createToolBar()
self.createStyle()
self.setCentralWidget(self.center1)
def createDocks(self):
#Game Tree Docking Bay
self.
treeDock = QtGui.
QDockWidget("Dock-Game Tree", self
) self.center4 = TreeDock(self, self.client)
self.treeDock.setWidget(self.center4)
self.
treeDock.
setFeatures(QtGui.
QDockWidget.
DockWidgetMovable |
self.center4.add('Child-2')
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.treeDock)
#Player List Docking Bay
self.
PlayerList = QtGui.
QDockWidget("Dock-Player List", self
) self.center3 = PListDock(self, self.client)
self.PlayerList.setWidget(self.center3)
self.
PlayerList.
setFeatures(QtGui.
QDockWidget.
DockWidgetMovable |
self.center3.add(2, 'Player-2', 'Idle')
self.center3.add(3, 'Player-3', 'Typing')
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.PlayerList)
#Map Docking Bay
self.center1 = MapDock(self, self.client)
self.mapDock.setWidget(self.center1)
self.
mapDock.
setFeatures(QtGui.
QDockWidget.
DockWidgetMovable |
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.mapDock)
self.mapDock.hide()
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: This is the main entry point of the oprg application
from PyQt4 import QtCore, QtGui
from os import sep
from map_engine.map_dock import MapDock
from chat_engine.chat_dock import ChatDock
from net_engine.plist_dock import PListDock
from net_engine.client_gear import ClientGear
from tree_engine.tree_dock import TreeDock
from tool_gears.path_gear import PathTool, path
PathTool().load_paths(path)
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowIcon(QtGui.QIcon(path['core_images'] + 'traipse-logo-2.png'))
self.client = ClientGear(self)
self.createActions()
self.createDocks()
self.StatusBar('Ready')
self.createToolBar()
self.createStyle()
self.setCentralWidget(self.center1)
def createDocks(self):
#Game Tree Docking Bay
self.treeDock = QtGui.QDockWidget("Dock-Game Tree", self)
self.center4 = TreeDock(self, self.client)
self.treeDock.setWidget(self.center4)
self.treeDock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
QtGui.QDockWidget.DockWidgetFloatable)
self.center4.add('Child-2')
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.treeDock)
#Player List Docking Bay
self.PlayerList = QtGui.QDockWidget("Dock-Player List", self)
self.center3 = PListDock(self, self.client)
self.PlayerList.setWidget(self.center3)
self.PlayerList.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
QtGui.QDockWidget.DockWidgetFloatable)
self.center3.add(2, 'Player-2', 'Idle')
self.center3.add(3, 'Player-3', 'Typing')
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.PlayerList)
#Map Docking Bay
self.mapDock = QtGui.QDockWidget("Dock-Map", self)
self.center1 = MapDock(self, self.client)
self.mapDock.setWidget(self.center1)
self.mapDock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
QtGui.QDockWidget.DockWidgetFloatable)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.mapDock)
self.mapDock.hide()
To copy to clipboard, switch view to plain text mode
This is the Main file. This is my anchor to all my other UI scripts. This is not a complete version, but here you can see I am creating a proxy Player List and proxy Game Tree. I want you to look at the Map Docking Bay. It inserts the MapDock class, passing the parent and the future network client.
map_dock.py
from PyQt4 import QtCore, QtGui
from tool_gears.path_gear import path
from map_engine.tool_gear import mapToolGear
from map_engine.map_gear import MapDocket
def __init__(self, parent, client):
super(MapDock, self).__init__()
self.parent = parent; self.client = client
self.createMap()
self.createToolBar()
self.setCentralWidget(self.mapDocket)
def createToolBar(self):
self.ToolBay = mapToolGear(self.parent)
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.ToolBay)
## Map Docket
def createMap(self):
self.mapView = MapDocket()
layout.addWidget(self.mapView)
self.mapDocket.setLayout(layout)
def createMapEditor(self):
self.
parent.
mapEditor = QtGui.
QDialog() self.parent.mapEditView = MapDocket()
layout.addWidget(self.parent.mapEditView)
self.parent.mapEditor.setLayout(layout)
self.parent.mapEditor.show()
def empty(self):
pass
from PyQt4 import QtCore, QtGui
from tool_gears.path_gear import path
from map_engine.tool_gear import mapToolGear
from map_engine.map_gear import MapDocket
class MapDock(QtGui.QMainWindow):
def __init__(self, parent, client):
super(MapDock, self).__init__()
self.parent = parent; self.client = client
self.createMap()
self.createToolBar()
self.setCentralWidget(self.mapDocket)
def createToolBar(self):
self.ToolBay = mapToolGear(self.parent)
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.ToolBay)
## Map Docket
def createMap(self):
self.mapDocket = QtGui.QWidget()
layout = QtGui.QGridLayout()
self.mapView = MapDocket()
layout.addWidget(self.mapView)
self.mapDocket.setLayout(layout)
def createMapEditor(self):
self.parent.mapEditor = QtGui.QDialog()
layout = QtGui.QGridLayout()
self.parent.mapEditView = MapDocket()
layout.addWidget(self.parent.mapEditView)
self.parent.mapEditor.setLayout(layout)
self.parent.mapEditor.show()
def empty(self):
pass
To copy to clipboard, switch view to plain text mode
Here is the entirety of my map_dock file, which contains the MapDock class. Can you see how I am re using the MapDocket() class to create a map for the core software and a map for the map editor? Maybe I am wrong, but I think that is what you are trying to do. Notice how the second one is rooted in the parent?
I would suggest you look at your Ui_Dialog Classes. They don't need to declared (object), the should be declared (QtGui.QDialog). I am also not sure why you would create a setupUI function and not use the pre-built __init__ function. I would suggest you use __init__ and then you can create room for you parent object, plus you can build the UI just by calling the class each time.
Bookmarks