Esempio n. 1
0
    def runWizard(self):
        self.wizard = Wizard()
        self.wizard.setWindowIcon(QIcon("./images/projectnew.png"))

        if self.wizard.exec_():
            #print "complete"
            self.project = self.wizard.project
            self.setWindowTitle("PopGen: Version-1.1 (%s)" %
                                (self.project.name))
            self.project.save()
            self.fileManager.project = self.project
            self.fileManager.populate()
            self.enableFunctions(True)
Esempio n. 2
0
    def runWizard(self):
        self.wizard = Wizard()
        self.wizard.setWindowIcon(QIcon("./images/projectnew.png"))

        if self.wizard.exec_():
            # print "complete"
            self.project = self.wizard.project
            self.setWindowTitle("PopGen: Version-1.1 (%s)" % (self.project.name))
            self.project.save()
            self.fileManager.project = self.project
            self.fileManager.populate()
            self.enableFunctions(True)
Esempio n. 3
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        import pp

        ppservers = ()
        if len(sys.argv) > 1:
            ncpus = int(sys.argv[1])
            self.job_server = pp.Server(ncpus, ppservers=ppservers, restart=True)
        else:
            self.job_server = pp.Server(ppservers=ppservers, restart=True)

        # print dir(self.job_server)

        # print 'number of workers', self.job_server.get_ncpus()
        # self.job_server.set_ncpus(1)
        # print 'number of workers', self.job_server.get_ncpus()

        self.dirty = False
        self.projectName = None

        self.setWindowTitle("PopGen Version-1.1")
        self.setWindowIcon(QIcon("./images/popsyn.png"))
        self.workingWindow = QLabel()
        self.showMaximized()
        self.setMinimumSize(800, 500)
        self.workingWindow.setAlignment(Qt.AlignCenter)
        bkground = QPixmap("./images/background.png")
        self.workingWindow.setPixmap(bkground)
        self.workingWindow.setScaledContents(True)
        self.setCentralWidget(self.workingWindow)

        self.sizeLabel = QLabel()
        self.sizeLabel.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
        status = self.statusBar()
        status.setSizeGripEnabled(False)
        status.addPermanentWidget(self.sizeLabel)
        status.showMessage("Ready", 5000)

        # FILE MENU
        # Defining menu/toolbar actions
        projectNewAction = self.createAction(
            "&New Project", self.projectNew, QKeySequence.New, "projectnew", "Create a new PopGen project."
        )
        projectOpenAction = self.createAction(
            "&Open Project", self.projectOpen, QKeySequence.Open, "projectopen", "Open an existing PopGen project."
        )
        self.projectSaveAction = self.createAction(
            "&Save Project", self.projectSave, QKeySequence.Save, "projectsave", "Save the current PopGen project."
        )
        self.projectSaveAsAction = self.createAction(
            "Save Project &As...",
            self.projectSaveAs,
            icon="projectsaveas",
            tip="Save the current PopGen project with a new name.",
        )
        self.projectCloseAction = self.createAction(
            "&Close Project", self.projectClose, "Ctrl+W", tip="Close the current PopGen project."
        )
        applicationQuitAction = self.createAction(
            "&Quit", self.close, "Ctrl+Q", icon="quit", tip="Close the application."
        )

        self.projectSaveAction.setEnabled(False)
        self.projectSaveAsAction.setEnabled(False)
        self.projectCloseAction.setEnabled(False)

        # Adding actions to menu
        self.fileMenu = self.menuBar().addMenu("&File")
        # self.addActions(self.fileMenu, (projectNewAction, projectOpenAction, None, self.projectSaveAction,
        #                                   self.projectSaveAsAction, None, self.projectCloseAction, None, applicationQuitAction))
        self.addActions(
            self.fileMenu,
            (
                projectNewAction,
                projectOpenAction,
                None,
                self.projectSaveAction,
                None,
                self.projectCloseAction,
                None,
                applicationQuitAction,
            ),
        )
        # Adding actions to toolbar
        self.fileToolBar = self.addToolBar("File")
        self.fileToolBar.setObjectName("FileToolBar")
        # self.addActions(self.fileToolBar, (projectNewAction, projectOpenAction, self.projectSaveAction, self.projectSaveAsAction))
        self.addActions(self.fileToolBar, (projectNewAction, projectOpenAction, self.projectSaveAction))

        # DATA MENU
        # Defining menu/toolbar actions
        dataSourceAction = self.createAction(
            "Data Source &Connection", self.dataSource, icon="datasource", tip="Enter MySQL connection settings."
        )
        dataImportAction = self.createAction(
            "&Import", self.dataImport, icon="fileimport", tip="Import data into MySQL database."
        )
        # dataStatisticsAction = self.createAction("&Statistics", self.dataStatistics,
        #                                         icon="statistics", tip="Conduct descriptive analysis.")

        dataModifyAction = self.createAction(
            "&Display", self.dataModify, icon="modifydata", tip="View, analyze and modify the input data."
        )

        dataMargsHhldAction = self.createAction(
            "&Household", self.dataMargsHhld, tip="Modify the distribution of household variables of interest."
        )
        dataMargsGQAction = self.createAction(
            "&Groupquarter", self.dataMargsGQ, tip="Modify the distribution of household variables of interest."
        )
        dataMargsPersAction = self.createAction(
            "&Person", self.dataMargsPers, tip="Modify the distribution of household variables of interest."
        )

        # Adding actions to menu
        self.dataMenu = self.menuBar().addMenu("&Data")

        # self.addActions(self.dataMenu, (dataSourceAction, None, dataImportAction, dataStatisticsAction, dataModifyAction))
        self.addActions(self.dataMenu, (dataSourceAction, None, dataImportAction, dataModifyAction, None))

        self.dataMargsSubMenu = self.dataMenu.addMenu(QIcon("images/Marginals.png"), "Modify Marginals Distributions")
        self.addActions(self.dataMargsSubMenu, (dataMargsHhldAction, dataMargsGQAction, dataMargsPersAction))

        # Adding actions to toolbar
        self.dataToolBar = self.addToolBar("Data")
        self.dataToolBar.setObjectName("DataToolBar")
        # self.addActions(self.dataToolBar, (dataSourceAction,  dataImportAction, dataStatisticsAction, dataModifyAction))
        self.addActions(self.dataToolBar, (dataSourceAction, dataImportAction, dataModifyAction))

        self.dataMenu.setDisabled(True)
        self.dataToolBar.setDisabled(True)

        # SYNTHESIZER MENU
        # Defining menu/toolbar actions
        # synthesizerControlVariablesAction = self.createAction("Control &Variables", self.synthesizerControlVariables,
        #                                                      icon="controlvariables",
        #                                                      tip="Select variables to control.")
        setCorrespondenceAction = self.createAction(
            "Set Corresponding Variables",
            self.synthesizerSetCorrBetVariables,
            icon="varcorr",
            tip="""Select the variables and """
            """set the correspondence map between the variables """
            """in the sample file and variables in the control file.""",
        )
        synthesizerParameterAction = self.createAction(
            "&Parameters/Settings", self.synthesizerParameter, icon="parameters", tip="Set parameter values."
        )
        synthesizerRunAction = self.createAction("Run", self.synthesizerRun, icon="run", tip="Run synthesizer.")
        synthesizerStopAction = self.createAction(
            "Stop", self.synthesizerStop, icon="stop", tip="Stop the current population synthesis run."
        )
        # Adding actions to menu
        self.synthesizerMenu = self.menuBar().addMenu("&Synthesizer")
        # self.addActions(self.synthesizerMenu, (setCorrespondenceAction,
        #                                       synthesizerParameterAction, None,
        #                                       synthesizerRunAction, synthesizerStopAction))
        self.addActions(
            self.synthesizerMenu, (setCorrespondenceAction, synthesizerParameterAction, None, synthesizerRunAction)
        )
        # Adding actions to toolbar
        self.synthesizerToolBar = self.addToolBar("Synthesizer")
        # self.addActions(self.synthesizerToolBar, (synthesizerControlVariablesAction, synthesizerParameterAction,
        #                                          synthesizerRunAction))
        self.addActions(
            self.synthesizerToolBar, (setCorrespondenceAction, synthesizerParameterAction, synthesizerRunAction)
        )

        self.synthesizerMenu.setDisabled(True)
        self.synthesizerToolBar.setDisabled(True)

        self.scenarioComboBox = QComboBox()
        scenarioItems = ["Scenario - 1", "Scenario - 2", "Scenario - 3", "Scenario - 4", "Scenario - 5"]
        self.scenarioComboBox.addItems(scenarioItems)

        self.scenarioToolBar = self.addToolBar("Scenario")
        self.scenarioToolBar.addWidget(self.scenarioComboBox)
        self.scenarioToolBar.setDisabled(True)

        # RESULTS MENU
        # Defining menu/toolbar actions
        resultsRegionalAARDAction = self.createAction(
            "Average Absolute Relative Difference (AARD)",
            self.resultsRegionalAARD,
            tip="""Display the distribution of Average Absolute Relative Difference (AARD) """
            """across individual geographies.""",
        )
        resultsRegionalPValueAction = self.createAction(
            "p-Value",
            self.resultsRegionalPValue,
            tip="""Display the distribution of p-value """
            """for the synthetic population across individual geographies.""",
        )
        resultsRegionalHousDistAction = self.createAction(
            "Distribution of Housing Variables", self.resultsRegionalHousDist, tip="Comparison of housing variables."
        )
        resultsRegionalPersDistAction = self.createAction(
            "Distribution of Person Variables", self.resultsRegionalPersDist, tip="Comparison of person variables."
        )

        resultsRegionalAction = self.createAction(
            "Regional Geography Statistics",
            self.resultsRegional,
            icon="region",
            tip="Display performance statistics for the entire region.",
        )

        resultsIndividualAction = self.createAction(
            "&Individual Geography Statistics",
            self.resultsIndividual,
            icon="individualgeo",
            tip="Display performance statistics for individual geographies.",
        )

        resultsViewHHAction = self.createAction(
            "&View Households",
            self.resultsViewHH,
            icon="viewhh",
            tip="Display synthesized households for the entire region.",
        )

        resultsExportCSVAction = self.createAction(
            "Into &CSV Format", self.resultsCSVExport, tip="Export results into a comma-seperated file"
        )

        resultsExportTabAction = self.createAction(
            "Into &Tab-delimited Format", self.resultsTabExport, tip="Export results into a tab-delimited file"
        )

        resultsExportSummaryAction = self.createAction(
            "Summary Statistics",
            self.resultsExportSummary,
            tip="Export summary statistics for the synthetic population",
        )

        thematicMapsHhldAction = self.createAction(
            "Household",
            self.thematicMapsHhld,
            tip="""Display thematic maps of the synthetic population for """ """household attribute categories""",
        )

        thematicMapsGQAction = self.createAction(
            "Groupquarter",
            self.thematicMapsGQ,
            tip="""Display thematic maps of the synthetic population for """ """groupquarter attribute categories""",
        )

        thematicMapsPersonAction = self.createAction(
            "Person",
            self.thematicMapsPerson,
            tip="""Display thematic maps of the synthetic population for """ """person attribute categories""",
        )

        # Adding actions to menu
        self.resultsMenu = self.menuBar().addMenu("&Results")
        self.regionwideSubMenu = self.resultsMenu.addMenu(QIcon("images/region.png"), "Regional Statistics")
        self.addActions(
            self.regionwideSubMenu,
            (
                resultsRegionalAARDAction,
                resultsRegionalPValueAction,
                resultsRegionalHousDistAction,
                resultsRegionalPersDistAction,
            ),
        )

        self.addActions(self.resultsMenu, (resultsIndividualAction,))

        self.thematicMapsSubMenu = self.resultsMenu.addMenu(QIcon("images/thematic.png"), "&Thematic Maps")
        self.addActions(
            self.thematicMapsSubMenu, (thematicMapsHhldAction, thematicMapsGQAction, thematicMapsPersonAction)
        )

        self.addActions(self.resultsMenu, (None,))

        self.exportSubMenu = self.resultsMenu.addMenu(QIcon("images/export.png"), "&Export Synthetic Population Tables")
        self.addActions(
            self.exportSubMenu, (resultsExportCSVAction, resultsExportTabAction, None, resultsExportSummaryAction)
        )

        # self.addActions(self.resultsMenu, (resultsViewHHAction,))
        # Adding actions to toolbar

        # self.resultsToolBar = self.addToolBar("Results")
        # self.resultsToolBar.addToolBar(QIcon("Regional SubMenu"))
        # self.addActions(self.resultsToolBar, (resultsRegionalAction, resultsIndividualAction))

        self.resultsMenu.setDisabled(True)
        # self.resultsToolBar.setDisabled(True)

        # HELP MENU
        # Defining menu/toolbar actions

        helpDocumentationAction = self.createAction(
            "Documentation", self.showDocumentation, tip="Display the documentation of PopGen.", icon="documentation"
        )
        helpHelpAction = self.createAction(
            "Help", self.showHelp, tip="Quick reference for important parameters.", icon="help"
        )

        helpAboutAction = self.createAction("About PopGen", self.showAbout, tip="Display software information")

        dataHhldSample = self.createAction(
            "Household Sample", self.showHhldSampleStruct, tip="Data structure for the household sample file."
        )

        dataGQSample = self.createAction(
            "Groupquarter Sample", self.showGQSampleStruct, tip="Data structure for the groupquarter sample file."
        )

        dataPersonSample = self.createAction(
            "Person Sample", self.showPersonSampleStruct, tip="Data structure for the person sample file."
        )

        dataHhldMarginals = self.createAction(
            "Household Marginals", self.showHhldMarginalsStruct, tip="Data structure for the household marginals file."
        )

        dataGQMarginals = self.createAction(
            "Groupquarter Marginals",
            self.showGQMarginalsStruct,
            tip="Data structure for the groupquarter marginals file.",
        )

        dataPersonMarginals = self.createAction(
            "Person Marginals", self.showPersonMarginalsStruct, tip="Data structure for the person marginals file."
        )

        dataGeocorr = self.createAction(
            "Geographic Correspondence",
            self.showGeocorrStruct,
            tip="Data structure for the geographic correspondence file.",
        )

        resHousingSyn = self.createAction(
            "Housing Synthetic Data", self.showHousingSyn, tip="Data structure for the housing synthetic data file."
        )

        resPersonSyn = self.createAction(
            "Person Synthetic Data", self.showPersonSyn, tip="Data structure for the person synthetic data file."
        )

        self.helpMenu = self.menuBar().addMenu("&Help")

        self.helpDataTemplateSubMenu = self.helpMenu.addMenu(QIcon("images/structure.png"), "&Data Structures")

        self.addActions(
            self.helpDataTemplateSubMenu,
            (
                dataHhldSample,
                dataGQSample,
                dataPersonSample,
                None,
                dataHhldMarginals,
                dataGQMarginals,
                dataPersonMarginals,
                None,
                dataGeocorr,
                None,
                resHousingSyn,
                resPersonSyn,
            ),
        )

        # self.addActions(self.helpMenu, (None, helpDocumentationAction, helpHelpAction, None, helpAboutAction))
        self.addActions(self.helpMenu, (None, helpDocumentationAction, None, helpAboutAction))

        # FILE MANAGER
        # Setting up the file manager
        fileManagerDockWidget = QDockWidget("File Manager", self)
        fileManagerDockWidget.setObjectName("FileManagerDockWidget")
        fileManagerDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)

        self.fileManager = QTreeWidgetCMenu()
        fileManagerDockWidget.setWidget(self.fileManager)
        self.addDockWidget(Qt.LeftDockWidgetArea, fileManagerDockWidget)

        # self.connect(self.fileManager, SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.fileManager.editItem)
        self.connect(self.fileManager, SIGNAL("itemClicked(QTreeWidgetItem *,int)"), self.fileManager.click)
        self.connect(self, SIGNAL("Dirty(bool)"), self.windowDirty)
        self.connect(self.scenarioComboBox, SIGNAL("currentIndexChanged(int)"), self.scenarioChanged)

    def scenarioChanged(self, index):
        file = (
            self.project.location
            + os.path.sep
            + self.project.name
            + os.path.sep
            + "%s%s%s.pop" % (self.project.name, "scenario", index + 1)
        )
        file = os.path.realpath(file)
        with open(file, "rb") as f:
            self.project = pickle.load(f)
            self.setWindowTitle("PopGen: Version-1.1 (%s)" % self.project.name)
        self.project.scenario = index + 1
        self.project.save()
        self.fileManager.project = self.project
        self.fileManager.populate()

    def windowDirty(self, value):
        # print 'entering dirty %s' %value
        if value:
            self.setWindowTitle("PopGen: Version-1.1 %s*" % self.project.name)
        else:
            self.setWindowTitle("PopGen: Version-1.1 %s" % self.project.name)

    # Defining all the slots and supporting methods

    def projectNew(self):
        if not self.fileManager.isEnabled():
            self.runWizard()
        else:
            reply = QMessageBox.question(
                None,
                "Project Setup Wizard",
                QString("""A PopGen project already open. Would you like to continue?"""),
                QMessageBox.Yes | QMessageBox.No,
            )
            if reply == QMessageBox.Yes:
                save = QMessageBox.question(
                    None,
                    "Project Setup Wizard",
                    QString("""Would you like to save the project?"""),
                    QMessageBox.Yes | QMessageBox.No,
                )
                self.fileManager.clear()
                self.fileManager.setEnabled(False)
                self.enableFunctions(False)
                self.project = None

                if save == QMessageBox.Yes:
                    self.project.save()
                self.runWizard()

    def runWizard(self):
        self.wizard = Wizard()
        self.wizard.setWindowIcon(QIcon("./images/projectnew.png"))

        if self.wizard.exec_():
            # print "complete"
            self.project = self.wizard.project
            self.setWindowTitle("PopGen: Version-1.1 (%s)" % (self.project.name))
            self.project.save()
            self.fileManager.project = self.project
            self.fileManager.populate()
            self.enableFunctions(True)

    def enableFunctions(self, option):
        self.projectSaveAction.setEnabled(option)
        self.projectSaveAsAction.setEnabled(option)
        self.projectCloseAction.setEnabled(option)

        self.dataMenu.setEnabled(option)
        self.dataToolBar.setEnabled(option)

        self.synthesizerMenu.setEnabled(option)
        self.synthesizerToolBar.setEnabled(option)

        self.resultsMenu.setEnabled(option)
        # self.resultsToolBar.setEnabled(option)

        self.scenarioToolBar.setEnabled(option)

    def projectOpen(self):
        project = OpenProject()

        if not project.file.isEmpty():
            if self.fileManager.isEnabled():
                reply = QMessageBox.warning(
                    None,
                    "Open Existing Project",
                    QString("""A PopGen project already open. Would you like to continue?"""),
                    QMessageBox.Yes | QMessageBox.No,
                )
                if reply == QMessageBox.Yes:
                    save = QMessageBox.warning(
                        None,
                        "Save Existing Project",
                        QString("""Would you like to save the project?"""),
                        QMessageBox.Yes | QMessageBox.No,
                    )
                    if save == QMessageBox.Yes:
                        SaveProject(self.project)
                    with open(project.file, "rb") as f:
                        self.project = pickle.load(f)
                        self.setWindowTitle("PopGen: Version-1.1 (%s)" % self.project.name)
                        self.fileManager.project = self.project
                        self.fileManager.populate()
                        self.enableFunctions(True)
                        self.scenarioComboBox.setCurrentIndex((self.project.scenario - 1))
                        # PopulateFileManager(self.project, self.fileManager)

            else:
                with open(project.file, "rb") as f:
                    self.project = pickle.load(f)
                    self.setWindowTitle("PopGen: Version-1.1 (%s)" % self.project.name)
                    self.fileManager.project = self.project
                    self.fileManager.populate()
                    self.enableFunctions(True)
                    self.scenarioComboBox.setCurrentIndex(self.project.scenario - 1)
                    # PopulateFileManager(self.project, self.fileManager)

    def projectSave(self):
        if self.project:
            self.project.save()

    def projectSaveAs(self):
        file = QFileDialog.getSaveFileName(
            self, QString("Save As..."), "%s" % self.project.location, "PopGen File (*.pop)"
        )

        file = re.split("[/.]", file)
        filename = file[-2]
        if not filename.isEmpty():
            reply = QMessageBox.warning(
                self,
                "Save Existing Project As...",
                QString("""Would you like to continue?"""),
                QMessageBox.Yes | QMessageBox.No,
            )
            if reply == QMessageBox.Yes:
                self.project.filename = filename
                self.project.save()
                self.setWindowTitle("PopGen: Version-1.1 (%s)" % self.project.name)

    def projectClose(self):
        self.fileManager.clear()
        self.fileManager.setEnabled(False)
        self.enableFunctions(False)
        self.project = None

    def dataSource(self):
        dataConnectionDia = DBConnectionDialog(self.project)
        if dataConnectionDia.exec_():
            if self.project <> dataConnectionDia.project:
                self.project = dataConnectionDia.project
                self.project.save()
                self.fileManager.populate()

    def dataImport(self):
        dataprocesscheck = DataDialog(self.project)
        dataprocesscheck.exec_()
        self.fileManager.populate()

    def dataStatistics(self):
        QMessageBox.information(self, "Information", "Run some descriptive analysis", QMessageBox.Ok)

    def dataModify(self):
        try:
            check = self.fileManager.item.parent().text(0) == "Data Tables"
            tablename = self.fileManager.item.text(0)
            if check:
                b = DisplayTable(self.project, tablename)

                b.exec_()
        except Exception, e:
            QMessageBox.warning(
                self,
                "Data",
                """Select a table and then choose this option to display a table"""
                """or use the context menu to view a table.""",
                QMessageBox.Ok,
            )
Esempio n. 4
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        import pp
        ppservers = ()
        if len(sys.argv) > 1:
            ncpus = int(sys.argv[1])
            self.job_server = pp.Server(ncpus,
                                        ppservers=ppservers,
                                        restart=True)
        else:
            self.job_server = pp.Server(ppservers=ppservers, restart=True)

        #print dir(self.job_server)

        #print 'number of workers', self.job_server.get_ncpus()
        #self.job_server.set_ncpus(1)
        #print 'number of workers', self.job_server.get_ncpus()

        self.dirty = False
        self.projectName = None

        self.setWindowTitle("PopGen Version-1.1")
        self.setWindowIcon(QIcon("./images/popsyn.png"))
        self.workingWindow = QLabel()
        self.showMaximized()
        self.setMinimumSize(800, 500)
        self.workingWindow.setAlignment(Qt.AlignCenter)
        bkground = QPixmap("./images/background.png")
        self.workingWindow.setPixmap(bkground)
        self.workingWindow.setScaledContents(True)
        self.setCentralWidget(self.workingWindow)

        self.sizeLabel = QLabel()
        self.sizeLabel.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
        status = self.statusBar()
        status.setSizeGripEnabled(False)
        status.addPermanentWidget(self.sizeLabel)
        status.showMessage("Ready", 5000)

        # FILE MENU
        # Defining menu/toolbar actions
        projectNewAction = self.createAction("&New Project", self.projectNew,
                                             QKeySequence.New, "projectnew",
                                             "Create a new PopGen project.")
        projectOpenAction = self.createAction(
            "&Open Project", self.projectOpen, QKeySequence.Open,
            "projectopen", "Open an existing PopGen project.")
        self.projectSaveAction = self.createAction(
            "&Save Project", self.projectSave, QKeySequence.Save,
            "projectsave", "Save the current PopGen project.")
        self.projectSaveAsAction = self.createAction(
            "Save Project &As...",
            self.projectSaveAs,
            icon="projectsaveas",
            tip="Save the current PopGen project with a new name.")
        self.projectCloseAction = self.createAction(
            "&Close Project",
            self.projectClose,
            "Ctrl+W",
            tip="Close the current PopGen project.")
        applicationQuitAction = self.createAction("&Quit",
                                                  self.close,
                                                  "Ctrl+Q",
                                                  icon="quit",
                                                  tip="Close the application.")

        self.projectSaveAction.setEnabled(False)
        self.projectSaveAsAction.setEnabled(False)
        self.projectCloseAction.setEnabled(False)

        # Adding actions to menu
        self.fileMenu = self.menuBar().addMenu("&File")
        #self.addActions(self.fileMenu, (projectNewAction, projectOpenAction, None, self.projectSaveAction,
        #                                   self.projectSaveAsAction, None, self.projectCloseAction, None, applicationQuitAction))
        self.addActions(
            self.fileMenu,
            (projectNewAction, projectOpenAction, None, self.projectSaveAction,
             None, self.projectCloseAction, None, applicationQuitAction))
        # Adding actions to toolbar
        self.fileToolBar = self.addToolBar("File")
        self.fileToolBar.setObjectName("FileToolBar")
        #self.addActions(self.fileToolBar, (projectNewAction, projectOpenAction, self.projectSaveAction, self.projectSaveAsAction))
        self.addActions(
            self.fileToolBar,
            (projectNewAction, projectOpenAction, self.projectSaveAction))

        # DATA MENU
        # Defining menu/toolbar actions
        dataSourceAction = self.createAction(
            "Data Source &Connection",
            self.dataSource,
            icon="datasource",
            tip="Enter MySQL connection settings.")
        dataImportAction = self.createAction(
            "&Import",
            self.dataImport,
            icon="fileimport",
            tip="Import data into MySQL database.")
        #dataStatisticsAction = self.createAction("&Statistics", self.dataStatistics,
        #                                         icon="statistics", tip="Conduct descriptive analysis.")

        dataModifyAction = self.createAction(
            "&Display",
            self.dataModify,
            icon="modifydata",
            tip="View, analyze and modify the input data.")

        dataMargsHhldAction = self.createAction(
            "&Household",
            self.dataMargsHhld,
            tip="Modify the distribution of household variables of interest.")
        dataMargsGQAction = self.createAction(
            "&Groupquarter",
            self.dataMargsGQ,
            tip="Modify the distribution of household variables of interest.")
        dataMargsPersAction = self.createAction(
            "&Person",
            self.dataMargsPers,
            tip="Modify the distribution of household variables of interest.")

        # Adding actions to menu
        self.dataMenu = self.menuBar().addMenu("&Data")

        #self.addActions(self.dataMenu, (dataSourceAction, None, dataImportAction, dataStatisticsAction, dataModifyAction))
        self.addActions(
            self.dataMenu,
            (dataSourceAction, None, dataImportAction, dataModifyAction, None))

        self.dataMargsSubMenu = self.dataMenu.addMenu(
            QIcon("images/Marginals.png"), "Modify Marginals Distributions")
        self.addActions(
            self.dataMargsSubMenu,
            (dataMargsHhldAction, dataMargsGQAction, dataMargsPersAction))

        # Adding actions to toolbar
        self.dataToolBar = self.addToolBar("Data")
        self.dataToolBar.setObjectName("DataToolBar")
        #self.addActions(self.dataToolBar, (dataSourceAction,  dataImportAction, dataStatisticsAction, dataModifyAction))
        self.addActions(self.dataToolBar,
                        (dataSourceAction, dataImportAction, dataModifyAction))

        self.dataMenu.setDisabled(True)
        self.dataToolBar.setDisabled(True)

        # SYNTHESIZER MENU
        # Defining menu/toolbar actions
        #synthesizerControlVariablesAction = self.createAction("Control &Variables", self.synthesizerControlVariables,
        #                                                      icon="controlvariables",
        #                                                      tip="Select variables to control.")
        setCorrespondenceAction = self.createAction(
            "Set Corresponding Variables",
            self.synthesizerSetCorrBetVariables,
            icon="varcorr",
            tip="""Select the variables and """
            """set the correspondence map between the variables """
            """in the sample file and variables in the control file.""")
        synthesizerParameterAction = self.createAction(
            "&Parameters/Settings",
            self.synthesizerParameter,
            icon="parameters",
            tip="Set parameter values.")
        synthesizerRunAction = self.createAction("Run",
                                                 self.synthesizerRun,
                                                 icon="run",
                                                 tip="Run synthesizer.")
        synthesizerStopAction = self.createAction(
            "Stop",
            self.synthesizerStop,
            icon="stop",
            tip="Stop the current population synthesis run.")
        # Adding actions to menu
        self.synthesizerMenu = self.menuBar().addMenu("&Synthesizer")
        #self.addActions(self.synthesizerMenu, (setCorrespondenceAction,
        #                                       synthesizerParameterAction, None,
        #                                       synthesizerRunAction, synthesizerStopAction))
        self.addActions(self.synthesizerMenu,
                        (setCorrespondenceAction, synthesizerParameterAction,
                         None, synthesizerRunAction))
        # Adding actions to toolbar
        self.synthesizerToolBar = self.addToolBar("Synthesizer")
        #self.addActions(self.synthesizerToolBar, (synthesizerControlVariablesAction, synthesizerParameterAction,
        #                                          synthesizerRunAction))
        self.addActions(self.synthesizerToolBar,
                        (setCorrespondenceAction, synthesizerParameterAction,
                         synthesizerRunAction))

        self.synthesizerMenu.setDisabled(True)
        self.synthesizerToolBar.setDisabled(True)

        self.scenarioComboBox = QComboBox()
        scenarioItems = [
            'Scenario - 1', 'Scenario - 2', 'Scenario - 3', 'Scenario - 4',
            'Scenario - 5'
        ]
        self.scenarioComboBox.addItems(scenarioItems)

        self.scenarioToolBar = self.addToolBar("Scenario")
        self.scenarioToolBar.addWidget(self.scenarioComboBox)
        self.scenarioToolBar.setDisabled(True)

        # RESULTS MENU
        # Defining menu/toolbar actions
        resultsRegionalAARDAction = self.createAction(
            "Average Absolute Relative Difference (AARD)",
            self.resultsRegionalAARD,
            tip=
            """Display the distribution of Average Absolute Relative Difference (AARD) """
            """across individual geographies.""")
        resultsRegionalPValueAction = self.createAction(
            "p-Value",
            self.resultsRegionalPValue,
            tip="""Display the distribution of p-value """
            """for the synthetic population across individual geographies.""")
        resultsRegionalHousDistAction = self.createAction(
            "Distribution of Housing Variables",
            self.resultsRegionalHousDist,
            tip="Comparison of housing variables.")
        resultsRegionalPersDistAction = self.createAction(
            "Distribution of Person Variables",
            self.resultsRegionalPersDist,
            tip="Comparison of person variables.")

        resultsRegionalAction = self.createAction(
            "Regional Geography Statistics",
            self.resultsRegional,
            icon="region",
            tip="Display performance statistics for the entire region.")

        resultsIndividualAction = self.createAction(
            "&Individual Geography Statistics",
            self.resultsIndividual,
            icon="individualgeo",
            tip="Display performance statistics for individual geographies.")

        resultsViewHHAction = self.createAction(
            "&View Households",
            self.resultsViewHH,
            icon="viewhh",
            tip="Display synthesized households for the entire region.")

        resultsExportCSVAction = self.createAction(
            "Into &CSV Format",
            self.resultsCSVExport,
            tip="Export results into a comma-seperated file")

        resultsExportTabAction = self.createAction(
            "Into &Tab-delimited Format",
            self.resultsTabExport,
            tip="Export results into a tab-delimited file")

        resultsExportSummaryAction = self.createAction(
            "Summary Statistics",
            self.resultsExportSummary,
            tip="Export summary statistics for the synthetic population")

        thematicMapsHhldAction = self.createAction(
            "Household",
            self.thematicMapsHhld,
            tip="""Display thematic maps of the synthetic population for """
            """household attribute categories""")

        thematicMapsGQAction = self.createAction(
            "Groupquarter",
            self.thematicMapsGQ,
            tip="""Display thematic maps of the synthetic population for """
            """groupquarter attribute categories""")

        thematicMapsPersonAction = self.createAction(
            "Person",
            self.thematicMapsPerson,
            tip="""Display thematic maps of the synthetic population for """
            """person attribute categories""")

        # Adding actions to menu
        self.resultsMenu = self.menuBar().addMenu("&Results")
        self.regionwideSubMenu = self.resultsMenu.addMenu(
            QIcon("images/region.png"), "Regional Statistics")
        self.addActions(
            self.regionwideSubMenu,
            (resultsRegionalAARDAction, resultsRegionalPValueAction,
             resultsRegionalHousDistAction, resultsRegionalPersDistAction))

        self.addActions(self.resultsMenu, (resultsIndividualAction, ))

        self.thematicMapsSubMenu = self.resultsMenu.addMenu(
            QIcon("images/thematic.png"), "&Thematic Maps")
        self.addActions(self.thematicMapsSubMenu,
                        (thematicMapsHhldAction, thematicMapsGQAction,
                         thematicMapsPersonAction))

        self.addActions(self.resultsMenu, (None, ))

        self.exportSubMenu = self.resultsMenu.addMenu(
            QIcon("images/export.png"), "&Export Synthetic Population Tables")
        self.addActions(self.exportSubMenu,
                        (resultsExportCSVAction, resultsExportTabAction, None,
                         resultsExportSummaryAction))

        #self.addActions(self.resultsMenu, (resultsViewHHAction,))
        # Adding actions to toolbar

        #self.resultsToolBar = self.addToolBar("Results")
        #self.resultsToolBar.addToolBar(QIcon("Regional SubMenu"))
        #self.addActions(self.resultsToolBar, (resultsRegionalAction, resultsIndividualAction))

        self.resultsMenu.setDisabled(True)
        #self.resultsToolBar.setDisabled(True)

        # HELP MENU
        # Defining menu/toolbar actions

        helpDocumentationAction = self.createAction(
            "Documentation",
            self.showDocumentation,
            tip="Display the documentation of PopGen.",
            icon="documentation")
        helpHelpAction = self.createAction(
            "Help",
            self.showHelp,
            tip="Quick reference for important parameters.",
            icon="help")

        helpAboutAction = self.createAction("About PopGen",
                                            self.showAbout,
                                            tip="Display software information")

        dataHhldSample = self.createAction(
            "Household Sample",
            self.showHhldSampleStruct,
            tip="Data structure for the household sample file.")

        dataGQSample = self.createAction(
            "Groupquarter Sample",
            self.showGQSampleStruct,
            tip="Data structure for the groupquarter sample file.")

        dataPersonSample = self.createAction(
            "Person Sample",
            self.showPersonSampleStruct,
            tip="Data structure for the person sample file.")

        dataHhldMarginals = self.createAction(
            "Household Marginals",
            self.showHhldMarginalsStruct,
            tip="Data structure for the household marginals file.")

        dataGQMarginals = self.createAction(
            "Groupquarter Marginals",
            self.showGQMarginalsStruct,
            tip="Data structure for the groupquarter marginals file.")

        dataPersonMarginals = self.createAction(
            "Person Marginals",
            self.showPersonMarginalsStruct,
            tip="Data structure for the person marginals file.")

        dataGeocorr = self.createAction(
            "Geographic Correspondence",
            self.showGeocorrStruct,
            tip="Data structure for the geographic correspondence file.")

        resHousingSyn = self.createAction(
            "Housing Synthetic Data",
            self.showHousingSyn,
            tip="Data structure for the housing synthetic data file.")

        resPersonSyn = self.createAction(
            "Person Synthetic Data",
            self.showPersonSyn,
            tip="Data structure for the person synthetic data file.")

        self.helpMenu = self.menuBar().addMenu("&Help")

        self.helpDataTemplateSubMenu = self.helpMenu.addMenu(
            QIcon("images/structure.png"), "&Data Structures")

        self.addActions(
            self.helpDataTemplateSubMenu,
            (dataHhldSample, dataGQSample, dataPersonSample, None,
             dataHhldMarginals, dataGQMarginals, dataPersonMarginals, None,
             dataGeocorr, None, resHousingSyn, resPersonSyn))

        #self.addActions(self.helpMenu, (None, helpDocumentationAction, helpHelpAction, None, helpAboutAction))
        self.addActions(self.helpMenu,
                        (None, helpDocumentationAction, None, helpAboutAction))

        # FILE MANAGER
        # Setting up the file manager
        fileManagerDockWidget = QDockWidget("File Manager", self)
        fileManagerDockWidget.setObjectName("FileManagerDockWidget")
        fileManagerDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)

        self.fileManager = QTreeWidgetCMenu()
        fileManagerDockWidget.setWidget(self.fileManager)
        self.addDockWidget(Qt.LeftDockWidgetArea, fileManagerDockWidget)

        #self.connect(self.fileManager, SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.fileManager.editItem)
        self.connect(self.fileManager,
                     SIGNAL("itemClicked(QTreeWidgetItem *,int)"),
                     self.fileManager.click)
        self.connect(self, SIGNAL("Dirty(bool)"), self.windowDirty)
        self.connect(self.scenarioComboBox, SIGNAL("currentIndexChanged(int)"),
                     self.scenarioChanged)

    def scenarioChanged(self, index):
        file = (self.project.location + os.path.sep + self.project.name +
                os.path.sep + '%s%s%s.pop' %
                (self.project.name, 'scenario', index + 1))
        file = os.path.realpath(file)
        with open(file, 'rb') as f:
            self.project = pickle.load(f)
            self.setWindowTitle("PopGen: Version-1.1 (%s)" % self.project.name)
        self.project.scenario = index + 1
        self.project.save()
        self.fileManager.project = self.project
        self.fileManager.populate()

    def windowDirty(self, value):
        #print 'entering dirty %s' %value
        if value:
            self.setWindowTitle("PopGen: Version-1.1 %s*" % self.project.name)
        else:
            self.setWindowTitle("PopGen: Version-1.1 %s" % self.project.name)


# Defining all the slots and supporting methods

    def projectNew(self):
        if not self.fileManager.isEnabled():
            self.runWizard()
        else:
            reply = QMessageBox.question(
                None, "Project Setup Wizard",
                QString(
                    """A PopGen project already open. Would you like to continue?"""
                ), QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                save = QMessageBox.question(
                    None, "Project Setup Wizard",
                    QString("""Would you like to save the project?"""),
                    QMessageBox.Yes | QMessageBox.No)
                self.fileManager.clear()
                self.fileManager.setEnabled(False)
                self.enableFunctions(False)
                self.project = None

                if save == QMessageBox.Yes:
                    self.project.save()
                self.runWizard()

    def runWizard(self):
        self.wizard = Wizard()
        self.wizard.setWindowIcon(QIcon("./images/projectnew.png"))

        if self.wizard.exec_():
            #print "complete"
            self.project = self.wizard.project
            self.setWindowTitle("PopGen: Version-1.1 (%s)" %
                                (self.project.name))
            self.project.save()
            self.fileManager.project = self.project
            self.fileManager.populate()
            self.enableFunctions(True)

    def enableFunctions(self, option):
        self.projectSaveAction.setEnabled(option)
        self.projectSaveAsAction.setEnabled(option)
        self.projectCloseAction.setEnabled(option)

        self.dataMenu.setEnabled(option)
        self.dataToolBar.setEnabled(option)

        self.synthesizerMenu.setEnabled(option)
        self.synthesizerToolBar.setEnabled(option)

        self.resultsMenu.setEnabled(option)
        #self.resultsToolBar.setEnabled(option)

        self.scenarioToolBar.setEnabled(option)

    def projectOpen(self):
        project = OpenProject()

        if not project.file.isEmpty():
            if self.fileManager.isEnabled():
                reply = QMessageBox.warning(
                    None, "Open Existing Project",
                    QString(
                        """A PopGen project already open. Would you like to continue?"""
                    ), QMessageBox.Yes | QMessageBox.No)
                if reply == QMessageBox.Yes:
                    save = QMessageBox.warning(
                        None, "Save Existing Project",
                        QString("""Would you like to save the project?"""),
                        QMessageBox.Yes | QMessageBox.No)
                    if save == QMessageBox.Yes:
                        SaveProject(self.project)
                    with open(project.file, 'rb') as f:
                        self.project = pickle.load(f)
                        self.setWindowTitle("PopGen: Version-1.1 (%s)" %
                                            self.project.name)
                        self.fileManager.project = self.project
                        self.fileManager.populate()
                        self.enableFunctions(True)
                        self.scenarioComboBox.setCurrentIndex(
                            (self.project.scenario - 1))
                        #PopulateFileManager(self.project, self.fileManager)

            else:
                with open(project.file, 'rb') as f:
                    self.project = pickle.load(f)
                    self.setWindowTitle("PopGen: Version-1.1 (%s)" %
                                        self.project.name)
                    self.fileManager.project = self.project
                    self.fileManager.populate()
                    self.enableFunctions(True)
                    self.scenarioComboBox.setCurrentIndex(
                        self.project.scenario - 1)
                    #PopulateFileManager(self.project, self.fileManager)

    def projectSave(self):
        if self.project:
            self.project.save()

    def projectSaveAs(self):
        file = QFileDialog.getSaveFileName(self, QString("Save As..."),
                                           "%s" % self.project.location,
                                           "PopGen File (*.pop)")

        file = re.split("[/.]", file)
        filename = file[-2]
        if not filename.isEmpty():
            reply = QMessageBox.warning(
                self, "Save Existing Project As...",
                QString("""Would you like to continue?"""),
                QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.project.filename = filename
                self.project.save()
                self.setWindowTitle("PopGen: Version-1.1 (%s)" %
                                    self.project.name)

    def projectClose(self):
        self.fileManager.clear()
        self.fileManager.setEnabled(False)
        self.enableFunctions(False)
        self.project = None

    def dataSource(self):
        dataConnectionDia = DBConnectionDialog(self.project)
        if dataConnectionDia.exec_():
            if self.project <> dataConnectionDia.project:
                self.project = dataConnectionDia.project
                self.project.save()
                self.fileManager.populate()

    def dataImport(self):
        dataprocesscheck = DataDialog(self.project)
        dataprocesscheck.exec_()
        self.fileManager.populate()

    def dataStatistics(self):
        QMessageBox.information(self, "Information",
                                "Run some descriptive analysis",
                                QMessageBox.Ok)

    def dataModify(self):
        try:
            check = self.fileManager.item.parent().text(0) == 'Data Tables'
            tablename = self.fileManager.item.text(0)
            if check:
                b = DisplayTable(self.project, tablename)

                b.exec_()
        except Exception, e:
            QMessageBox.warning(
                self, "Data",
                """Select a table and then choose this option to display a table"""
                """or use the context menu to view a table.""", QMessageBox.Ok)