+ def on_edit_id(self, txt):
+ self.__item.id = txt
+
+ def on_edit_strategy(self, txt):
+ if not txt:
+ self.__entries.strategy_args.set('')
+ return
+ name2class = {
+ 'StillStrategy': StillStrategy,
+ 'UpStrategy': UpStrategy,
+ 'HitStrategy': HitStrategy,
+ 'DownStrategy': DownStrategy,
+ 'FixedStrategy': FixedStrategy}
+ class_ = name2class[txt]
+ args = []
+ error = False
+ if txt == 'StillStrategy':
+ args += [self.__item._np]
+ if txt in ['UpStrategy', 'DownStrategy']:
+ args += [self.__item._np]
+ try:
+ args += [float(self.__entries.strategy_args.get())]
+ except ValueError:
+ error = True
+ if txt == 'HitStrategy':
+ for item in self.__all_items:
+ if item.id == self.__entries.strategy_args.get():
+ args += [item]
+ args += [self.__item.node]
+ args += [self.__item._world]
+ if not error:
+ self.__item.strategy = class_(*args)
+ self.__item.strategy_json = txt
+ else:
+ self.__show_error_popup()
+
+ def on_edit_strategy_args(self, txt):
+ self.__item.strategy_args_json = txt
+
+ def __show_error_popup(self):
+ self.__dialog = OkDialog(dialogName='Strategy args errors',
+ text=_('There are errors in the strategy args.'),
+ command=self.__actually_close)
+ self.__dialog['frameColor'] = (.4, .4, .4, .14)
+ self.__dialog['relief'] = FLAT
+ self.__dialog.component('text0')['fg'] = (.9, .9, .9, 1)
+ self.__dialog.component('text0')['font'] = self._font
+ for b in self.__dialog.buttonList:
+ b['frameColor'] = (.4, .4, .4, .14)
+ b.component('text0')['fg'] = (.9, .9, .9, 1)
+ b.component('text0')['font'] = self._font
+ b.component('text1')['fg'] = (.9, .1, .1, 1)
+ b.component('text1')['font'] = self._font
+ b.component('text2')['fg'] = (.9, .9, .1, 1)
+ b.component('text2')['font'] = self._font
+
+ def __actually_close(self, arg):
+ self.__entries.strategy.set('')
+ self.__entries.strategy_args.set('')
+ self.__dialog.cleanup()
+