add dialog "add program", that appears after creating new project
authorSurkov Sergey <surkovsv93@gmail.com>
Mon, 26 Jun 2017 19:42:42 +0300
changeset 1708 24416137cda7
parent 1707 92537edeb205
child 1709 1e8900fc8ddb
add dialog "add program", that appears after creating new project
also, sets one task and one instance of created program in main project resource
BeremizIDE.py
IDEFrame.py
ProjectController.py
dialogs/PouDialog.py
--- a/BeremizIDE.py	Mon Jun 26 19:38:51 2017 +0300
+++ b/BeremizIDE.py	Mon Jun 26 19:42:42 2017 +0300
@@ -849,6 +849,7 @@
                 if self.EnableDebug:
                     self.DebugVariablePanel.SetDataProducer(self.CTR)
                 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+                IDEFrame.OnAddNewProject(self, event)
             else:
                 self.ResetView()
                 self.ShowErrorMessage(result)
--- a/IDEFrame.py	Mon Jun 26 19:38:51 2017 +0300
+++ b/IDEFrame.py	Mon Jun 26 19:42:42 2017 +0300
@@ -2277,25 +2277,36 @@
 #                         Add Project Elements Functions
 #-------------------------------------------------------------------------------
 
+    def OnAddNewProject(self, event):
+        # Asks user to create main program after creating new project
+        AddProgramDialog = self.GenerateAddPouFunction('program', True)
+        # Checks that user created main program
+        if AddProgramDialog(event):
+            self.Controler.SetProjectDefaultConfiguration()
+
     def OnAddDataTypeMenu(self, event):
         tagname = self.Controler.ProjectAddDataType()
         if tagname is not None:
             self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
             self.EditProjectElement(ITEM_DATATYPE, tagname)
 
-    def GenerateAddPouFunction(self, pou_type):
+    def GenerateAddPouFunction(self, pou_type, type_readonly = False):
         def OnAddPouMenu(event):
-            dialog = PouDialog(self, pou_type)
+            dialog = PouDialog(self, pou_type, type_readonly)
             dialog.SetPouNames(self.Controler.GetProjectPouNames())
             dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames())
             dialog.SetValues({"pouName": self.Controler.GenerateNewName(None, None, "%s%%d" % pou_type)})
+            pou_created = False
             if dialog.ShowModal() == wx.ID_OK:
                 values = dialog.GetValues()
                 tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
                 if tagname is not None:
                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
                     self.EditProjectElement(ITEM_POU, tagname)
+                    dialog.Destroy()
+                    pou_created = True
             dialog.Destroy()
+            return pou_created
         return OnAddPouMenu
 
     def GenerateAddTransitionFunction(self, pou_name):
--- a/ProjectController.py	Mon Jun 26 19:38:51 2017 +0300
+++ b/ProjectController.py	Mon Jun 26 19:42:42 2017 +0300
@@ -393,6 +393,18 @@
         self.ProjectAddConfiguration(config_name)
         self.ProjectAddConfigurationResource(config_name, res_name)
 
+    def SetProjectDefaultConfiguration(self):
+        # Sets default task and instance for new project
+        config = self.Project.getconfiguration(self.GetProjectMainConfigurationName())
+        resource = config.getresource()[0].getname()
+        config = config.getname()
+        resource_tagname = self.ComputeConfigurationResourceName(config, resource)
+        def_task = [
+            {'Priority': '0', 'Single': '', 'Interval': 'T#20ms', 'Name': 'task0', 'Triggering': 'Cyclic'}]
+        def_instance = [
+            {'Task': def_task[0].get('Name'), 'Type': self.GetProjectPouNames()[0], 'Name': 'instance0'}]
+        self.SetEditedResourceInfos(resource_tagname, def_task, def_instance)
+
     def NewProject(self, ProjectPath, BuildPath=None):
         """
         Create a new project in an empty folder
--- a/dialogs/PouDialog.py	Mon Jun 26 19:38:51 2017 +0300
+++ b/dialogs/PouDialog.py	Mon Jun 26 19:42:42 2017 +0300
@@ -41,7 +41,7 @@
     POU_LANGUAGES = GetPouLanguages()
     POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES])
 
-    def __init__(self, parent, pou_type = None):
+    def __init__(self, parent, pou_type=None, type_readonly=False):
         wx.Dialog.__init__(self, id=-1, parent=parent,
               name='PouDialog', title=_('Create a new POU'),
               style=wx.DEFAULT_DIALOG_STYLE)
@@ -85,7 +85,8 @@
         self.SetSizer(main_sizer)
 
         for option in GetPouTypes():
-            self.PouType.Append(_(option))
+            if not type_readonly or _(option) == _(pou_type):
+                self.PouType.Append(_(option))
         if pou_type is not None:
             self.PouType.SetStringSelection(_(pou_type))
         self.RefreshLanguage()