当前位置: 首页>>代码示例>>Python>>正文


Python engine.Engine类代码示例

本文整理汇总了Python中engine.Engine的典型用法代码示例。如果您正苦于以下问题:Python Engine类的具体用法?Python Engine怎么用?Python Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestEngine

class TestEngine(unittest.TestCase):
    def setUp(self):
        self.x = Engine(simple_lesson)

    def test_new(self):
        self.assertIsNotNone(self.x)

    def test_process_first(self):
        new_state, messages = self.x.process_message()
        self.assertEqual(new_state, 1)
        self.assertEqual(messages, ["First prompt", "The first question."])

    def test_process_correct_answer(self):
        new_state, messages = self.x.process_message(1, "a")
        self.assertEqual(new_state, 2)
        self.assertEqual(messages, ["That is correct.", "The second question."])

    def test_process_incorrect_answer(self):
        new_state, messages = self.x.process_message(2, "b")
        self.assertEqual(new_state, 2)
        self.assertEqual(messages, ["Wrong!"])

    def test_process_last_correct_answer(self):
        new_state, messages = self.x.process_message(2, "a")
        self.assertEqual(new_state, -1)
        self.assertEqual(messages, ["That is correct.", "Quiz Complete!"])

    def test_process_invalid_response(self):
        new_state, messages = self.x.process_message(1, "x")
        self.assertEqual(new_state, 1)
        self.assertEqual(messages, ["Invalid response, try again."])
开发者ID:cwkoss,项目名称:TextTeach,代码行数:31,代码来源:test_engine.py

示例2: on_message

    def on_message(self, sender=None, message=None):
        logging.info("Recieved message from %s: %s", sender, message)
        if sender is None or message is None or message == "":
            raise Error("Invalid sender or message.")
        # Admin start command requires 10 digit phone NOT prefixed with "+1"
        if message.split(' ')[0].lower() == "start":
            sender = "+1" + message.split(' ')[1]
            logging.info("AdminStart for #: %s", sender)
            message = "AdminStart"
        student = Student.ensure_student(phone=sender)
        try:
            student.totalMsgReceived
        except:
            student.totalMsgReceived = 1
        else:
            student.totalMsgReceived += 1
        student.put()
        session = Session.ensure_session(student.get_id())
        lesson = self.lessons.get(session.lesson_id)
        if lesson is None:
            raise Error("No such lesson: %s" % session.lesson_id)

        json_data = open('hiragana.json')
        data = json.load(json_data)
        json_data.close()
        eng = Engine(data)
        messages = eng.process_message_dev(message, student)
        #logging.info("Student's foo: %s" % student.questionHistory['foo'])

        if session.state == -1:
            session.key.delete()
        else:
            session.put()
        self.send_SMS_replies(sender, messages)
开发者ID:cwkoss,项目名称:TextTeach,代码行数:34,代码来源:controller.py

示例3: on_err_disconnect

 def on_err_disconnect(self):
     """
     Called automatically when the engine messagebus node exits/closes.
     This will emit a EvtDisconnect event.
     """
     Engine.on_err_disconnect(self)
     self.parent.event_generate(EvtDisconnect, when='tail')
开发者ID:tito2016,项目名称:Python-Project,代码行数:7,代码来源:tk_engine.py

示例4: __init__

    def __init__(self, parent, englabel=None, userdict={}, 
                    timeout=10):
        """
        The PTK engine class for embedding in gtk applications. 
        To use create an instance of this or a subclass. 
        It uses the parent object for signals. 
        engine.disconnect() should also be called before the application exits.
        
        Important. 
        It uses the a the gtk mainloop to post/bind events and starts a 
        communications thread, therefore gtk.gdk.threads_init() must be called 
        before the main loop is started!

            gtk.gdk.threads_init()  
            gtk.main()

        Signals to use:
        'engine_disconnect' -  sent went the engine disconnects.

        Methods/attributes you might want to overload:
        _get_welcome()  - Returns a string welcome message.
        self.eng_prompts - these are the prompts used by the controlling console.
        """
        self.parent = parent
        
        #add the engine disconnect signal
        if gobject.signal_lookup("engine_disconnect", self.parent) == 0:
            gobject.signal_new("engine_disconnect", self.parent, 
                               gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,())
        Engine.__init__(self, englabel, userdict, timeout)
开发者ID:tito2016,项目名称:Python-Project,代码行数:30,代码来源:gtk_engine.py

示例5: __init__

    def __init__(self, autoConnect = False):
        Application.__init__(self)
        Engine.__init__(self)
        #ip, port = "cradle.dyndns.org", "10001"
        ip, port = "127.0.0.1", "10001"

        if not autoConnect:
            address = raw_input("server ('%s:%s') :> " % (ip, port))
            
            if address != "":
                split = address.split(":")
                ip = split[0]
                if len(split) == 2:
                    port = split[1]

        self.chat = gamenet.NetCode("cradle", "cradle.dyndns.org", "AV", "enter", "-".join([ip, port]))
        self.chat.registerMessageListener(self.messageListener)
        self.timeBetweenChatUpdates = 0.5
        self.timeUntilNextChatUpdate = 0.0            
            
        self.network = networkclient.NetworkClient(ip, int(port))
        self.timeBetweenNetworkUpdates = 0.02
        self.timeUntilNextNetworkUpdate = 0.0
        self.serverRoundTripTime = 0.0
        self.lastServerUpdate = time.time()
        self.player = None
开发者ID:cradle,项目名称:manic,代码行数:26,代码来源:client.py

示例6: EnigmaX

class EnigmaX():
    def __init__(self):
        self.builder = Gtk.Builder()
        self.builder.add_from_file(gtk_builder_file)
        self.engine = Engine()
        self.window = self.builder.get_object('windowMain')
        self.textBox = self.builder.get_object('entry')
        self.label = self.builder.get_object('label')
        self.label2 = self.builder.get_object('enigma')
        self.engineToString()

        self.textBox.connect('activate', self.signal_text_activate)
        self.textBox.connect('changed', self.signal_text_changed)
        self.window.connect('destroy', self.signal_window_destroy)

        self.ciphertext = ''

        self.window.show_all()
    
    def signal_window_destroy(self, _):
        self.window.destroy()
        Gtk.main_quit()

    def signal_text_activate(self, *args):
        self.label.set_text(self.engine.run(self.textBox.get_text()))
        self.engineToString()
    
    def signal_text_changed(self, *args):
        newChar = self.textBox.get_text()[-1] if len(self.textBox.get_text()) else ''
        self.ciphertext += self.engine.translate(newChar.upper())
        self.label.set_text(self.ciphertext)
        self.engineToString()
    
    def engineToString(self):
        self.label2.set_text(self.engine.toString())
开发者ID:jacobj10,项目名称:PyEnigma,代码行数:35,代码来源:enigmaX.py

示例7: main

def main():
    parser = ArgumentParser()
    parser.add_argument('name', help='name of language configuration')
    parser.add_argument(
        '-v', '--verbose', action='store_true',
        help='show intermediate sound changes'
    )
    parser.add_argument(
        '-r', '--repeat', type=int, default=1,
        help='generate multiple words'
    )
    parser.add_argument(
        '-p', '--phonetic', action='store_true',
        help='show phonetic transcriptions'
    )
    parser.add_argument(
        '-R', '--raw', action='store_true',
        help='show raw state machine output'
    )
    parser.add_argument(
        '-w', '--words', nargs='+',
        help='use given words instead of state machine output'
    )
    engine = Engine(parser)
    engine.run()
开发者ID:chheisler,项目名称:Conlang,代码行数:25,代码来源:app.py

示例8: main

def main():
	os.environ["SDL_VIDEO_CENTERED"] = "1"
	pygame.init()

	game_data = {
		TITLE: "Crazy Ant",
		SIZE: (640, 480),
		FONT: Font(None, 32),
		LEVELS: [
			"level1",
			"level2",
			"level3",
		],
		LEVEL_DATA: {
			"level1": {
				FILE: "level1.lvl",
			},
			"level2": {
				FILE: "level2.lvl",
			},
			"level3": {
				FILE: "level3.lvl",
			},
		},
		CONTROLS: {
			LEFT: K_a,
			RIGHT: K_d,
			JUMP: K_s
		},
	}

	engine = Engine(game_data)
	engine.run()
开发者ID:luciferous,项目名称:CrazyAnt,代码行数:33,代码来源:main.py

示例9: Controller

class Controller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        #是否更新
        #False表示下载url_queue的链接,True表示更新,
        self.run_list=[False,True]
        self.run_sqe=0
        self.engine_is_running=False
        
    def run(self):
        '''循环运行'''
        self.is_running=True
        #设置运行类型
        self.is_update=self.run_list[self.run_sqe]
        settings.S_is_update=self.is_update

        self.eng=Engine(settings.S_target_website)
        self.eng.start()
        
        self.run_sqe+=1
        if self.run_sqe>=len(self.run_list):
            self.run_sqe=0
            
        self.engine_is_running=True
        self.eng.join()
        if self.is_running:
            self.run()
        
    def stop(self):
        self.eng.is_running=False
        self.is_running=False
开发者ID:lvshuchengyin,项目名称:mycode,代码行数:31,代码来源:controller.py

示例10: on_init

    def on_init(self):
        Engine.on_init(self)

        self.winner_text = Text(self.width/4, 80, str(""), 30)
        self.add(self.winner_text)
        self.start_game_text = Text(self.width/3, 120, str("Press START"), 30)
        self.add(self.start_game_text)

        self.scoreP1_text = Text(self.width/4, 30, str(self.scoreP1), 50)
        self.scoreP2_text = Text(self.width - self.width/4, 30, str(self.scoreP2), 50)
        self.add(self.scoreP1_text)
        self.add(self.scoreP2_text)

        self.fps_text = Text(280, 220, "30")
        self.add(self.fps_text)
        self.ball = Ball(self.width/2, self.height/2, "ball.png")
        self.add(self.ball)
        self.playerOne = Paddle(20, self.height/2, "paddle.png")
        self.add(self.playerOne)
        self.playerTwo = Paddle(320 - 20, self.height/2, "paddle.png")
        self.add(self.playerTwo)

        self.sfx_padOne = soundEffect("blip1.wav")
        self.sfx_padTwo = soundEffect("blip2.wav")
        self.music_bg = musicPlayer("UGH1.wav", -1)
        self.music_bg.play()

        self.start_game(False)
开发者ID:JackOfDawn,项目名称:GCW-Python,代码行数:28,代码来源:main.py

示例11: start_engine

def start_engine(args):
    if not (args.name and args.engine_cfg):
        LOG.error('Need name and engine cfg')
        return
    utils.create_files([engine_cfg])
    if args.purge:
        utils.purge_disabled(engine_cfg)
    if utils.check_exists_and_enabled(args.name, engine_cfg):
        LOG.error("An engine of the same name %s is already "
                  "registered and running", args.name)
        return
    if utils.check_exists_and_disabled(args.name, engine_cfg):
        LOG.error("And engine of the same name %s is already "
                  "registered, but disabled. Run with purge?", args.name)
        return
    try:
        cfg_data = dict(utils.load_yaml(args.engine_cfg))[args.name]
        cfg = {
            args.name: {
                'cfg': os.path.join(os.getcwd(), args.engine_cfg),
                'pid': os.getpid(),
                'backend': cfg_data['backend'],
                'enabled': True
            }
        }
        utils.write_yaml(cfg, engine_cfg)
        LOG.info('Added %s to engine cfg', args.name)
        entropy_engine = Engine(args.name, **cfg_data)
        entropy_engine.run()
    except Exception:
        LOG.exception("Could not start engine %s", args.name)
        return
开发者ID:openstack,项目名称:entropy,代码行数:32,代码来源:__main__.py

示例12: Test

class Test(unittest.TestCase):

    #--------------------------------------------------------------------------
    def setUp(self):
        self.eng = Engine()
        self.que = Queuer()
        self.gen = TaskerGenerator(self.eng,
                                   'taskerGen',
                                   self.que,
                                   timeStart=1.0,
                                   timeEnd=1000.0,
                                   taskStart=1.0,
                                   taskEnd=500.0,
                                   limit=100)
        self.svc = Servicer(self.que, self.eng)

    #--------------------------------------------------------------------------
    def tearDown(self):
        pass

    #--------------------------------------------------------------------------
    def test_init(self):
        pass

    #--------------------------------------------------------------------------
    def test_run(self):
        # Test
        self.gen.start()
        self.svc.start()
        self.eng.runEngine()

        # Expectations
        self.svc.reportStats()
开发者ID:jrecuero,项目名称:simulator,代码行数:33,代码来源:test_simulator.py

示例13: __init__

    def __init__(self, host_device, engine_id, config_source):
        """
        """
        Engine.__init__(self, host_device, engine_id, config_source)

        # check that we have all the required attributes for an f-engine
        assert hasattr(self, 'vacc_len'), 'x-engine must have a vector accumulator length'
开发者ID:sma-wideband,项目名称:corr2,代码行数:7,代码来源:xengine.py

示例14: on_err_disconnect

 def on_err_disconnect(self):
     """
     The engine node disconnected from the message bus.
     This will emit a SigDisconnect signal.
     """
     Engine.on_err_disconnect(self)
     self.parent.emit(QtCore.SIGNAL(SigDisconnect))
开发者ID:tito2016,项目名称:Python-Project,代码行数:7,代码来源:pyside_engine.py

示例15: IndexerThread

class IndexerThread(threading.Thread):

    def __init__(self, queue, index_directory, log_rate, log_file):

        self.search_engine = Engine(index_directory)
        self.buffered_writer = self.search_engine.new_buffered_writer(120, 100 , 512)
        self.queue = queue
        self.log_count = 0
        self.log_rate = log_rate
        self.log_file = log_file
        threading.Thread.__init__(self) # needed for thread to be instantiated

  
    def run(self):

        while True:

            while not self.queue.empty():

                path, add_or_delete = self.queue.get_nowait()
                time_taken, successful = self.add_or_remove(path, add_or_delete)

                if successful: 
                    if self.log_count % self.log_rate == 0:
                        if add_or_delete:
                            log(self.log_file, ("time taken to index path: ", [time_taken, path, str(datetime.now())]))
                        else:
                            log(self.log_file, ("time taken to un-index path: ", [time_taken, path, str(datetime.now())]))
                else:
                    log(self.log_file,("index/ un-index of path was unsuccessful: ", [path, str(datetime.now())]))

                self.log_count += 1


    """
    This method indexes/ removes an index of 'path', and returns the time taken to do so. 
        params:
            - path: the path to index/ remove from index
            - add_or_delete: True for add/ False for delete
        return:
            - time_taken (0.0 if unsuccessful; i.e. directory, not file)
            - boolean of successful or not (whether file or directory)
    """
    def add_or_remove(self, path, add_or_delete):

        if os.path.isdir(path):
            return [0.0, False]

        t0 = time.time()
        
        if add_or_delete:
            self.search_engine.add_document(path, self.buffered_writer)
        else:
            self.search_engine.remove_document(path, self.buffered_writer)

        t1 = time.time()
        time_taken = t1 - t0

        return [time_taken, True]
开发者ID:theshop,项目名称:file-mi,代码行数:59,代码来源:fileMonitorQueueLogged.py


注:本文中的engine.Engine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。