Exemple #1
0
 def OnMenuSelected(self, event):
     """ Handles Menu selection """
     MenuID = event.GetId()
     if MenuID in [wx.ID_SAVE, wx.ID_SAVEAS]:  # save or save as menu
         self.SaveReport(MenuID)
     else:
         cdml.OnMenuSelected(self, event)
Exemple #2
0
    def OnMenuSelected(self, event):
        """ Do something when action buttons are clicked.
            Action buttons are Save, Run Simulation, View Result and Close"""
        menuId = event.GetId()
        evtType = event.GetEventType()

        if evtType==wx.wxEVT_COMMAND_MENU_SELECTED:
            if menuId not in [cdml.ID_MENU_REPORT_ALL]:
                # Use the default handler first and if no more processing needed return
                if cdml.OnMenuSelected(self, event):
                    return

        try:
            # In any case, if a button - Save, Run, View Result - is clicked, data will be save
            save_ok = self.CheckData()

            if evtType == wx.wxEVT_CLOSE_WINDOW:    # Close Window Event
                #cdml.CloseForm(self, True, self.Collection, self.idPrj)
                cdml.CloseForm(self, True)
                return

            elif menuId == cdml.ID_MENU_COPY_RECORD:
                copy_ok = self.CopyProject()
                if not copy_ok: return
                cdml.dlgSimpleMsg('INFO', 'The project has been successfully copied - you are now working on the new copy', wx.OK, wx.ICON_INFORMATION, Parent = self)
            elif menuId == wx.ID_SAVE :
                if not save_ok: return
                cdml.dlgSimpleMsg('INFO', 'The project data has been saved successfully', wx.OK, wx.ICON_INFORMATION, Parent = self)

            elif menuId == wx.ID_APPLY:             # Run Simulation
                self.RunSimulation()

            elif menuId == wx.ID_VIEW_DETAILS:  # View Results / Extract PopulationSets
                self.ShowSimResult()

            elif menuId == wx.ID_CLEAR:

                result_ids = [ result.ID for result in DB.SimulationResults.values()
                                if result.ProjectID == self.idPrj ]

                if result_ids == [] :
                    cdml.dlgSimpleMsg('ERROR', "There are no simulation results for this project", Parent = self)
                else:
                    ans = cdml.dlgSimpleMsg('WARNING', 'Simulation results will be deleted permanently.\nDo you want to continue with deletion?', wx.YES_NO, wx.ICON_WARNING, Parent = self)
                    if ans == wx.ID_NO: return

                    for id in result_ids:
                        DB.SimulationResults.Delete(id, ProjectBypassID = self.idPrj)

                    cdml.dlgSimpleMsg('INFO', 'All simulation results were deleted', wx.OK, wx.ICON_INFORMATION, Parent = self)

        except:
            (ExceptType, ExceptValue, ExceptTraceback) = sys.exc_info()
            need_ans = cdml.iif(evtType == wx.wxEVT_CLOSE_WINDOW, True, False)
            if cdml.dlgErrorMsg(yesno=need_ans, Parent = self) == wx.ID_NO:
                cdml.CloseForm(self, False)
Exemple #3
0
    def OnMenuSelected(self, event):
        """ Event handler for Popup menu"""

        # Use the default handler first and if no more processing needed return
        if cdml.OnMenuSelected(self, event):
            return

        menuId = event.GetId()
        if menuId == cdml.IDF_BUTTON1:  # ADD ROW
            self.grid_1.AppendRows(1)

        elif menuId == cdml.IDF_BUTTON2:  # Delete Row

            row = self.grid_1.GetGridCursorRow()
            if row == -1: return

            self.grid_1.DeleteRows(row)

        elif menuId == wx.ID_UNDO:  # Undo
            self.Undo()
Exemple #4
0
    def OnMenuSelected(self, event):
        """ Event handler for buttons and menu items in main form"""

        menuId = event.GetId()
        if menuId in [wx.ID_NEW, wx.ID_OPEN]:  # New and Open menu
            self.OpenDB(menuId)  # open dialog to select database file

        elif menuId == cdml.ID_MENU_COPY_RECORD:
            self.CopyProjectRecord()

        elif menuId == cdml.ID_MENU_DELETE_RECORD:
            self.DeleteProjectRecord()

        elif menuId in [wx.ID_SAVE, wx.ID_SAVEAS]:  # save or save as menu
            self.SaveDB(menuId)

        elif menuId in range(
                cdml.IDF_BUTTON1,
                cdml.IDF_BUTTON10):  # Items in Data Menu and buttons
            # check database was loaded
            if not self._db_opened:
                cdml.dlgSimpleMsg(
                    'WARNING',
                    "No data is loaded to the system. Please select 'New' or 'Open' in File menu",
                    wx.OK,
                    wx.ICON_WARNING,
                    Parent=self)
                return

            btn = self.FindWindowById(
                menuId)  # synchronize selected menu to a button
            if btn.userData == None:
                return  # target for should be assigned to each button
            # as user data to avoid import statement.
            # See __set_properties method

            if btn.userData == 'Transitions' and len(DB.StudyModels) == 0:
                cdml.dlgSimpleMsg('ERROR',
                                  'A Model should be defined',
                                  Parent=self)
                return

            cdml.OpenForm(btn.userData,
                          self)  # open a form as default mode(=None)

        elif menuId in [
                cdml.ID_MENU_ABOUT, cdml.ID_MENU_HELP,
                cdml.ID_MENU_HELP_GENERAL
        ]:
            cdml.OnMenuSelected(self, event)

        elif menuId == cdml.ID_MENU_REPORT_THIS:  # Create a report for a specific project
            index = self.lc_project.GetFirstSelected()
            if index in [-1,
                         0]:  # -1 : nothing selected, 0 'New Project' selected
                return
            ProjectCode = self.IndexToPID[index]
            if ProjectCode in DB.Projects.keys():
                cdml.OpenForm("ReportViewer",
                              self,
                              key=(DB.Projects[ProjectCode], None))

        elif menuId == cdml.ID_MENU_REPORT_ALL:  # Create a report for all projects
            CollectionObject = DB.Projects
            if CollectionObject != None:
                cdml.OpenForm("ReportViewer",
                              self,
                              key=(CollectionObject, None))