def htm_settings(): settings = [] if 'user_mail' in session: user = User.get(User.mail == session['user_mail']) if request.method == 'POST': # and form.validate(): form = SettingsForm(request.form) set = RunSettings.select().where(RunSettings.id == int(request.form['name'].split('form-')[1])).get() set.json_string = json.dumps(form.data) set.save() flash('Конфигурация сохранена') try: res = RunSettings.select().where(RunSettings.user == user.get_id()) for set in res: # print(json.loads(set.json_string)) f = SettingsForm() if set.json_string != "": f = SettingsForm.from_json(json.loads(set.json_string), skip_unknown_keys=True) settings.append({"id": set.id, "data": f}) except RunSettings.DoesNotExist: print("RunSettings empty") return render_template("htmSettings.html", settings=settings) else: return render_template("basic.html")
def OnShowSettings(self): form = SettingsForm(self, self.settings, self.imageCache) if form.exec_() == QtGui.QDialog.Accepted: self.LoadSettings()
def start_htm(server_port, settings_id): setjson = RunSettings.select().where(RunSettings.id == settings_id).get() f = SettingsForm.from_json(jsonpickle.json.loads(setjson.json_string), skip_unknown_keys=True) inset = f.getInputSettings() spset = f.getSpatialSettings() tpset = f.getTemporalSettings() htm = HTMCore(inset, spset, tpset) htm.move() # десиреализовать объект из строки - jsonpickle.decode(s) server = SocketServer(server_port) while True: data = server.receive_message() message = SystemMessages.get_keys_in_text(data) data = SystemMessages.clear_keys_in_text(data) if SystemMessages.GET_DATA in message: # сериализуем нужные нам части в объекте HTMSerialization htm_serialization = HTMSerialization(htm) server.send_message(jsonpickle.encode(htm_serialization)) continue if SystemMessages.MOVE in message: # сериализуем нужные нам части в объекте HTMSerialization htm.move() htm_serialization = HTMSerialization(htm) server.send_message(jsonpickle.encode(htm_serialization)) continue if SystemMessages.MOVE100 in message: # сериализуем нужные нам части в объекте HTMSerialization for i in range(100): htm.move() htm_serialization = HTMSerialization(htm) server.send_message(jsonpickle.encode(htm_serialization)) continue if SystemMessages.MOVE1000 in message: # сериализуем нужные нам части в объекте HTMSerialization for i in range(1000): htm.move() htm_serialization = HTMSerialization(htm) server.send_message(jsonpickle.encode(htm_serialization)) continue if SystemMessages.RESTART_WITH_SETTINGS: port, settings_id = data.replace('(', '', 1).replace(')', '', 1).split(',') setjson = RunSettings.select().where(RunSettings.id == settings_id).get() f = SettingsForm.from_json(jsonpickle.json.loads(setjson.json_string), skip_unknown_keys=True) inset = f.getInputSettings() spset = f.getSpatialSettings() tpset = f.getTemporalSettings() htm = HTMCore(inset, spset, tpset) htm.move() server.send_message("ok") continue if SystemMessages.STOP in message: server.send_message("ok") server.close() break print("Сообщение не обработано, нет ключей или .п.")