def finish_callback(cmd): session = Kernel.session() # remove command from active commands set sc_utils.removeFromSet(session, cmds[cmd], keynodes.ui.active_base_user_cmd) # append command into finished command set sc_utils.appendIntoSet(session, Kernel.segment(), cmds[cmd], keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) cmds.pop(cmd) cmd.delete()
def mouse_move_to_empty_place(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] # check if it's a mouse move to emty place command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_to_empty_place], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) window_width = render_engine._ogreViewport.getActualWidth() window_height = render_engine._ogreViewport.getActualHeight() kernel = Kernel.getSingleton() init_pos = (window_width / 2, window_height / 2) # check whether there is object under the mouse cursor objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) # looking for a place without object while len(objects) > 0: init_pos = calculate_next_mouse_position(init_pos, window_height, window_width, 30, 30) objects = kernel.getRootSheet()._getObjectsUnderMouse( True, True, init_pos) cmd = commands.MouseMoveTo(init_pos) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def mouse_move_object(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove from initiated set session.erase_el(command[1]) command = command[2] # check if it's a mouse move to object command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_obj], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) # get target object object = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, 0), True, 3) if not object: return object = object[2] obj = ScObject._sc2Objects(object) if len(obj) == 0: return obj = obj[0] # print obj._getScAddr().this # FIXME: find element in specified window (root window) init_pos = (0, 0) # target_pos = None # if isinstance(obj, suit.core.objects.ObjectDepth): # target_pos = render_engine.pos3dTo2dWindow(obj.getPosition()) # else: # target_pos = obj.getCenter() cmd = commands.MouseMove(init_pos, obj) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def mouse_move_object(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove from initiated set session.erase_el(command[1]) command = command[2] # check if it's a mouse move to object command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_obj], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) # get target object object = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, 0), True, 3) if not object: return object = object[2] obj = ScObject._sc2Objects(object) if len(obj) == 0: return obj = obj[0] # print obj._getScAddr().this # FIXME: find element in specified window (root window) init_pos = (0, 0) # target_pos = None # if isinstance(obj, suit.core.objects.ObjectDepth): # target_pos = render_engine.pos3dTo2dWindow(obj.getPosition()) # else: # target_pos = obj.getCenter() cmd = commands.MouseMove(init_pos, obj) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def _setSheet(self, _sheet): """Sets sheet for a logic """ BaseModeLogic._setSheet(self, _sheet) _sheet.eventRootChanged = self._onRootChanged _sheet.eventUpdate = self._onUpdate # getting data from content and save to temporary file import os import suit.core.sc_utils as sc_utils _addr = _sheet._getScAddr() if _addr is None: return kernel = Kernel.getSingleton() session = kernel.session() fmt = sc_utils.getContentFormat(session, _addr) assert fmt is not None file_name = "%s.%s" % (str(_addr.this), session.get_idtf(fmt).lower()) # saving data to file _cont = session.get_content_const(_addr) assert _cont is not None _cont_data = _cont.convertToCont() data = _cont.get_data(_cont_data.d.size) path = os.path.join(kernel.cache_path, 'video') out_file = os.path.join(path, file_name) file(out_file, "wb").write(data) ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup( "video") self.setVideo(file_name)
def _setSheet(self, _sheet): """Sets sheet for a logic """ BaseModeLogic._setSheet(self, _sheet) _sheet.eventRootChanged = self._onRootChanged _sheet.eventUpdate = self._onUpdate # getting data from content and save to temporary file import os import suit.core.sc_utils as sc_utils _addr = _sheet._getScAddr() if _addr is None: return kernel = Kernel.getSingleton() session = kernel.session() fmt = sc_utils.getContentFormat(session, _addr) assert fmt is not None file_name = "%s.%s" %(str(_addr.this), session.get_idtf(fmt).lower()) # saving data to file _cont = session.get_content_const(_addr) assert _cont is not None _cont_data = _cont.convertToCont() data = _cont.get_data(_cont_data.d.size) path = os.path.join(kernel.cache_path, 'video') out_file = os.path.join(path, file_name) file(out_file, "wb").write(data) ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup("video") self.setVideo(file_name)
def mouse_move_to_empty_place(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] # check if it's a mouse move to emty place command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_to_empty_place], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) window_width = render_engine._ogreViewport.getActualWidth() window_height = render_engine._ogreViewport.getActualHeight() kernel = Kernel.getSingleton() init_pos = (window_width / 2, window_height / 2) # check whether there is object under the mouse cursor objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) # looking for a place without object while len(objects) > 0: init_pos = calculate_next_mouse_position(init_pos, window_height, window_width, 30, 30) objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) cmd = commands.MouseMoveTo(init_pos) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции перемещения мыши на объект", keynodes.ui.init_base_user_cmd, mouse_move_object, [])) kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции нажатия(отпускания) кнопки мыши", keynodes.ui.init_base_user_cmd, mouse_button, []))
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции перемещения мыши на объект", keynodes.ui.init_base_user_cmd, mouse_move_object, [])) kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции нажатия(отпускания) кнопки мыши", keynodes.ui.init_base_user_cmd, mouse_button, []))
def cmd_finished(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove finished state (that need to replay it in future) session.erase_el(command[1]) command = command[2] # trying to find next command res = sc_utils.searchOneShotFullBinPairsAttrFromNode( session, command, keynodes.common.nrel_base_order, sc_core.pm.SC_CONST) if res is None: return next_command = res[2] # check if command isn't active if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.active_base_user_cmd], sc_core.pm.SC_CONST): raise RuntimeWarning("Command %s is active" % str(next_command)) # if next command included into finished commands set, then we need to remove it from that set if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.finish_base_user_cmd], sc_core.pm.SC_CONST): sc_utils.removeFromSet(session, next_command, keynodes.ui.finish_base_user_cmd) # append command into set of initialized commands sc_utils.appendIntoSet(session, Kernel.segment(), next_command, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_CONST)
def mouse_button(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError( "There are no button id for mouse button command %s" % str(command)) button = button[2] button_id = -1 # translate button sc-addr into ois button id if button.this == keynodes.ui.mouse_button_left.this: button_id = ois.MB_Left elif button.this == keynodes.ui.mouse_button_right.this: button_id = ois.MB_Right elif button.this == keynodes.ui.mouse_button_middle.this: button_id = ois.MB_Middle else: raise RuntimeError("Unknown mouse button id for command %s" % str(command)) cmd = commands.MouseButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def cmd_finished(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove finished state (that need to replay it in future) session.erase_el(command[1]) command = command[2] # trying to find next command res = sc_utils.searchOneShotFullBinPairsAttrFromNode(session, command, keynodes.common.nrel_base_order, sc_core.pm.SC_CONST) if res is None: return next_command = res[2] # check if command isn't active if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.active_base_user_cmd], sc_core.pm.SC_CONST): raise RuntimeWarning("Command %s is active" % str(next_command)) # if next command included into finished commands set, then we need to remove it from that set if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.finish_base_user_cmd], sc_core.pm.SC_CONST): sc_utils.removeFromSet(session, next_command, keynodes.ui.finish_base_user_cmd) # append command into set of initialized commands sc_utils.appendIntoSet(session, Kernel.segment(), next_command, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_CONST)
def keyboard_button(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError( "There are no button id for keyboard button command %s" % str(command)) button = button[2] button_id = -1 for i in keynodes.ui.keyboard.dictionary: if button.this == i.this: button_id = keynodes.ui.keyboard.dictionary[i] if button_id == -1: raise RuntimeError("Unknown keyboard button id for command %s" % str(command)) cmd = commands.KeyboardButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции перемещения мыши на объект", keynodes.ui.init_base_user_cmd, mouse_move_object, [])) kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции нажатия(отпускания) кнопки мыши", keynodes.ui.init_base_user_cmd, mouse_button, [])) kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции перемещения мыши в область поля без объектов", keynodes.ui.init_base_user_cmd, mouse_move_to_empty_place, [])) kernel.registerOperation(ScEventHandlerSetMember(u"операция эмуляции нажатия(отпускания) кнопки клавиатуры", keynodes.ui.init_base_user_cmd, keyboard_button, []))
def mouse_button(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError("There are no button id for mouse button command %s" % str(command)); button = button[2] button_id = -1 # translate button sc-addr into ois button id if button.this == keynodes.ui.mouse_button_left.this: button_id = ois.MB_Left elif button.this == keynodes.ui.mouse_button_right.this: button_id = ois.MB_Right elif button.this == keynodes.ui.mouse_button_middle.this: button_id = ois.MB_Middle else: raise RuntimeError("Unknown mouse button id for command %s" % str(command)) cmd = commands.MouseButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def keyboard_button(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError("There are no button id for keyboard button command %s" % str(command)); button = button[2] button_id = -1 for i in keynodes.ui.keyboard.dictionary: if button.this == i.this: button_id = keynodes.ui.keyboard.dictionary[i] if button_id == -1: raise RuntimeError("Unknown keyboard button id for command %s" % str(command)) cmd = commands.KeyboardButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции перемещения мыши на объект", keynodes.ui.init_base_user_cmd, mouse_move_object, [])) kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции нажатия(отпускания) кнопки мыши", keynodes.ui.init_base_user_cmd, mouse_button, [])) kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции перемещения мыши в область поля без объектов", keynodes.ui.init_base_user_cmd, mouse_move_to_empty_place, [])) kernel.registerOperation( ScEventHandlerSetMember( u"операция эмуляции нажатия(отпускания) кнопки клавиатуры", keynodes.ui.init_base_user_cmd, keyboard_button, []))
def start(self): Kernel.getSingleton().addUpdateListener(self)
def delete(self): Kernel.getSingleton().removeUpdateListener(self)
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation(ScEventHandlerSetMember(u"операция перехода к следующей команде при выполнении протокола действий", keynodes.ui.finish_base_user_cmd, cmd_finished, []))
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation(ScEventHandlerSetMember(u"operation that update UI after localization change", keynodes.ui.translate_lang_current, translation_changed, []))
def translation_changed(_params, _segment): kernel = Kernel.getSingleton() kernel.translationChanged()
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation( ScEventHandlerSetMember( u"операция перехода к следующей команде при выполнении протокола действий", keynodes.ui.finish_base_user_cmd, cmd_finished, []))
def initialize(): kernel = Kernel.getSingleton() kernel.registerOperation( ScEventHandlerSetMember( u"operation that update UI after localization change", keynodes.ui.translate_lang_current, translation_changed, []))