open/save projects
This commit is contained in:
		@@ -220,7 +220,7 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
        ov.daemon = True
 | 
					        ov.daemon = True
 | 
				
			||||||
        ov.start()
 | 
					        ov.start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.NewProject(self.models[0])
 | 
					        #   self.NewProject(self.models[0])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Функции приложения и обработки сервера
 | 
					    # Функции приложения и обработки сервера
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -372,27 +372,47 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
    def OnOpenProject(self, event):
 | 
					    def OnOpenProject(self, event):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def WalkModels(source, root, models, model_def = None):
 | 
					        def WalkModels(source, root, models, model_def = None):
 | 
				
			||||||
            
 | 
					            # for имя-модели, параметры-модели
 | 
				
			||||||
            for key, value in source.iteritems():
 | 
					            for mname, value in source.iteritems():
 | 
				
			||||||
                label = value['model']
 | 
					                label = value['model']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if label not in models:
 | 
					                if label not in models:
 | 
				
			||||||
                    raise KeyError, 'no "{}"'.format(label)
 | 
					                    raise KeyError, 'no "{}"'.format(label)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                data = ModelData(self.server, models[label], model_def)
 | 
					                data = ModelData(self.server, models[label], model_def)
 | 
				
			||||||
                data.mdef.params = value['data']
 | 
					                data.mdef.params = value['data']
 | 
				
			||||||
 | 
					                data.state = value['state']
 | 
				
			||||||
                if 'result' in value:
 | 
					                if 'result' in value:
 | 
				
			||||||
                    data.res = task.ResultData(value['result'])
 | 
					                    data.res = task.ResultData(value['result'])
 | 
				
			||||||
                # тут надо проверить все добавленные параметры
 | 
					                # тут надо проверить все добавленные параметры
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                item = um.AppendItem(root, key)
 | 
					                item = self.AddModel(root, mname, data)
 | 
				
			||||||
                um.SetPyData(item, data)
 | 
					                model_items[mname] = item
 | 
				
			||||||
                model_items[key] = item
 | 
					
 | 
				
			||||||
                WalkModels(value['um'], item, models[label].GetSpecs(), data)
 | 
					                WalkModels(value['um'], item, models[label].GetSpecs(), data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def WalkPlots(source, root):
 | 
				
			||||||
 | 
					            for plot in source:
 | 
				
			||||||
 | 
					                item = self.m_plots.AppendItem(root, plot[0])
 | 
				
			||||||
 | 
					                self.m_plots.SetPyData(item, 'plot')
 | 
				
			||||||
 | 
					                self.m_plots.SetItemImage(item, self.icons.porg)
 | 
				
			||||||
 | 
					                for line in plot[1]:
 | 
				
			||||||
 | 
					                    model_label = line['model']
 | 
				
			||||||
 | 
					                    data = LineData(
 | 
				
			||||||
 | 
					                        ums_ptr = (um, model_items[model_label]),
 | 
				
			||||||
 | 
					                        plots_ptr = None,
 | 
				
			||||||
 | 
					                        type = line['type'],
 | 
				
			||||||
 | 
					                        columns = (line['colx'], line['coly'])
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    self.AddLine(item, line['title'], data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:        
 | 
					        try:        
 | 
				
			||||||
            infile = 'data.opl'
 | 
					            infile = 'data.opl'
 | 
				
			||||||
            data = {}
 | 
					            data = {}
 | 
				
			||||||
            with open(infile, 'rb') as f:
 | 
					            # with open(infile, 'rb') as f:
 | 
				
			||||||
                data = json.loads(zlib.decompress(f.read()))
 | 
					            #     data = json.loads(zlib.decompress(f.read()))
 | 
				
			||||||
 | 
					            with open(infile, 'r') as f:
 | 
				
			||||||
 | 
					                data = json.loads(f.read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            pprint(data)
 | 
					            pprint(data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -406,19 +426,29 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            um = self.m_user_models
 | 
					            um = self.m_user_models
 | 
				
			||||||
            model_items = {}
 | 
					            model_items = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            root = um.GetRootItem()
 | 
					            root = um.GetRootItem()
 | 
				
			||||||
            WalkModels(data['um'], root, {model.GetLabel(): model})
 | 
					            WalkModels(data['um'], root, {model.GetLabel(): model})
 | 
				
			||||||
 | 
					            um.ExpandAll(root)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            root = self.m_plots.GetRootItem()
 | 
				
			||||||
 | 
					            WalkPlots(data['plots'], root)
 | 
				
			||||||
 | 
					            self.m_plots.ExpandAll(root)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # except KeyError, e:
 | 
					        # except KeyError, e:
 | 
				
			||||||
        #     wx.MessageBox("Can't parse saved file!", 'Error!')
 | 
					        #     wx.MessageBox("Can't parse saved file!", 'Error!')
 | 
				
			||||||
        # except ValueError, e:
 | 
					        # except ValueError, e:
 | 
				
			||||||
        #     wx.MessageBox("Can't parse saved file!", 'Error!')
 | 
					        #     wx.MessageBox("Can't parse saved file!", 'Error!')
 | 
				
			||||||
        except Exception, e:
 | 
					        except Exception, e:
 | 
				
			||||||
 | 
					            # wx.MessageBox("Can't load file", 'Error')
 | 
				
			||||||
            print 'Oops', type(e), e
 | 
					            print 'Oops', type(e), e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def OnSaveProject(self, event):
 | 
					    def OnSaveProject(self, event):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def WalkModels(item, dest):
 | 
					        def WalkModels(item, dest):
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					            Сохраняем информацию о каждой модели
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
            if item != um.GetRootItem():
 | 
					            if item != um.GetRootItem():
 | 
				
			||||||
                data = um.GetPyData(item)
 | 
					                data = um.GetPyData(item)
 | 
				
			||||||
                title = um.GetItemText(item)
 | 
					                title = um.GetItemText(item)
 | 
				
			||||||
@@ -439,6 +469,9 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
                child = um.GetNextSibling(child)
 | 
					                child = um.GetNextSibling(child)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def WalkPlots(root, dest):
 | 
					        def WalkPlots(root, dest):
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					            Сохраняем информацию о каждом графике
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
            # по всеи элементам первого уровня
 | 
					            # по всеи элементам первого уровня
 | 
				
			||||||
            item1, _ = self.m_plots.GetFirstChild(root)
 | 
					            item1, _ = self.m_plots.GetFirstChild(root)
 | 
				
			||||||
            while item1.IsOk():
 | 
					            while item1.IsOk():
 | 
				
			||||||
@@ -460,7 +493,6 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
                dest.append([title, lines])
 | 
					                dest.append([title, lines])
 | 
				
			||||||
                item1 = self.m_plots.GetNextSibling(item1)
 | 
					                item1 = self.m_plots.GetNextSibling(item1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        wx.BeginBusyCursor()
 | 
					        wx.BeginBusyCursor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        data = {}
 | 
					        data = {}
 | 
				
			||||||
@@ -860,8 +892,8 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
    @item_protector
 | 
					    @item_protector
 | 
				
			||||||
    def AddLines(self, line_type):
 | 
					    def AddLines(self, line_type):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Добавляет линии в выделенный график компонента с графиками
 | 
					        Добавляет линии в выделенный график
 | 
				
			||||||
        (m_plots)
 | 
					        (компонента с графиками m_plots)
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        # получаем указатель на индекс и данные элемента, который выделен
 | 
					        # получаем указатель на индекс и данные элемента, который выделен
 | 
				
			||||||
        item, data = self.GetSelectedItemData(self.m_plots)
 | 
					        item, data = self.GetSelectedItemData(self.m_plots)
 | 
				
			||||||
@@ -870,21 +902,19 @@ class MainFrame(forms.MainFrame):
 | 
				
			|||||||
            return
 | 
					            return
 | 
				
			||||||
        # получаем указанные пользователем линии
 | 
					        # получаем указанные пользователем линии
 | 
				
			||||||
        lines = self.GetLines(line_type)
 | 
					        lines = self.GetLines(line_type)
 | 
				
			||||||
        # if not lines:
 | 
					 | 
				
			||||||
        #     return
 | 
					 | 
				
			||||||
        for line in lines:
 | 
					        for line in lines:
 | 
				
			||||||
            title = line.GetTitle()
 | 
					            self.AddLine(item, line.GetTitle(), line)
 | 
				
			||||||
            child = self.m_plots.AppendItem(item, title)
 | 
					
 | 
				
			||||||
            # указываем на только что созданный новый элемент
 | 
					    def AddLine(self, root, title, line_data):
 | 
				
			||||||
            line.plots_ptr = (self.m_plots, child)
 | 
					        item = self.m_plots.AppendItem(root, title)
 | 
				
			||||||
            # заполняем элемент данными
 | 
					        self.m_plots.SetPyData(item, line_data)
 | 
				
			||||||
            self.m_plots.SetPyData(child, line)
 | 
					        line_data.plots_ptr = (self.m_plots, item)
 | 
				
			||||||
            self.m_plots.SetItemImage(child, self.icons.pline)
 | 
					        if line_data.type == LINE_MARKER:
 | 
				
			||||||
            self.m_plots.Expand(item)
 | 
					            self.m_plots.SetItemImage(item, self.icons.pmarker)
 | 
				
			||||||
            if line.type == LINE_MARKER:
 | 
					 | 
				
			||||||
                self.m_plots.SetItemImage(child, self.icons.pmarker)
 | 
					 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
                self.m_plots.SetItemImage(child, self.icons.pline)
 | 
					            self.m_plots.SetItemImage(item, self.icons.pline)
 | 
				
			||||||
 | 
					        self.m_plots.Expand(root)
 | 
				
			||||||
 | 
					        return item
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def OnAddCurves(self, event):
 | 
					    def OnAddCurves(self, event):
 | 
				
			||||||
        self.AddLines(LINE_CURVE)
 | 
					        self.AddLines(LINE_CURVE)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,7 +33,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                "n": {
 | 
					                "n": {
 | 
				
			||||||
                    "type":     "int",
 | 
					                    "type":     "int",
 | 
				
			||||||
                    "default":  10,
 | 
					                    "default":  20,
 | 
				
			||||||
                    "title":    "Steps",
 | 
					                    "title":    "Steps",
 | 
				
			||||||
                    "comment":  "Number of steps for algorithm"
 | 
					                    "comment":  "Number of steps for algorithm"
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user