prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
<|fim_middle|>
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
<|fim_middle|>
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
<|fim_middle|>
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | return wait_for_event(ok_codes, self._events, self._event_cond) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
<|fim_middle|>
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | return wait_for_response(event_id, self._responses, self._responses_cond) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
<|fim_middle|>
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | return wait_for_special(event_id, self._responses, self._responses_cond) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
<|fim_middle|>
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
<|fim_middle|>
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
<|fim_middle|>
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
<|fim_middle|>
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
<|fim_middle|>
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self._main() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
<|fim_middle|>
<|fim▁end|> | if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
<|fim_middle|>
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self._datas.put(('burst', channel, data)) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
<|fim_middle|>
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self._datas.put(('broadcast', channel, data)) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
<|fim_middle|>
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
<|fim_middle|>
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self.channels[channel].on_broadcast_data(data) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
<|fim_middle|>
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | self.channels[channel].on_burst_data(data) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
<|fim_middle|>
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _logger.warning("Unknown data type '%s': %r", data_type, data) |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
<|fim_middle|>
<|fim▁end|> | _logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join() |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def <|fim_middle|>(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | __init__ |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def <|fim_middle|>(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | new_channel |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def <|fim_middle|>(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | request_message |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def <|fim_middle|>(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | set_network_key |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def <|fim_middle|>(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | wait_for_event |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def <|fim_middle|>(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | wait_for_response |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def <|fim_middle|>(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | wait_for_special |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def <|fim_middle|>(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _worker_response |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def <|fim_middle|>(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _worker_event |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def <|fim_middle|>(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _worker |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def <|fim_middle|>(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | _main |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def <|fim_middle|>(self):
self._main()
def stop(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | start |
<|file_name|>node.py<|end_file_name|><|fim▁begin|># Ant
#
# Copyright (c) 2012, Gustav Tiger <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import collections
import threading
import logging
import Queue
from ant.base.ant import Ant
from ant.base.message import Message
from ant.easy.channel import Channel
from ant.easy.filter import wait_for_event, wait_for_response, wait_for_special
_logger = logging.getLogger("garmin.ant.easy.node")
class Node():
def __init__(self):
self._responses_cond = threading.Condition()
self._responses = collections.deque()
self._event_cond = threading.Condition()
self._events = collections.deque()
self._datas = Queue.Queue()
self.channels = {}
self.ant = Ant()
self._running = True
self._worker_thread = threading.Thread(target=self._worker, name="ant.easy")
self._worker_thread.start()
def new_channel(self, ctype):
channel = Channel(0, self, self.ant)
self.channels[0] = channel
channel._assign(ctype, 0x00)
return channel
def request_message(self, messageId):
_logger.debug("requesting message %#02x", messageId)
self.ant.request_message(0, messageId)
_logger.debug("done requesting message %#02x", messageId)
return self.wait_for_special(messageId)
def set_network_key(self, network, key):
self.ant.set_network_key(network, key)
return self.wait_for_response(Message.ID.SET_NETWORK_KEY)
def wait_for_event(self, ok_codes):
return wait_for_event(ok_codes, self._events, self._event_cond)
def wait_for_response(self, event_id):
return wait_for_response(event_id, self._responses, self._responses_cond)
def wait_for_special(self, event_id):
return wait_for_special(event_id, self._responses, self._responses_cond)
def _worker_response(self, channel, event, data):
self._responses_cond.acquire()
self._responses.append((channel, event, data))
self._responses_cond.notify()
self._responses_cond.release()
def _worker_event(self, channel, event, data):
if event == Message.Code.EVENT_RX_BURST_PACKET:
self._datas.put(('burst', channel, data))
elif event == Message.Code.EVENT_RX_BROADCAST:
self._datas.put(('broadcast', channel, data))
else:
self._event_cond.acquire()
self._events.append((channel, event, data))
self._event_cond.notify()
self._event_cond.release()
def _worker(self):
self.ant.response_function = self._worker_response
self.ant.channel_event_function = self._worker_event
# TODO: check capabilities
self.ant.start()
def _main(self):
while self._running:
try:
(data_type, channel, data) = self._datas.get(True, 1.0)
self._datas.task_done()
if data_type == 'broadcast':
self.channels[channel].on_broadcast_data(data)
elif data_type == 'burst':
self.channels[channel].on_burst_data(data)
else:
_logger.warning("Unknown data type '%s': %r", data_type, data)
except Queue.Empty as e:
pass
def start(self):
self._main()
def <|fim_middle|>(self):
if self._running:
_logger.debug("Stoping ant.easy")
self._running = False
self.ant.stop()
self._worker_thread.join()
<|fim▁end|> | stop |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:<|fim▁hole|> def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()<|fim▁end|> | # m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
|
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
<|fim_middle|>
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | return ClickMenu(*args, **kwargs) |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
<|fim_middle|>
<|fim▁end|> | """Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill() |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
<|fim_middle|>
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2 |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
<|fim_middle|>
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time() |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
<|fim_middle|>
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | """Draw an overlay on top of the map, showing various information
about position etc.""" |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
<|fim_middle|>
<|fim▁end|> | text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill() |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
<|fim_middle|>
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time() |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
<|fim_middle|>
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time() |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def <|fim_middle|>(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | getModule |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def <|fim_middle|>(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | __init__ |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def <|fim_middle|>(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | handleMessage |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def <|fim_middle|>(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def drawNewWaypoint(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | drawMapOverlay |
<|file_name|>_mod_clickMenu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Menu for quickly adding waypoints when on move
#----------------------------------------------------------------------------
# Copyright 2007-2008, Oliver White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule
import cairo
from time import time
from math import pi
def getModule(*args, **kwargs):
return ClickMenu(*args, **kwargs)
class ClickMenu(RanaModule):
"""Overlay info on the map"""
def __init__(self, *args, **kwargs):
RanaModule.__init__(self, *args, **kwargs)
self.lastWaypoint = "(none)"
self.lastWaypointAddTime = 0
self.messageLingerTime = 2
def handleMessage(self, message, messageType, args):
if message == "addWaypoint":
m = self.m.get("waypoints", None)
if m is not None:
self.lastWaypoint = m.newWaypoint()
self.lastWaypointAddTime = time()
def drawMapOverlay(self, cr):
"""Draw an overlay on top of the map, showing various information
about position etc."""
# waypoins will be done in another way, so this is disabled for the time being
# (x,y,w,h) = self.get('viewport')
#
# dt = time() - self.lastWaypointAddTime
# if(dt > 0 and dt < self.messageLingerTime):
# self.drawNewWaypoint(cr, x+0.5*w, y+0.5*h, w*0.3)
# else:
# m = self.m.get('clickHandler', None)
# if(m != None):
# m.registerXYWH(x+0.25*w,y+0.25*h,w*0.5,h*0.5, "clickMenu:addWaypoint")
def <|fim_middle|>(self, cr, x, y, size):
text = self.lastWaypoint
cr.set_font_size(200)
extents = cr.text_extents(text)
(w, h) = (extents[2], extents[3])
cr.set_source_rgb(0, 0, 0.5)
cr.arc(x, y, size, 0, 2 * pi)
cr.fill()
x1 = x - 0.5 * w
y1 = y + 0.5 * h
border = 20
cr.set_source_rgb(1, 1, 1)
cr.move_to(x1, y1)
cr.show_text(text)
cr.fill()
<|fim▁end|> | drawNewWaypoint |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL) <|fim▁hole|> while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()<|fim▁end|> | pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
|
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
<|fim_middle|>
<|fim▁end|> | def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term() |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
<|fim_middle|>
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()
<|fim▁end|> | f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close() |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
<|fim_middle|>
<|fim▁end|> | context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term() |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
<|fim_middle|>
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()
<|fim▁end|> | result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result)) |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
<|fim_middle|>
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()
<|fim▁end|> | self.log("Received unknown task: %s", task_name) |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def <|fim_middle|>(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def handle(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()
<|fim▁end|> | log |
<|file_name|>registration_worker.py<|end_file_name|><|fim▁begin|>import zmq
import datetime
import pytz
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from registrations.models import Registration
from registrations import handlers
from registrations import tasks
class Command(BaseCommand):
def log(self, message):
f = open(settings.TASK_LOG_PATH, 'a')
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
log_message = "%s\t%s\n" % (now, message)
self.stdout.write(log_message)
f.write(log_message)
f.close()
def <|fim_middle|>(self, *args, **options):
context = zmq.Context()
pull_socket = context.socket(zmq.PULL)
pull_socket.bind('tcp://*:7002')
self.log("Registration Worker ZMQ Socket Bound to 7002")
while True:
try:
data = pull_socket.recv_json()
task_name = data.pop('task')
task_kwargs = data.pop('kwargs')
self.log("Got task '%s' with kwargs: %s" % (task_name, task_kwargs))
if hasattr(tasks, task_name):
result = getattr(tasks, task_name)(**task_kwargs)
self.log("Task '%s' result: %s" % (task_name, result))
else:
self.log("Received unknown task: %s", task_name)
except Exception, e:
self.log("Error: %s" % e)
pull_socket.close()
context.term()
<|fim▁end|> | handle |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":<|fim▁hole|><|fim▁end|> | main() |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
<|fim_middle|>
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | '''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None] |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
<|fim_middle|>
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members) |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
<|fim_middle|>
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | '''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
<|fim_middle|>
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | '''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None] |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
<|fim_middle|>
if __name__ == "__main__":
main()
<|fim▁end|> | load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace() |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | main() |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def <|fim_middle|>(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | __init__ |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def <|fim_middle|>(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | get_archive_object_tar |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def <|fim_middle|>(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def main():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | read_files |
<|file_name|>load_archive.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tarfile
class load_data:
'''
class to load txt data
'''
def __init__(self, filename):
self.filename = filename
tfile, members = self.get_archive_object_tar()
self.read_files(tfile, members)
def get_archive_object_tar(self):
'''
return tarfile object and its members
'''
tfile = tarfile.open(name=self.filename)
members = tfile.getnames()
return tfile, members
def read_files(self, tfile, members):
'''
array with txt data from tarfile object
'''
self.data = [tfile.extractfile(member).read() for member in members if
tfile.extractfile(member) is not None]
def <|fim_middle|>():
load_data('enron_mail_clean.tar.gz')
import pdb
pdb.set_trace()
if __name__ == "__main__":
main()
<|fim▁end|> | main |
<|file_name|>yarrharr.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright © 2013, 2014, 2017, 2020 Tom Most <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this Program, or any covered work, by linking or
# combining it with OpenSSL (or a modified version of that library),
# containing parts covered by the terms of the OpenSSL License, the
# licensors of this Program grant you additional permission to convey
# the resulting work. Corresponding Source for a non-source form of
# such a combination shall include the source code for the parts of<|fim▁hole|>import argparse
import os
import sys
import yarrharr
def main(argv=sys.argv[1:]):
parser = argparse.ArgumentParser(description="Yarrharr feed reader")
parser.add_argument("--version", action="version", version=yarrharr.__version__)
parser.parse_args(argv)
os.environ["DJANGO_SETTINGS_MODULE"] = "yarrharr.settings"
from yarrharr.application import run
run()<|fim▁end|> | # OpenSSL used as well as that of the covered work.
from __future__ import absolute_import
|
<|file_name|>yarrharr.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright © 2013, 2014, 2017, 2020 Tom Most <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this Program, or any covered work, by linking or
# combining it with OpenSSL (or a modified version of that library),
# containing parts covered by the terms of the OpenSSL License, the
# licensors of this Program grant you additional permission to convey
# the resulting work. Corresponding Source for a non-source form of
# such a combination shall include the source code for the parts of
# OpenSSL used as well as that of the covered work.
from __future__ import absolute_import
import argparse
import os
import sys
import yarrharr
def main(argv=sys.argv[1:]):
p<|fim_middle|>
<|fim▁end|> | arser = argparse.ArgumentParser(description="Yarrharr feed reader")
parser.add_argument("--version", action="version", version=yarrharr.__version__)
parser.parse_args(argv)
os.environ["DJANGO_SETTINGS_MODULE"] = "yarrharr.settings"
from yarrharr.application import run
run()
|
<|file_name|>yarrharr.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright © 2013, 2014, 2017, 2020 Tom Most <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this Program, or any covered work, by linking or
# combining it with OpenSSL (or a modified version of that library),
# containing parts covered by the terms of the OpenSSL License, the
# licensors of this Program grant you additional permission to convey
# the resulting work. Corresponding Source for a non-source form of
# such a combination shall include the source code for the parts of
# OpenSSL used as well as that of the covered work.
from __future__ import absolute_import
import argparse
import os
import sys
import yarrharr
def m<|fim_middle|>argv=sys.argv[1:]):
parser = argparse.ArgumentParser(description="Yarrharr feed reader")
parser.add_argument("--version", action="version", version=yarrharr.__version__)
parser.parse_args(argv)
os.environ["DJANGO_SETTINGS_MODULE"] = "yarrharr.settings"
from yarrharr.application import run
run()
<|fim▁end|> | ain( |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1 <|fim▁hole|>
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])<|fim▁end|> | else:
self.npc.vy = 0 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
<|fim_middle|>
<|fim▁end|> | def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1]) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
<|fim_middle|>
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized." |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
<|fim_middle|>
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
<|fim_middle|>
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
<|fim_middle|>
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos ) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
<|fim_middle|>
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = [] |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
<|fim_middle|>
<|fim▁end|> | print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1]) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
<|fim_middle|>
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
<|fim_middle|>
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | if self.npc.vy < 0.3:
self.npc.vy += 0.1 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
<|fim_middle|>
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.npc.vy += 0.1 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
<|fim_middle|>
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.npc.vy = 0 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
<|fim_middle|>
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | collidingPoints.append(point) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
<|fim_middle|>
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.npc.processPointCollision(collidingPoints) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
<|fim_middle|>
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.npc.vx = 0.1 |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
<|fim_middle|>
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.pts.append( pos ) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
<|fim_middle|>
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | self.pts = [] |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
<|fim_middle|>
<|fim▁end|> | self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1]) |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def <|fim_middle|>(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | __init__ |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def <|fim_middle|>(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | update |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def <|fim_middle|>(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | processKeyDown |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def <|fim_middle|>(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | processMouseMotion |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def <|fim_middle|>(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def processMouseButtonUp(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | processMouseButtonDown |
<|file_name|>level0.py<|end_file_name|><|fim▁begin|>import sys,os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
#from ethosgame.ethos.level import Level
from ..level import Level
#from ethosgame.ethos.gameobject import GameObject
from ..gameobject import GameObject
#from ethosgame.ethos.drawnobject import DrawnObject
from ..drawnobject import DrawnObject
import pygame
from pygame.locals import *
from pygame import Color, image, font, sprite
class Level0(Level):
def __init__(self):
super(Level0, self).__init__()
self.activeSprites = sprite.RenderClear()
self.drawnSprites = []
self.npc = GameObject(image.load('User.png'), 100,50)
self.activeSprites.add(self.npc)
self.block1 = GameObject(image.load('platform.png'), 100, 400)
self.activeSprites.add(self.block1);
self.mousex = 0
self.mousey = 0
#The highest height our npc
#can climb. If a the dY with a
#point is higher than this, the
#npc will just fall to his death
self.MAX_HILL_HEIGHT = 3
self.toDrawRectTopLeft = (0,0)
self.toDrawRectBottomRight = (0,0)
self.drawing = False
self.pts = []
print "Level 0 initialized."
def update(self, dT):
#print "Running level0"
#Character info
for gobject in self.activeSprites:
if gobject is not self.npc:
if not gobject.rect.colliderect(self.npc.rect):
#if self.npc.vy < 0.3 and (gobject.rect.y >= self.npc.rect.y + self.npc.rect.height):
if self.npc.vy < 0.3:
self.npc.vy += 0.1
else:
self.npc.vy = 0
gobject.update(dT)
collidingPoints = []
for drawnstuff in self.drawnSprites:
for point in drawnstuff.pts:
x = self.npc.rect.collidepoint(point)
if x:
collidingPoints.append(point)
if(len(collidingPoints) > 0):
self.npc.processPointCollision(collidingPoints)
def processKeyDown(self,key):
print "You hit the key " + str(key) + "!"
if key == pygame.K_RIGHT:
self.npc.vx = 0.1
def processMouseMotion(self,pos):
#print "Your mouse is at " + str(pos[0]) + " " + str(pos[1])
self.mousex = pos[0]
self.mousey = pos[1]
if self.drawing and len(self.pts) < 100:
self.pts.append( pos )
def processMouseButtonDown(self, pos):
print "Ya clicked at " + str(pos[0]) + " " + str(pos[1]) + " ya goof!"
self.drawing = True
self.toDrawRectTopLeft = (pos[0],pos[1])
if len(self.pts) > 0:
self.pts = []
def <|fim_middle|>(self, pos):
print "Ya let go"
if self.drawing is True:
self.drawing = False
self.drawnSprites.append ( DrawnObject(self.pts) )
self.toDrawRectBottomRight = (pos[0], pos[1])
<|fim▁end|> | processMouseButtonUp |
<|file_name|>filters.py<|end_file_name|><|fim▁begin|>from rest_framework.filters import (
FilterSet
)
from trialscompendium.trials.models import Treatment
<|fim▁hole|> """
class Meta:
model = Treatment
fields = {'id': ['exact', 'in'],
'no_replicate': ['exact', 'in', 'gte', 'lte'],
'nitrogen_treatment': ['iexact', 'in', 'icontains'],
'phosphate_treatment': ['iexact', 'in', 'icontains'],
'tillage_practice': ['iexact', 'in', 'icontains'],
'cropping_system': ['iexact', 'in', 'icontains'],
'crops_grown': ['iexact', 'in', 'icontains'],
'farm_yard_manure': ['iexact', 'in', 'icontains'],
'farm_residue': ['iexact', 'in', 'icontains'],
}
order_by = ['tillage_practice', 'cropping_system', 'crops_grown']<|fim▁end|> | class TreatmentListFilter(FilterSet):
"""
Filter query list from treatment database table |
<|file_name|>filters.py<|end_file_name|><|fim▁begin|>from rest_framework.filters import (
FilterSet
)
from trialscompendium.trials.models import Treatment
class TreatmentListFilter(FilterSet):
<|fim_middle|>
<|fim▁end|> | """
Filter query list from treatment database table
"""
class Meta:
model = Treatment
fields = {'id': ['exact', 'in'],
'no_replicate': ['exact', 'in', 'gte', 'lte'],
'nitrogen_treatment': ['iexact', 'in', 'icontains'],
'phosphate_treatment': ['iexact', 'in', 'icontains'],
'tillage_practice': ['iexact', 'in', 'icontains'],
'cropping_system': ['iexact', 'in', 'icontains'],
'crops_grown': ['iexact', 'in', 'icontains'],
'farm_yard_manure': ['iexact', 'in', 'icontains'],
'farm_residue': ['iexact', 'in', 'icontains'],
}
order_by = ['tillage_practice', 'cropping_system', 'crops_grown'] |
<|file_name|>filters.py<|end_file_name|><|fim▁begin|>from rest_framework.filters import (
FilterSet
)
from trialscompendium.trials.models import Treatment
class TreatmentListFilter(FilterSet):
"""
Filter query list from treatment database table
"""
class Meta:
<|fim_middle|>
<|fim▁end|> | model = Treatment
fields = {'id': ['exact', 'in'],
'no_replicate': ['exact', 'in', 'gte', 'lte'],
'nitrogen_treatment': ['iexact', 'in', 'icontains'],
'phosphate_treatment': ['iexact', 'in', 'icontains'],
'tillage_practice': ['iexact', 'in', 'icontains'],
'cropping_system': ['iexact', 'in', 'icontains'],
'crops_grown': ['iexact', 'in', 'icontains'],
'farm_yard_manure': ['iexact', 'in', 'icontains'],
'farm_residue': ['iexact', 'in', 'icontains'],
}
order_by = ['tillage_practice', 'cropping_system', 'crops_grown'] |
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
def show_title(self, obj):
if not obj.target:
return '-- %s --' % ugettext('empty position')
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
show_title.short_description = _('Title')
def is_filled(self, obj):
if obj.target:
return True
else:
return False
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till
is_active.short_description = _('Active')<|fim▁hole|> list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',)
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)<|fim▁end|> | is_active.boolean = True
|
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
<|fim_middle|>
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)
<|fim▁end|> | def show_title(self, obj):
if not obj.target:
return '-- %s --' % ugettext('empty position')
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
show_title.short_description = _('Title')
def is_filled(self, obj):
if obj.target:
return True
else:
return False
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till
is_active.short_description = _('Active')
is_active.boolean = True
list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',) |
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
def show_title(self, obj):
<|fim_middle|>
show_title.short_description = _('Title')
def is_filled(self, obj):
if obj.target:
return True
else:
return False
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till
is_active.short_description = _('Active')
is_active.boolean = True
list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',)
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)
<|fim▁end|> | if not obj.target:
return '-- %s --' % ugettext('empty position')
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) |
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
def show_title(self, obj):
if not obj.target:
return '-- %s --' % ugettext('empty position')
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
show_title.short_description = _('Title')
def is_filled(self, obj):
<|fim_middle|>
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till
is_active.short_description = _('Active')
is_active.boolean = True
list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',)
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)
<|fim▁end|> | if obj.target:
return True
else:
return False |
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
def show_title(self, obj):
if not obj.target:
return '-- %s --' % ugettext('empty position')
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
show_title.short_description = _('Title')
def is_filled(self, obj):
if obj.target:
return True
else:
return False
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
<|fim_middle|>
is_active.short_description = _('Active')
is_active.boolean = True
list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',)
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)
<|fim▁end|> | if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till |
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin
from django.utils.translation import ugettext, ugettext_lazy as _
from ella.positions.models import Position
from ella.utils import timezone
class PositionOptions(admin.ModelAdmin):
def show_title(self, obj):
if not obj.target:
<|fim_middle|>
else:
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
show_title.short_description = _('Title')
def is_filled(self, obj):
if obj.target:
return True
else:
return False
is_filled.short_description = _('Filled')
is_filled.boolean = True
def is_active(self, obj):
if obj.disabled:
return False
now = timezone.now()
active_from = not obj.active_from or obj.active_from <= now
active_till = not obj.active_till or obj.active_till > now
return active_from and active_till
is_active.short_description = _('Active')
is_active.boolean = True
list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',)
list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',)
search_fields = ('box_type', 'text',)
# suggest_fields = {'category': ('tree_path', 'title', 'slug',),}
admin.site.register(Position, PositionOptions)
<|fim▁end|> | return '-- %s --' % ugettext('empty position') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.