prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): <|fim_middle|> return list() <|fim▁end|>
block_number = item["blockNumber"] return [block_number]
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def <|fim_middle|>( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
deploy_token
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def <|fim_middle|>( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
deploy_tokens_and_fund_accounts
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def <|fim_middle|>( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
deploy_service_registry_and_set_urls
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def <|fim_middle|>(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
get_test_contract
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def <|fim_middle|>(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def get_list_of_block_numbers(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
deploy_rpc_test_contract
<|file_name|>smartcontracts.py<|end_file_name|><|fim▁begin|>import os from typing import List, Tuple from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import get_random_service from raiden.network.proxies.service_registry import ServiceRegistry from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.utils import typing from raiden.utils.smart_contracts import deploy_contract_web3 from raiden.utils.solc import compile_files_cwd from raiden_contracts.constants import CONTRACT_HUMAN_STANDARD_TOKEN from raiden_contracts.contract_manager import ContractManager def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=(initial_amount, decimals, token_name, token_symbol), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address ) def deploy_tokens_and_fund_accounts( token_amount: int, number_of_tokens: int, deploy_service: BlockChainService, participants: typing.List[typing.Address], contract_manager: ContractManager, ) -> typing.List[typing.TokenAddress]: """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): number of token instances that will be created deploy_service (BlockChainService): the blockchain connection that will deploy participants (list(address)): participant addresses that will receive tokens """ result = list() for _ in range(number_of_tokens): token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, deploy_service.client, contract_manager=contract_manager, constructor_arguments=(token_amount, 2, "raiden", "Rd"), ) result.append(token_address) # only the creator of the token starts with a balance (deploy_service), # transfer from the creator to the other nodes for transfer_to in participants: deploy_service.token(token_address).transfer( to_address=transfer_to, amount=token_amount // len(participants) ) return result def deploy_service_registry_and_set_urls( private_keys, web3, contract_manager, service_registry_address ) -> Tuple[ServiceRegistry, List[str]]: urls = ["http://foo", "http://boo", "http://coo"] c1_client = JSONRPCClient(web3, private_keys[0]) c1_service_proxy = ServiceRegistry( jsonrpc_client=c1_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c2_client = JSONRPCClient(web3, private_keys[1]) c2_service_proxy = ServiceRegistry( jsonrpc_client=c2_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) c3_client = JSONRPCClient(web3, private_keys[2]) c3_service_proxy = ServiceRegistry( jsonrpc_client=c3_client, service_registry_address=service_registry_address, contract_manager=contract_manager, ) # Test that getting a random service for an empty registry returns None pfs_address = get_random_service(c1_service_proxy, "latest") assert pfs_address is None # Test that setting the urls works c1_service_proxy.set_url(urls[0]) c2_service_proxy.set_url(urls[1]) c3_service_proxy.set_url(urls[2]) return c1_service_proxy, urls def get_test_contract(name): contract_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "smart_contracts", name) ) contracts = compile_files_cwd([contract_path]) return contract_path, contracts def deploy_rpc_test_contract(deploy_client, name): contract_path, contracts = get_test_contract(f"{name}.sol") contract_proxy, _ = deploy_client.deploy_solidity_contract( name, contracts, libraries=dict(), constructor_parameters=None, contract_path=contract_path ) return contract_proxy def <|fim_middle|>(item): """ Creates a list of block numbers of the given list/single event""" if isinstance(item, list): return [element["blockNumber"] for element in item] if isinstance(item, dict): block_number = item["blockNumber"] return [block_number] return list() <|fim▁end|>
get_list_of_block_numbers
<|file_name|>_y.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class YValidator(_plotly_utils.basevalidators.DataArrayValidator): def __init__(self, plotly_name="y", parent_name="bar", **kwargs):<|fim▁hole|> parent_name=parent_name, anim=kwargs.pop("anim", True), edit_type=kwargs.pop("edit_type", "calc+clearAxisTypes"), role=kwargs.pop("role", "data"), **kwargs )<|fim▁end|>
super(YValidator, self).__init__( plotly_name=plotly_name,
<|file_name|>_y.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class YValidator(_plotly_utils.basevalidators.DataArrayValidator): <|fim_middle|> <|fim▁end|>
def __init__(self, plotly_name="y", parent_name="bar", **kwargs): super(YValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, anim=kwargs.pop("anim", True), edit_type=kwargs.pop("edit_type", "calc+clearAxisTypes"), role=kwargs.pop("role", "data"), **kwargs )
<|file_name|>_y.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class YValidator(_plotly_utils.basevalidators.DataArrayValidator): def __init__(self, plotly_name="y", parent_name="bar", **kwargs): <|fim_middle|> <|fim▁end|>
super(YValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, anim=kwargs.pop("anim", True), edit_type=kwargs.pop("edit_type", "calc+clearAxisTypes"), role=kwargs.pop("role", "data"), **kwargs )
<|file_name|>_y.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class YValidator(_plotly_utils.basevalidators.DataArrayValidator): def <|fim_middle|>(self, plotly_name="y", parent_name="bar", **kwargs): super(YValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, anim=kwargs.pop("anim", True), edit_type=kwargs.pop("edit_type", "calc+clearAxisTypes"), role=kwargs.pop("role", "data"), **kwargs ) <|fim▁end|>
__init__
<|file_name|>page_links_to_edge_list_wiki.py<|end_file_name|><|fim▁begin|>import optparse import pickle<|fim▁hole|> parser = optparse.OptionParser() parser.add_option('-i','--input', dest = 'input_file', help = 'input_file') parser.add_option('-o','--output', dest = 'output_file', help = 'output_file') (options, args) = parser.parse_args() if options.input_file is None: options.input_file = raw_input('Enter input file:') if options.output_file is None: options.output_file = raw_input('Enter output file:') input_file = options.input_file output_file = options.output_file #define the dictionary url:wiki_id wiki_from_url_dict = {} with open('../../datasets/dbpedia/page_ids_en_2016.ttl','r') as f: for line in f: line = line.split(' ') if line[0] == '#': continue url = line[0] wiki_id_list = line[2].split('\"') wiki_id = wiki_id_list[1] print(url, wiki_id) wiki_from_url_dict[url] = int(wiki_id) output_file_write = open(output_file,'w') #iterate through the page links and turn urls into wiki_ids max_wiki_id = max(wiki_from_url_dict.values()) + 1 local_id = {} count = 0 with open(input_file) as page_links: for line in page_links: line = line.split(' ') if line[0] == '#': continue url_1 = line[0] url_2 = line[2] #if wiki_id not found, assign an id = max_wiki_id and increment max_wiki_id try: wiki_id1 = wiki_from_url_dict[url_1] #first entity has wiki_id try: wiki_id2 = wiki_from_url_dict[url_2] #first and second entities have wiki_ids except (KeyError, IndexError): #first entity has wiki_id, second entity doesn't try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 except (KeyError, IndexError): #first entity doesn't have wiki_id try: wiki_id1 = local_id[url_1] except (KeyError, IndexError): wiki_id1 = max_wiki_id local_id[url_1] = wiki_id1 max_wiki_id += 1 try: #first entity doesn't have wiki_id, second entity has it wiki_id2 = wiki_from_url_dict[url_2] except (KeyError, IndexError): #neither first nor second entity have wiki_ids try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 output_file_write.write('%d %d\n' %(wiki_id1,wiki_id2)) print count count += 1 output_file_write.close() pickle.dump(local_id,open('../../datasets/dbpedia/local_id_to_url_full_mapping_based.p','wb'))<|fim▁end|>
#converts urls to wiki_id
<|file_name|>page_links_to_edge_list_wiki.py<|end_file_name|><|fim▁begin|>import optparse import pickle #converts urls to wiki_id parser = optparse.OptionParser() parser.add_option('-i','--input', dest = 'input_file', help = 'input_file') parser.add_option('-o','--output', dest = 'output_file', help = 'output_file') (options, args) = parser.parse_args() if options.input_file is None: <|fim_middle|> if options.output_file is None: options.output_file = raw_input('Enter output file:') input_file = options.input_file output_file = options.output_file #define the dictionary url:wiki_id wiki_from_url_dict = {} with open('../../datasets/dbpedia/page_ids_en_2016.ttl','r') as f: for line in f: line = line.split(' ') if line[0] == '#': continue url = line[0] wiki_id_list = line[2].split('\"') wiki_id = wiki_id_list[1] print(url, wiki_id) wiki_from_url_dict[url] = int(wiki_id) output_file_write = open(output_file,'w') #iterate through the page links and turn urls into wiki_ids max_wiki_id = max(wiki_from_url_dict.values()) + 1 local_id = {} count = 0 with open(input_file) as page_links: for line in page_links: line = line.split(' ') if line[0] == '#': continue url_1 = line[0] url_2 = line[2] #if wiki_id not found, assign an id = max_wiki_id and increment max_wiki_id try: wiki_id1 = wiki_from_url_dict[url_1] #first entity has wiki_id try: wiki_id2 = wiki_from_url_dict[url_2] #first and second entities have wiki_ids except (KeyError, IndexError): #first entity has wiki_id, second entity doesn't try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 except (KeyError, IndexError): #first entity doesn't have wiki_id try: wiki_id1 = local_id[url_1] except (KeyError, IndexError): wiki_id1 = max_wiki_id local_id[url_1] = wiki_id1 max_wiki_id += 1 try: #first entity doesn't have wiki_id, second entity has it wiki_id2 = wiki_from_url_dict[url_2] except (KeyError, IndexError): #neither first nor second entity have wiki_ids try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 output_file_write.write('%d %d\n' %(wiki_id1,wiki_id2)) print count count += 1 output_file_write.close() pickle.dump(local_id,open('../../datasets/dbpedia/local_id_to_url_full_mapping_based.p','wb')) <|fim▁end|>
options.input_file = raw_input('Enter input file:')
<|file_name|>page_links_to_edge_list_wiki.py<|end_file_name|><|fim▁begin|>import optparse import pickle #converts urls to wiki_id parser = optparse.OptionParser() parser.add_option('-i','--input', dest = 'input_file', help = 'input_file') parser.add_option('-o','--output', dest = 'output_file', help = 'output_file') (options, args) = parser.parse_args() if options.input_file is None: options.input_file = raw_input('Enter input file:') if options.output_file is None: <|fim_middle|> input_file = options.input_file output_file = options.output_file #define the dictionary url:wiki_id wiki_from_url_dict = {} with open('../../datasets/dbpedia/page_ids_en_2016.ttl','r') as f: for line in f: line = line.split(' ') if line[0] == '#': continue url = line[0] wiki_id_list = line[2].split('\"') wiki_id = wiki_id_list[1] print(url, wiki_id) wiki_from_url_dict[url] = int(wiki_id) output_file_write = open(output_file,'w') #iterate through the page links and turn urls into wiki_ids max_wiki_id = max(wiki_from_url_dict.values()) + 1 local_id = {} count = 0 with open(input_file) as page_links: for line in page_links: line = line.split(' ') if line[0] == '#': continue url_1 = line[0] url_2 = line[2] #if wiki_id not found, assign an id = max_wiki_id and increment max_wiki_id try: wiki_id1 = wiki_from_url_dict[url_1] #first entity has wiki_id try: wiki_id2 = wiki_from_url_dict[url_2] #first and second entities have wiki_ids except (KeyError, IndexError): #first entity has wiki_id, second entity doesn't try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 except (KeyError, IndexError): #first entity doesn't have wiki_id try: wiki_id1 = local_id[url_1] except (KeyError, IndexError): wiki_id1 = max_wiki_id local_id[url_1] = wiki_id1 max_wiki_id += 1 try: #first entity doesn't have wiki_id, second entity has it wiki_id2 = wiki_from_url_dict[url_2] except (KeyError, IndexError): #neither first nor second entity have wiki_ids try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 output_file_write.write('%d %d\n' %(wiki_id1,wiki_id2)) print count count += 1 output_file_write.close() pickle.dump(local_id,open('../../datasets/dbpedia/local_id_to_url_full_mapping_based.p','wb')) <|fim▁end|>
options.output_file = raw_input('Enter output file:')
<|file_name|>page_links_to_edge_list_wiki.py<|end_file_name|><|fim▁begin|>import optparse import pickle #converts urls to wiki_id parser = optparse.OptionParser() parser.add_option('-i','--input', dest = 'input_file', help = 'input_file') parser.add_option('-o','--output', dest = 'output_file', help = 'output_file') (options, args) = parser.parse_args() if options.input_file is None: options.input_file = raw_input('Enter input file:') if options.output_file is None: options.output_file = raw_input('Enter output file:') input_file = options.input_file output_file = options.output_file #define the dictionary url:wiki_id wiki_from_url_dict = {} with open('../../datasets/dbpedia/page_ids_en_2016.ttl','r') as f: for line in f: line = line.split(' ') if line[0] == '#': <|fim_middle|> url = line[0] wiki_id_list = line[2].split('\"') wiki_id = wiki_id_list[1] print(url, wiki_id) wiki_from_url_dict[url] = int(wiki_id) output_file_write = open(output_file,'w') #iterate through the page links and turn urls into wiki_ids max_wiki_id = max(wiki_from_url_dict.values()) + 1 local_id = {} count = 0 with open(input_file) as page_links: for line in page_links: line = line.split(' ') if line[0] == '#': continue url_1 = line[0] url_2 = line[2] #if wiki_id not found, assign an id = max_wiki_id and increment max_wiki_id try: wiki_id1 = wiki_from_url_dict[url_1] #first entity has wiki_id try: wiki_id2 = wiki_from_url_dict[url_2] #first and second entities have wiki_ids except (KeyError, IndexError): #first entity has wiki_id, second entity doesn't try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 except (KeyError, IndexError): #first entity doesn't have wiki_id try: wiki_id1 = local_id[url_1] except (KeyError, IndexError): wiki_id1 = max_wiki_id local_id[url_1] = wiki_id1 max_wiki_id += 1 try: #first entity doesn't have wiki_id, second entity has it wiki_id2 = wiki_from_url_dict[url_2] except (KeyError, IndexError): #neither first nor second entity have wiki_ids try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 output_file_write.write('%d %d\n' %(wiki_id1,wiki_id2)) print count count += 1 output_file_write.close() pickle.dump(local_id,open('../../datasets/dbpedia/local_id_to_url_full_mapping_based.p','wb')) <|fim▁end|>
continue
<|file_name|>page_links_to_edge_list_wiki.py<|end_file_name|><|fim▁begin|>import optparse import pickle #converts urls to wiki_id parser = optparse.OptionParser() parser.add_option('-i','--input', dest = 'input_file', help = 'input_file') parser.add_option('-o','--output', dest = 'output_file', help = 'output_file') (options, args) = parser.parse_args() if options.input_file is None: options.input_file = raw_input('Enter input file:') if options.output_file is None: options.output_file = raw_input('Enter output file:') input_file = options.input_file output_file = options.output_file #define the dictionary url:wiki_id wiki_from_url_dict = {} with open('../../datasets/dbpedia/page_ids_en_2016.ttl','r') as f: for line in f: line = line.split(' ') if line[0] == '#': continue url = line[0] wiki_id_list = line[2].split('\"') wiki_id = wiki_id_list[1] print(url, wiki_id) wiki_from_url_dict[url] = int(wiki_id) output_file_write = open(output_file,'w') #iterate through the page links and turn urls into wiki_ids max_wiki_id = max(wiki_from_url_dict.values()) + 1 local_id = {} count = 0 with open(input_file) as page_links: for line in page_links: line = line.split(' ') if line[0] == '#': <|fim_middle|> url_1 = line[0] url_2 = line[2] #if wiki_id not found, assign an id = max_wiki_id and increment max_wiki_id try: wiki_id1 = wiki_from_url_dict[url_1] #first entity has wiki_id try: wiki_id2 = wiki_from_url_dict[url_2] #first and second entities have wiki_ids except (KeyError, IndexError): #first entity has wiki_id, second entity doesn't try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 except (KeyError, IndexError): #first entity doesn't have wiki_id try: wiki_id1 = local_id[url_1] except (KeyError, IndexError): wiki_id1 = max_wiki_id local_id[url_1] = wiki_id1 max_wiki_id += 1 try: #first entity doesn't have wiki_id, second entity has it wiki_id2 = wiki_from_url_dict[url_2] except (KeyError, IndexError): #neither first nor second entity have wiki_ids try: #check if a local id has already been assigned wiki_id2 = local_id[url_2] except (KeyError, IndexError): wiki_id2 = max_wiki_id local_id[url_2] = wiki_id2 max_wiki_id +=1 output_file_write.write('%d %d\n' %(wiki_id1,wiki_id2)) print count count += 1 output_file_write.close() pickle.dump(local_id,open('../../datasets/dbpedia/local_id_to_url_full_mapping_based.p','wb')) <|fim▁end|>
continue
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs()<|fim▁hole|> kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs<|fim▁end|>
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): <|fim_middle|> <|fim▁end|>
"""A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): <|fim_middle|> def get_context_data(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs <|fim▁end|>
self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs)
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): <|fim_middle|> <|fim▁end|>
kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: <|fim_middle|> return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs <|fim▁end|>
try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e))
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def <|fim_middle|>(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs <|fim▁end|>
dispatch
<|file_name|>mixins.py<|end_file_name|><|fim▁begin|>from __future__ import unicode_literals from __future__ import absolute_import from django.views.generic.base import TemplateResponseMixin from wiki.core.plugins import registry from wiki.conf import settings class ArticleMixin(TemplateResponseMixin): """A mixin that receives an article object as a parameter (usually from a wiki decorator) and puts this information as an instance attribute and in the template context.""" def dispatch(self, request, article, *args, **kwargs): self.urlpath = kwargs.pop('urlpath', None) self.article = article self.children_slice = [] if settings.SHOW_MAX_CHILDREN > 0: try: for child in self.article.get_children( max_num=settings.SHOW_MAX_CHILDREN + 1, articles__article__current_revision__deleted=False, user_can_read=request.user): self.children_slice.append(child) except AttributeError as e: raise Exception( "Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.\n\n" + str(e)) return super(ArticleMixin, self).dispatch(request, *args, **kwargs) def <|fim_middle|>(self, **kwargs): kwargs['urlpath'] = self.urlpath kwargs['article'] = self.article kwargs['article_tabs'] = registry.get_article_tabs() kwargs['children_slice'] = self.children_slice[:20] kwargs['children_slice_more'] = len(self.children_slice) > 20 kwargs['plugins'] = registry.get_plugins() return kwargs <|fim▁end|>
get_context_data
<|file_name|>test_generation.py<|end_file_name|><|fim▁begin|>def test_default(cookies):<|fim▁hole|> Checks if default configuration is working """ result = cookies.bake() assert result.exit_code == 0 assert result.project.isdir() assert result.exception is None<|fim▁end|>
"""
<|file_name|>test_generation.py<|end_file_name|><|fim▁begin|>def test_default(cookies): <|fim_middle|> <|fim▁end|>
""" Checks if default configuration is working """ result = cookies.bake() assert result.exit_code == 0 assert result.project.isdir() assert result.exception is None
<|file_name|>test_generation.py<|end_file_name|><|fim▁begin|>def <|fim_middle|>(cookies): """ Checks if default configuration is working """ result = cookies.bake() assert result.exit_code == 0 assert result.project.isdir() assert result.exception is None <|fim▁end|>
test_default
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if'<|fim▁hole|> except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children<|fim▁end|>
for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model)
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): <|fim_middle|> <|fim▁end|>
""" Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): <|fim_middle|> def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
""" Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m)
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): <|fim_middle|> def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
""" Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0])
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): <|fim_middle|> def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
""" Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): <|fim_middle|> def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
""" Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn)
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): <|fim_middle|> def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
""" Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1)
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): <|fim_middle|> <|fim▁end|>
""" Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used <|fim_middle|> except IndexError: pass return imm_children <|fim▁end|>
imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0]
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def <|fim_middle|>(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
__init__
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def <|fim_middle|>(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
schedule
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def <|fim_middle|>(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
unschedule
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def <|fim_middle|>(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
massReschedule
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def <|fim_middle|>(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def getImminent(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
readFirst
<|file_name|>schedulerNA.py<|end_file_name|><|fim▁begin|># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/) # # 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. """ The No Age scheduler is based on the Heapset scheduler, though it does not take age into account. .. warning:: This scheduler does not take the age into account, making it **unusable** in simulations where the *timeAdvance* function can return (exactly) 0. If unsure, do **not** use this scheduler, but the more general Heapset scheduler. The heap will contain only the timestamps of events that should happen. One of the dictionaries will contain the actual models that transition at the specified time. The second dictionary than contains a reverse relation: it maps the models to their time_next. This reverse relation is necessary to know the *old* time_next value of the model. Because as soon as the model has its time_next changed, its previously scheduled time will be unknown. This 'previous time' is **not** equal to the *timeLast*, as it might be possible that the models wait time was interrupted. For a schedule, the model is added to the dictionary at the specified time_next. In case it is the first element at this location in the dictionary, we also add the timestamp to the heap. This way, the heap only contains *unique* timestamps and thus the actual complexity is reduced to the number of *different* timestamps. Furthermore, the reverse relation is also updated. Unscheduling is done similarly by simply removing the element from the dictionary. Rescheduling is a slight optimisation of unscheduling, followed by scheduling. This scheduler does still schedule models that are inactive (their time_next is infinity), though this does not influence the complexity. The complexity is not affected due to infinity being a single element in the heap that is always present. Since a heap has O(log(n)) complexity, this one additional element does not have a serious impact. The main advantage over the Activity Heap is that it never gets dirty and thus doesn't require periodical cleanup. The only part that gets dirty is the actual heap, which only contains small tuples. Duplicates of these will also be reduced to a single element, thus memory consumption should not be a problem in most cases. This scheduler is ideal in situations where most transitions happen at exactly the same time, as we can then profit from the internal structure and simply return the mapped elements. It results in sufficient efficiency in most other cases, mainly due to the code base being a lot smaller then the Activity Heap. """ from heapq import heappush, heappop from pypdevs.logger import * class SchedulerNA(object): """ Scheduler class itself """ def __init__(self, models, epsilon, total_models): """ Constructor :param models: all models in the simulation """ self.heap = [] self.reverse = [None] * total_models self.mapped = {} self.infinite = float('inf') # Init the basic 'inactive' entry here, to prevent scheduling in the heap itself self.mapped[self.infinite] = set() self.epsilon = epsilon for m in models: self.schedule(m) def schedule(self, model): """ Schedule a model :param model: the model to schedule """ try: self.mapped[model.time_next[0]].add(model) except KeyError: self.mapped[model.time_next[0]] = set([model]) heappush(self.heap, model.time_next[0]) try: self.reverse[model.model_id] = model.time_next[0] except IndexError: self.reverse.append(model.time_next[0]) def unschedule(self, model): """ Unschedule a model :param model: model to unschedule """ try: self.mapped[self.reverse[model.model_id]].remove(model) except KeyError: pass self.reverse[model.model_id] = None def massReschedule(self, reschedule_set): """ Reschedule all models provided. Equivalent to calling unschedule(model); schedule(model) on every element in the iterable. :param reschedule_set: iterable containing all models to reschedule """ #NOTE the usage of exceptions is a lot better for the PyPy JIT and nets a noticable speedup # as the JIT generates guard statements for an 'if' for model in reschedule_set: model_id = model.model_id try: self.mapped[self.reverse[model_id]].remove(model) except KeyError: # Element simply not present, so don't need to unschedule it pass self.reverse[model_id] = tn = model.time_next[0] try: self.mapped[tn].add(model) except KeyError: # Create a tuple with a single entry and use it to initialize the mapped entry self.mapped[tn] = set((model, )) heappush(self.heap, tn) def readFirst(self): """ Returns the time of the first model that has to transition :returns: timestamp of the first model """ first = self.heap[0] while len(self.mapped[first]) == 0: del self.mapped[first] heappop(self.heap) first = self.heap[0] # The age was stripped of return (first, 1) def <|fim_middle|>(self, time): """ Returns a list of all models that transition at the provided time, with the specified epsilon deviation allowed. :param time: timestamp to check for models .. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set. """ t, age = time imm_children = set() try: first = self.heap[0] if (abs(first - t) < self.epsilon): #NOTE this would change the original set, though this doesn't matter as it is no longer used imm_children = self.mapped.pop(first) heappop(self.heap) first = self.heap[0] while (abs(first - t) < self.epsilon): imm_children |= self.mapped.pop(first) heappop(self.heap) first = self.heap[0] except IndexError: pass return imm_children <|fim▁end|>
getImminent
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning<|fim▁hole|> # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop()<|fim▁end|>
self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init()
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions <|fim_middle|> <|fim▁end|>
def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop()
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): <|fim_middle|> def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): <|fim_middle|> def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): <|fim_middle|> def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): <|fim_middle|> def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): <|fim_middle|> def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): <|fim_middle|> def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): <|fim_middle|> def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): <|fim_middle|> def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): <|fim_middle|> # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
pass
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): <|fim_middle|> # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): <|fim_middle|> # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
glClearColor(*self.clearColor)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): <|fim_middle|> # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): <|fim_middle|> # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity()
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): <|fim_middle|> # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
glutSwapBuffers() time.sleep(1/60.0)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): <|fim_middle|> # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): <|fim_middle|> # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL()
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): <|fim_middle|> # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): <|fim_middle|> # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): <|fim_middle|> # Run the GL def run(self): glutMainLoop() <|fim▁end|>
if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): <|fim_middle|> <|fim▁end|>
glutMainLoop()
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): <|fim_middle|> (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
(self._mouseX, self._mouseY) = (x, y)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): <|fim_middle|> (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
(self._mouseX, self._mouseY) = (x, y)
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): <|fim_middle|> # Run the GL def run(self): glutMainLoop() <|fim▁end|>
glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def <|fim_middle|>(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
init
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def <|fim_middle|>(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
close
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def <|fim_middle|>(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
mouse
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def <|fim_middle|>(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
mouseMotion
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def <|fim_middle|>(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
passiveMouseMotion
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def <|fim_middle|>(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
keyboard
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def <|fim_middle|>(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
specialKeys
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def <|fim_middle|>(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
timerFired
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def <|fim_middle|>(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
draw
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def <|fim_middle|>(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
__init__
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def <|fim_middle|>(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
initGL
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def <|fim_middle|>(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
initGLUT
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def <|fim_middle|>(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
preGL
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def <|fim_middle|>(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
postGL
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def <|fim_middle|>(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
timerFiredWrapper
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def <|fim_middle|>(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
drawWrapper
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def <|fim_middle|>(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
mouseMotionWrapper
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def <|fim_middle|>(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
passiveMouseMotionWrapper
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def <|fim_middle|>(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def run(self): glutMainLoop() <|fim▁end|>
reshape
<|file_name|>display.py<|end_file_name|><|fim▁begin|>from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import camera import time class Display(object): # Inheritrance convinience functions def init(self): pass def close(self): pass def mouse(self, mouseButton, buttonState, x, y): pass def mouseMotion(self, x, y, dx, dy): pass def passiveMouseMotion(self, x, y, dx, dy): pass def keyboard(self, key, x, y): pass def specialKeys(self, key, x, y): pass def timerFired(self, value): pass def draw(self): pass # Initialization function def __init__(self, width = 1280, height = 720, frameName = "OpenGL"): self.frameSize = (self.width, self.height) = (width, height) self.frameName = frameName self.timerDelay = 20 self.clearColor = (135.0/255, 206.0/255, 250.0/255, 1) self.defaultColor = (1, 1, 1) # Camera positioning self.pos = (0, 0, 0) self.ypr = (0, 0, 0) self.init() # Set up graphics self.initGL() self.initGLUT() self.camera = camera.Camera(self.width, self.height) # For mouse motion self._mouseX = None self._mouseY = None # One-time GL commands def initGL(self): glClearColor(*self.clearColor) # Initialize the window manager (GLUT) def initGLUT(self): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(*self.frameSize) glutCreateWindow(self.frameName) # Register all the convenience functions glutDisplayFunc(self.drawWrapper) glutIdleFunc(self.drawWrapper) glutTimerFunc(self.timerDelay, self.timerFired, 0) glutMouseFunc(self.mouse) glutMotionFunc(self.mouseMotionWrapper) glutPassiveMotionFunc(self.passiveMouseMotionWrapper) glutKeyboardFunc(self.keyboard) glutSpecialFunc(self.specialKeys) glutReshapeFunc(self.reshape) # Try to register a close function (fall back to a different one) try: glutCloseFunc(self.close) except: glutWMCloseFunc(self.close) # GL commands executed before drawing def preGL(self): glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) # Set up colors and clear buffers glClearColor(*self.clearColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(*self.defaultColor) glLoadIdentity() # Commands after GL is done def postGL(self): glutSwapBuffers() time.sleep(1/60.0) # Wrapper to re-register timer event def timerFiredWrapper(self, value): self.timerFired(value) glutTimerFunc(self.timerDelay, self.timerFired, value + 1) # Wrapper to handle as much GL as possible def drawWrapper(self): self.preGL() # Let the camera draw the view self.camera.draw(self.draw, self.pos, self.ypr) self.postGL() # Wrapper to pass change in position as well as position # Only called when mouse motion and button pressed def mouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.mouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Wrapper to pass change in position as well as position # Called when mouse motion and not button pressed def passiveMouseMotionWrapper(self, x, y): if(self._mouseX == None or self._mouseY == None): (self._mouseX, self._mouseY) = (x, y) (dx, dy) = (x - self._mouseX, y - self._mouseY) self.passiveMouseMotion(x, y, dx, dy) (self._mouseX, self._mouseY) = (x, y) # Update when resizing the window def reshape(self, width, height): if(self.width != width or self.height != height): glutReshapeWindow(width, height) self.camera.width = width self.camera.height = height # Run the GL def <|fim_middle|>(self): glutMainLoop() <|fim▁end|>
run
<|file_name|>constants.py<|end_file_name|><|fim▁begin|>KEY_UP = "up" KEY_DOWN = "down" KEY_RIGHT = "right" KEY_LEFT = "left" KEY_INSERT = "insert" KEY_HOME = "home" KEY_END = "end" KEY_PAGEUP = "pageup" KEY_PAGEDOWN = "pagedown" KEY_BACKSPACE = "backspace" KEY_DELETE = "delete" KEY_TAB = "tab" KEY_ENTER = "enter" KEY_PAUSE = "pause" KEY_ESCAPE = "escape" KEY_SPACE = "space" KEY_KEYPAD0 = "keypad0" KEY_KEYPAD1 = "keypad1" KEY_KEYPAD2 = "keypad2" KEY_KEYPAD3 = "keypad3" KEY_KEYPAD4 = "keypad4" KEY_KEYPAD5 = "keypad5" KEY_KEYPAD6 = "keypad6" KEY_KEYPAD7 = "keypad7" KEY_KEYPAD8 = "keypad8" KEY_KEYPAD9 = "keypad9" KEY_KEYPAD_PERIOD = "keypad_period" KEY_KEYPAD_DIVIDE = "keypad_divide" KEY_KEYPAD_MULTIPLY = "keypad_multiply" KEY_KEYPAD_MINUS = "keypad_minus" KEY_KEYPAD_PLUS = "keypad_plus" KEY_KEYPAD_ENTER = "keypad_enter" KEY_CLEAR = "clear" KEY_F1 = "f1" KEY_F2 = "f2" KEY_F3 = "f3" KEY_F4 = "f4" KEY_F5 = "f5" KEY_F6 = "f6" KEY_F7 = "f7" KEY_F8 = "f8" KEY_F9 = "f9" KEY_F10 = "f10" KEY_F11 = "f11" KEY_F12 = "f12" KEY_F13 = "f13" KEY_F14 = "f14" KEY_F15 = "f15" KEY_F16 = "f16" KEY_F17 = "f17" KEY_F18 = "f18" KEY_F19 = "f19" KEY_F20 = "f20" KEY_SYSREQ = "sysreq" KEY_BREAK = "break" KEY_CONTEXT_MENU = "context_menu" KEY_BROWSER_BACK = "browser_back" KEY_BROWSER_FORWARD = "browser_forward" KEY_BROWSER_REFRESH = "browser_refresh" KEY_BROWSER_STOP = "browser_stop" KEY_BROWSER_SEARCH = "browser_search"<|fim▁hole|><|fim▁end|>
KEY_BROWSER_FAVORITES = "browser_favorites" KEY_BROWSER_HOME = "browser_home"
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self):<|fim▁hole|> return plugins.get(self.plugin_name) def __repr__(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options<|fim▁end|>
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): <|fim_middle|> <|fim▁end|>
__tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): return plugins.get(self.plugin_name) def __repr__(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): <|fim_middle|> def __repr__(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options <|fim▁end|>
return plugins.get(self.plugin_name)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): return plugins.get(self.plugin_name) def __repr__(self): <|fim_middle|> def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options <|fim▁end|>
return "Authorization(id={id})".format(id=self.id)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): return plugins.get(self.plugin_name) def __repr__(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): <|fim_middle|> <|fim▁end|>
self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def <|fim_middle|>(self): return plugins.get(self.plugin_name) def __repr__(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options <|fim▁end|>
plugin
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): return plugins.get(self.plugin_name) def <|fim_middle|>(self): return "Authorization(id={id})".format(id=self.id) def __init__(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options <|fim▁end|>
__repr__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>""" .. module: lemur.authorizations.models :platform: unix :copyright: (c) 2018 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. .. moduleauthor:: Netflix Secops <[email protected]> """ from sqlalchemy import Column, Integer, String from sqlalchemy_utils import JSONType from lemur.database import db from lemur.plugins.base import plugins class Authorization(db.Model): __tablename__ = "pending_dns_authorizations" id = Column(Integer, primary_key=True, autoincrement=True) account_number = Column(String(128)) domains = Column(JSONType) dns_provider_type = Column(String(128)) options = Column(JSONType) @property def plugin(self): return plugins.get(self.plugin_name) def __repr__(self): return "Authorization(id={id})".format(id=self.id) def <|fim_middle|>(self, account_number, domains, dns_provider_type, options=None): self.account_number = account_number self.domains = domains self.dns_provider_type = dns_provider_type self.options = options <|fim▁end|>
__init__
<|file_name|>region_BM.py<|end_file_name|><|fim▁begin|>"""Auto-generated file, do not edit by hand. BM metadata""" from ..phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata PHONE_METADATA_BM = PhoneMetadata(id='BM', country_code=1, international_prefix='011',<|fim▁hole|> fixed_line=PhoneNumberDesc(national_number_pattern='441(?:[46]\\d\\d|5(?:4\\d|60|89))\\d{4}', example_number='4414123456', possible_length=(10,), possible_length_local_only=(7,)), mobile=PhoneNumberDesc(national_number_pattern='441(?:[2378]\\d|5[0-39])\\d{5}', example_number='4413701234', possible_length=(10,), possible_length_local_only=(7,)), toll_free=PhoneNumberDesc(national_number_pattern='8(?:00|33|44|55|66|77|88)[2-9]\\d{6}', example_number='8002123456', possible_length=(10,)), premium_rate=PhoneNumberDesc(national_number_pattern='900[2-9]\\d{6}', example_number='9002123456', possible_length=(10,)), personal_number=PhoneNumberDesc(national_number_pattern='52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|5(?:00|2[12]|33|44|66|77|88)[2-9]\\d{6}', example_number='5002345678', possible_length=(10,)), national_prefix='1', national_prefix_for_parsing='1|([2-8]\\d{6})$', national_prefix_transform_rule='441\\1', leading_digits='441', mobile_number_portable_region=True)<|fim▁end|>
general_desc=PhoneNumberDesc(national_number_pattern='(?:441|[58]\\d\\d|900)\\d{7}', possible_length=(10,), possible_length_local_only=(7,)),
<|file_name|>cover.py<|end_file_name|><|fim▁begin|>"""Support for MySensors covers.""" from homeassistant.components import mysensors from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverDevice from homeassistant.const import STATE_OFF, STATE_ON async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for covers.""" mysensors.setup_mysensors_platform( hass, DOMAIN, discovery_info, MySensorsCover, async_add_entities=async_add_entities) class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): """Representation of the value of a MySensors Cover child node.""" @property def assumed_state(self): """Return True if unable to access real state of entity.""" return self.gateway.optimistic @property def is_closed(self): """Return True if cover is closed.""" set_req = self.gateway.const.SetReq if set_req.V_DIMMER in self._values: return self._values.get(set_req.V_DIMMER) == 0 return self._values.get(set_req.V_LIGHT) == STATE_OFF @property def current_cover_position(self): """Return current position of cover. None is unknown, 0 is closed, 100 is fully open. """ set_req = self.gateway.const.SetReq return self._values.get(set_req.V_DIMMER) async def async_open_cover(self, **kwargs): """Move the cover up.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_UP, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 100 else: self._values[set_req.V_LIGHT] = STATE_ON self.async_schedule_update_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DOWN, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 0 else: self._values[set_req.V_LIGHT] = STATE_OFF self.async_schedule_update_ha_state() async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" position = kwargs.get(ATTR_POSITION) set_req = self.gateway.const.SetReq self.gateway.set_child_value(<|fim▁hole|> # Optimistically assume that cover has changed state. self._values[set_req.V_DIMMER] = position self.async_schedule_update_ha_state() async def async_stop_cover(self, **kwargs): """Stop the device.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_STOP, 1)<|fim▁end|>
self.node_id, self.child_id, set_req.V_DIMMER, position) if self.gateway.optimistic:
<|file_name|>cover.py<|end_file_name|><|fim▁begin|>"""Support for MySensors covers.""" from homeassistant.components import mysensors from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverDevice from homeassistant.const import STATE_OFF, STATE_ON async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): <|fim_middle|> class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): """Representation of the value of a MySensors Cover child node.""" @property def assumed_state(self): """Return True if unable to access real state of entity.""" return self.gateway.optimistic @property def is_closed(self): """Return True if cover is closed.""" set_req = self.gateway.const.SetReq if set_req.V_DIMMER in self._values: return self._values.get(set_req.V_DIMMER) == 0 return self._values.get(set_req.V_LIGHT) == STATE_OFF @property def current_cover_position(self): """Return current position of cover. None is unknown, 0 is closed, 100 is fully open. """ set_req = self.gateway.const.SetReq return self._values.get(set_req.V_DIMMER) async def async_open_cover(self, **kwargs): """Move the cover up.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_UP, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 100 else: self._values[set_req.V_LIGHT] = STATE_ON self.async_schedule_update_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DOWN, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 0 else: self._values[set_req.V_LIGHT] = STATE_OFF self.async_schedule_update_ha_state() async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" position = kwargs.get(ATTR_POSITION) set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DIMMER, position) if self.gateway.optimistic: # Optimistically assume that cover has changed state. self._values[set_req.V_DIMMER] = position self.async_schedule_update_ha_state() async def async_stop_cover(self, **kwargs): """Stop the device.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_STOP, 1) <|fim▁end|>
"""Set up the mysensors platform for covers.""" mysensors.setup_mysensors_platform( hass, DOMAIN, discovery_info, MySensorsCover, async_add_entities=async_add_entities)
<|file_name|>cover.py<|end_file_name|><|fim▁begin|>"""Support for MySensors covers.""" from homeassistant.components import mysensors from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverDevice from homeassistant.const import STATE_OFF, STATE_ON async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for covers.""" mysensors.setup_mysensors_platform( hass, DOMAIN, discovery_info, MySensorsCover, async_add_entities=async_add_entities) class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): <|fim_middle|> <|fim▁end|>
"""Representation of the value of a MySensors Cover child node.""" @property def assumed_state(self): """Return True if unable to access real state of entity.""" return self.gateway.optimistic @property def is_closed(self): """Return True if cover is closed.""" set_req = self.gateway.const.SetReq if set_req.V_DIMMER in self._values: return self._values.get(set_req.V_DIMMER) == 0 return self._values.get(set_req.V_LIGHT) == STATE_OFF @property def current_cover_position(self): """Return current position of cover. None is unknown, 0 is closed, 100 is fully open. """ set_req = self.gateway.const.SetReq return self._values.get(set_req.V_DIMMER) async def async_open_cover(self, **kwargs): """Move the cover up.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_UP, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 100 else: self._values[set_req.V_LIGHT] = STATE_ON self.async_schedule_update_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DOWN, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 0 else: self._values[set_req.V_LIGHT] = STATE_OFF self.async_schedule_update_ha_state() async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" position = kwargs.get(ATTR_POSITION) set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DIMMER, position) if self.gateway.optimistic: # Optimistically assume that cover has changed state. self._values[set_req.V_DIMMER] = position self.async_schedule_update_ha_state() async def async_stop_cover(self, **kwargs): """Stop the device.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_STOP, 1)
<|file_name|>cover.py<|end_file_name|><|fim▁begin|>"""Support for MySensors covers.""" from homeassistant.components import mysensors from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverDevice from homeassistant.const import STATE_OFF, STATE_ON async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for covers.""" mysensors.setup_mysensors_platform( hass, DOMAIN, discovery_info, MySensorsCover, async_add_entities=async_add_entities) class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): """Representation of the value of a MySensors Cover child node.""" @property def assumed_state(self): <|fim_middle|> @property def is_closed(self): """Return True if cover is closed.""" set_req = self.gateway.const.SetReq if set_req.V_DIMMER in self._values: return self._values.get(set_req.V_DIMMER) == 0 return self._values.get(set_req.V_LIGHT) == STATE_OFF @property def current_cover_position(self): """Return current position of cover. None is unknown, 0 is closed, 100 is fully open. """ set_req = self.gateway.const.SetReq return self._values.get(set_req.V_DIMMER) async def async_open_cover(self, **kwargs): """Move the cover up.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_UP, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 100 else: self._values[set_req.V_LIGHT] = STATE_ON self.async_schedule_update_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DOWN, 1) if self.gateway.optimistic: # Optimistically assume that cover has changed state. if set_req.V_DIMMER in self._values: self._values[set_req.V_DIMMER] = 0 else: self._values[set_req.V_LIGHT] = STATE_OFF self.async_schedule_update_ha_state() async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" position = kwargs.get(ATTR_POSITION) set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_DIMMER, position) if self.gateway.optimistic: # Optimistically assume that cover has changed state. self._values[set_req.V_DIMMER] = position self.async_schedule_update_ha_state() async def async_stop_cover(self, **kwargs): """Stop the device.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( self.node_id, self.child_id, set_req.V_STOP, 1) <|fim▁end|>
"""Return True if unable to access real state of entity.""" return self.gateway.optimistic