signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
@property<EOL><INDENT>def properties(self):<DEDENT>
|
return self._properties<EOL>
|
Miscellaneous properties.
Stores key/value pair properties.
Part of the extended profile.
Example:
>>> c = Component()
>>> c.properties = {'key':'value'}
Invalid assignment should throw exception:
>>> c.properties = 1
Traceback (most recent call last):
...
InvalidTypeError: ('component.ext.Properties', <type 'int'>, <type 'dict'>)
|
f5236:c0:m30
|
def get_configuration_set_by_id(self, id):
|
for cs in self.configuration_sets:<EOL><INDENT>if cs.id == id:<EOL><INDENT>return cs<EOL><DEDENT><DEDENT>return None<EOL>
|
Finds a configuration set in the component by its ID.
@param id The ID of the configuration set to search for.
@return The ConfigurationSet object for the set, or None if it was not
found.
|
f5236:c0:m32
|
def parse_xml_node(self, node):
|
self._reset()<EOL>self.id = node.getAttributeNS(RTS_NS, '<STR_LIT:id>')<EOL>self.path_uri = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>if node.hasAttributeNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self.active_configuration_set = node.getAttributeNS(RTS_NS,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self.active_configuration_set = '<STR_LIT>'<EOL><DEDENT>self.instance_name = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>self.compositeType = comp_type.from_string(node.getAttributeNS(RTS_NS,<EOL>'<STR_LIT>'))<EOL>required = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>if required == '<STR_LIT:true>' or required == '<STR_LIT:1>':<EOL><INDENT>self.is_required = True<EOL><DEDENT>else:<EOL><INDENT>self.is_required = False<EOL><DEDENT>self.comment = node.getAttributeNS(RTS_EXT_NS, '<STR_LIT>')<EOL>if node.hasAttributeNS(RTS_EXT_NS, '<STR_LIT>'):<EOL><INDENT>visible = node.getAttributeNS(RTS_EXT_NS, '<STR_LIT>')<EOL>if visible.lower() == '<STR_LIT:true>' or visible == '<STR_LIT:1>':<EOL><INDENT>self.visible = True<EOL><DEDENT>else:<EOL><INDENT>self.visible = False<EOL><DEDENT><DEDENT>for c in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._data_ports.append(DataPort().parse_xml_node(c))<EOL><DEDENT>for c in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._service_ports.append(ServicePort().parse_xml_node(c))<EOL><DEDENT>for c in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._config_sets.append(ConfigurationSet().parse_xml_node(c))<EOL><DEDENT>for c in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._exec_contexts.append(ExecutionContext().parse_xml_node(c))<EOL><DEDENT>for c in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._participants.append(Participant().parse_xml_node(c))<EOL><DEDENT>c = node.getElementsByTagNameNS(RTS_EXT_NS, '<STR_LIT>')<EOL>if c.length > <NUM_LIT:0>:<EOL><INDENT>if c.length > <NUM_LIT:1>:<EOL><INDENT>raise InvalidRtsProfileNodeError('<STR_LIT>')<EOL><DEDENT>self._location = Location().parse_xml_node(c[<NUM_LIT:0>])<EOL><DEDENT>for c in get_direct_child_elements_xml(node, prefix=RTS_EXT_NS,<EOL>local_name='<STR_LIT>'):<EOL><INDENT>name, value = parse_properties_xml(c)<EOL>self._properties[name] = value<EOL><DEDENT>return self<EOL>
|
Parse an xml.dom Node object representing a component into this
object.
>>> c = Component()
|
f5236:c0:m33
|
def save_xml(self, doc, element):
|
element.setAttributeNS(XSI_NS, XSI_NS_S + '<STR_LIT:type>', '<STR_LIT>')<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT:id>', self.id)<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>', self.path_uri)<EOL>if self.active_configuration_set:<EOL><INDENT>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>self.active_configuration_set)<EOL><DEDENT>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>self.instance_name)<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>comp_type.to_string(self.composite_type))<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>str(self.is_required).lower())<EOL>if self.comment:<EOL><INDENT>element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + '<STR_LIT>',<EOL>self.comment)<EOL><DEDENT>element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + '<STR_LIT>',<EOL>str(self.visible).lower())<EOL>for port in self.data_ports:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS, RTS_NS_S + '<STR_LIT>')<EOL>port.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>for port in self.service_ports:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS,<EOL>RTS_NS_S + '<STR_LIT>')<EOL>port.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>for cs in self.configuration_sets:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS,<EOL>RTS_NS_S + '<STR_LIT>')<EOL>cs.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>for ec in self.execution_contexts:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS,<EOL>RTS_NS_S + '<STR_LIT>')<EOL>ec.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>for p in self.participants:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS,<EOL>RTS_NS_S + '<STR_LIT>')<EOL>p.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>new_element = doc.createElementNS(RTS_EXT_NS,<EOL>RTS_EXT_NS_S + '<STR_LIT>')<EOL>self._location.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL>for p in self.properties:<EOL><INDENT>new_prop_element = doc.createElementNS(RTS_EXT_NS,<EOL>RTS_EXT_NS_S + '<STR_LIT>')<EOL>properties_to_xml(new_prop_element, p, self.properties[p])<EOL>element.appendChild(new_prop_element)<EOL><DEDENT>
|
Save this component into an xml.dom.Element object.
|
f5236:c0:m34
|
def parse_yaml(self, y):
|
self._reset()<EOL>self.id = y['<STR_LIT:id>']<EOL>self.path_uri = y['<STR_LIT>']<EOL>if '<STR_LIT>' in y:<EOL><INDENT>self.active_configuration_set = y['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self.active_configuration_set = '<STR_LIT>'<EOL><DEDENT>self.instance_name = y['<STR_LIT>']<EOL>self.compositeType = comp_type.from_string(y['<STR_LIT>'])<EOL>required = y['<STR_LIT>']<EOL>if required == True or required == '<STR_LIT:true>' or required == '<STR_LIT:1>':<EOL><INDENT>self.is_required = True<EOL><DEDENT>else:<EOL><INDENT>self.is_required = False<EOL><DEDENT>if RTS_EXT_NS_YAML + '<STR_LIT>' in y:<EOL><INDENT>self.comment = y[RTS_EXT_NS_YAML + '<STR_LIT>']<EOL><DEDENT>self.visible = False<EOL>if RTS_EXT_NS_YAML + '<STR_LIT>' in y:<EOL><INDENT>visible = y.get(RTS_EXT_NS_YAML + '<STR_LIT>')<EOL>if visible == True or visible == '<STR_LIT:true>' or visible == '<STR_LIT:True>':<EOL><INDENT>self.visible = True<EOL><DEDENT><DEDENT>if '<STR_LIT>' in y:<EOL><INDENT>for p in y.get('<STR_LIT>'):<EOL><INDENT>self._data_ports.append(DataPort().parse_yaml(p))<EOL><DEDENT><DEDENT>if '<STR_LIT>' in y:<EOL><INDENT>for p in y.get('<STR_LIT>'):<EOL><INDENT>self._service_ports.append(ServicePort().parse_yaml(p))<EOL><DEDENT><DEDENT>if '<STR_LIT>' in y:<EOL><INDENT>for p in y.get('<STR_LIT>'):<EOL><INDENT>self._config_sets.append(ConfigurationSet().parse_yaml(p))<EOL><DEDENT><DEDENT>if '<STR_LIT>' in y:<EOL><INDENT>for p in y.get('<STR_LIT>'):<EOL><INDENT>self._exec_contexts.append(ExecutionContext().parse_yaml(p))<EOL><DEDENT><DEDENT>if '<STR_LIT>' in y:<EOL><INDENT>for p in y.get('<STR_LIT>'):<EOL><INDENT>self._participants.append(Participant().parse_yaml(p))<EOL><DEDENT><DEDENT>if RTS_EXT_NS_YAML + '<STR_LIT:location>' in y:<EOL><INDENT>l = y[RTS_EXT_NS_YAML + '<STR_LIT:location>']<EOL>self._location = Location().parse_yaml(l)<EOL><DEDENT>if RTS_EXT_NS_YAML + '<STR_LIT>' in y:<EOL><INDENT>for p in y.get(RTS_EXT_NS_YAML + '<STR_LIT>'):<EOL><INDENT>if '<STR_LIT:value>' in p:<EOL><INDENT>value = p['<STR_LIT:value>']<EOL><DEDENT>else:<EOL><INDENT>value = None<EOL><DEDENT>self._properties[p['<STR_LIT:name>']] = value<EOL><DEDENT><DEDENT>return self<EOL>
|
Parse a YAML specification of a component into this object.
|
f5236:c0:m35
|
def __init__(self, component_id='<STR_LIT>', instance_name='<STR_LIT>'):
|
validate_attribute(component_id, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._component_id = component_id<EOL>validate_attribute(instance_name, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._instance_name = instance_name<EOL>self._properties = {}<EOL>
|
Constructor.
@param component_id The ID of the target component.
@type component_id str
@param instance_name The instance name of the target component.
@type instance_name str
|
f5237:c0:m0
|
@property<EOL><INDENT>def component_id(self):<DEDENT>
|
return self._component_id<EOL>
|
The ID of the target component.
RT components can be uniquely identified using the component ID and the
instance name.
|
f5237:c0:m2
|
@property<EOL><INDENT>def instance_name(self):<DEDENT>
|
return self._instance_name<EOL>
|
The instance name of the target component.
RT components can be uniquely identified using the component ID and the
instance name.
|
f5237:c0:m4
|
@property<EOL><INDENT>def properties(self):<DEDENT>
|
return self._properties<EOL>
|
Miscellaneous properties.
Stores key/value pair properties.
Part of the extended profile.
|
f5237:c0:m6
|
def parse_xml_node(self, node):
|
self.component_id = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>self.instance_name = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>for c in node.getElementsByTagNameNS(RTS_EXT_NS, '<STR_LIT>'):<EOL><INDENT>name, value = parse_properties_xml(c)<EOL>self._properties[name] = value<EOL><DEDENT>return self<EOL>
|
Parse an xml.dom Node object representing a target component into
this object.
|
f5237:c0:m8
|
def parse_yaml(self, y):
|
self.component_id = y['<STR_LIT>']<EOL>self.instance_name = y['<STR_LIT>']<EOL>if RTS_EXT_NS_YAML + '<STR_LIT>' in y:<EOL><INDENT>for p in y.get(RTS_EXT_NS_YAML + '<STR_LIT>'):<EOL><INDENT>if '<STR_LIT:value>' in p:<EOL><INDENT>value = p['<STR_LIT:value>']<EOL><DEDENT>else:<EOL><INDENT>value = None<EOL><DEDENT>self._properties[p['<STR_LIT:name>']] = value<EOL><DEDENT><DEDENT>return self<EOL>
|
Parse a YAML specification of a target component into this
object.
|
f5237:c0:m9
|
def save_xml(self, doc, element):
|
element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>self.component_id)<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>',<EOL>self.instance_name)<EOL>for p in self.properties:<EOL><INDENT>new_prop_element = doc.createElementNS(RTS_EXT_NS,<EOL>RTS_EXT_NS_S + '<STR_LIT>')<EOL>properties_to_xml(new_prop_element, p, self.properties[p])<EOL>element.appendChild(new_prop_element)<EOL><DEDENT>
|
Save this target component into an xml.dom.Element object.
|
f5237:c0:m10
|
def to_dict(self):
|
d = {'<STR_LIT>': self.component_id,<EOL>'<STR_LIT>': self.instance_name}<EOL>props = []<EOL>for name in self.properties:<EOL><INDENT>p = {'<STR_LIT:name>': name}<EOL>if self.properties[name]:<EOL><INDENT>p['<STR_LIT:value>'] = str(self.properties[name])<EOL><DEDENT>props.append(p)<EOL><DEDENT>if props:<EOL><INDENT>d[RTS_EXT_NS_YAML + '<STR_LIT>'] = props<EOL><DEDENT>return d<EOL>
|
Save this target component into a dictionary.
|
f5237:c0:m11
|
def __init__(self, component_id='<STR_LIT>', instance_name='<STR_LIT>', port_name='<STR_LIT>'):
|
super(TargetPort, self).__init__(component_id, instance_name)<EOL>validate_attribute(port_name, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._port_name = port_name<EOL>
|
Constructor. See also the @ref TargetComponent constructor.
@param port_name The name of the target port.
@type port_name str
|
f5237:c1:m0
|
@property<EOL><INDENT>def port_name(self):<DEDENT>
|
return self._port_name<EOL>
|
The ID of the target port.
|
f5237:c1:m2
|
def parse_xml_node(self, node):
|
super(TargetPort, self).parse_xml_node(node)<EOL>self.port_name = node.getAttributeNS(RTS_NS, '<STR_LIT>')<EOL>return self<EOL>
|
Parse an xml.dom Node object representing a target port into this
object.
|
f5237:c1:m4
|
def parse_yaml(self, y):
|
super(TargetPort, self).parse_yaml(y)<EOL>self.port_name = y['<STR_LIT>']<EOL>return self<EOL>
|
Parse a YAML specification of a target port into this object.
|
f5237:c1:m5
|
def save_xml(self, doc, element):
|
super(TargetPort, self).save_xml(doc, element)<EOL>element.setAttributeNS(XSI_NS, XSI_NS_S + '<STR_LIT:type>', '<STR_LIT>')<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT>', self.port_name)<EOL>
|
Save this target port into an xml.dom.Element object.
|
f5237:c1:m6
|
def to_dict(self):
|
d = super(TargetPort, self).to_dict()<EOL>d['<STR_LIT>'] = self.port_name<EOL>return d<EOL>
|
Save this target port into a dictionary.
|
f5237:c1:m7
|
def __init__(self, component_id='<STR_LIT>', instance_name='<STR_LIT>', id='<STR_LIT>'):
|
super(TargetExecutionContext, self).__init__(component_id,<EOL>instance_name)<EOL>validate_attribute(id, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._id = id<EOL>self._properties = {}<EOL>
|
Constructor. See also the @ref TargetComponent constructor.
@param id The ID of the target execution context.
@type id str
|
f5237:c2:m0
|
@property<EOL><INDENT>def id(self):<DEDENT>
|
return self._id<EOL>
|
The ID of the target execution context.
|
f5237:c2:m2
|
@property<EOL><INDENT>def properties(self):<DEDENT>
|
return self._properties<EOL>
|
Miscellaneous properties.
Stores key/value pair properties.
Part of the extended profile.
|
f5237:c2:m4
|
def parse_xml_node(self, node):
|
super(TargetExecutionContext, self).parse_xml_node(node)<EOL>if node.hasAttributeNS(RTS_NS, '<STR_LIT:id>'):<EOL><INDENT>self.id = node.getAttributeNS(RTS_NS, '<STR_LIT:id>')<EOL><DEDENT>else:<EOL><INDENT>self.id = '<STR_LIT>'<EOL><DEDENT>return self<EOL>
|
Parse an xml.dom Node object representing a target execution context
into this object.
|
f5237:c2:m6
|
def parse_yaml(self, y):
|
super(TargetExecutionContext, self).parse_yaml(y)<EOL>if '<STR_LIT:id>' in y:<EOL><INDENT>self.id = y['<STR_LIT:id>']<EOL><DEDENT>else:<EOL><INDENT>self.id = '<STR_LIT>'<EOL><DEDENT>return self<EOL>
|
Parse a YAML specification of a target execution context into this
object.
|
f5237:c2:m7
|
def save_xml(self, doc, element):
|
super(TargetExecutionContext, self).save_xml(doc, element)<EOL>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT:id>', self.id)<EOL>
|
Save this target execution context into an xml.dom.Element
object.
|
f5237:c2:m8
|
def to_dict(self):
|
d = super(TargetExecutionContext, self).to_dict()<EOL>d['<STR_LIT:id>'] = self.id<EOL>return d<EOL>
|
Save this target execution context into a dictionary.
|
f5237:c2:m9
|
def __init__(self, target_component=None):
|
validate_attribute(target_component, '<STR_LIT>',<EOL>expected_type=TargetComponent, required=False)<EOL>self._target_component = target_component<EOL>
|
Constructor.
@param target_component The target component of this participant.
@type target_component TargetComponent
|
f5238:c0:m0
|
@property<EOL><INDENT>def target_component(self):<DEDENT>
|
return self._target_component<EOL>
|
The target component of this participant.
|
f5238:c0:m2
|
def parse_xml_node(self, node):
|
if node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>').length != <NUM_LIT:1>:<EOL><INDENT>raise InvalidParticipantNodeError<EOL><DEDENT>self.target_component = TargetComponent().parse_xml_node(node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>')[<NUM_LIT:0>])<EOL>return self<EOL>
|
Parse an xml.dom Node object representing a participant into this
object.
|
f5238:c0:m4
|
def parse_yaml_node(self, y):
|
if '<STR_LIT>' not in y:<EOL><INDENT>raise InvalidParticipantNodeError<EOL><DEDENT>self.target_component = TargetComponent().parse_yaml_node(y['<STR_LIT>'])<EOL>return self<EOL>
|
Parse a YAML specification of a participant into this object.
|
f5238:c0:m5
|
def save_xml(self, doc, element):
|
new_element = doc.createElementNS(RTS_NS, RTS_NS_S + '<STR_LIT>')<EOL>self.target_component.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL>
|
Save this participant into an xml.dom.Element object.
|
f5238:c0:m6
|
def to_dict(self):
|
return {'<STR_LIT>': self.target_component.to_dict()}<EOL>
|
Save this participant into a dictionary.
|
f5238:c0:m7
|
def from_string(dir_string):
|
dir_string = dir_string.upper()<EOL>if dir_string == UP:<EOL><INDENT>return UP<EOL><DEDENT>elif dir_string == DOWN:<EOL><INDENT>return DOWN<EOL><DEDENT>elif dir_string == LEFT:<EOL><INDENT>return LEFT<EOL><DEDENT>elif dir_string == RIGHT:<EOL><INDENT>return RIGHT<EOL><DEDENT>else:<EOL><INDENT>raise InvalidDirectionError(dir_string)<EOL><DEDENT>
|
Returns the correct constant for a given string.
@raises InvalidDirectionError
|
f5239:m0
|
def to_string(direction):
|
if direction == UP:<EOL><INDENT>return UP<EOL><DEDENT>elif direction == DOWN:<EOL><INDENT>return DOWN<EOL><DEDENT>elif direction == LEFT:<EOL><INDENT>return LEFT<EOL><DEDENT>elif direction == RIGHT:<EOL><INDENT>return RIGHT<EOL><DEDENT>else:<EOL><INDENT>raise InvalidDirectionError(type_string)<EOL><DEDENT>
|
Returns the correct string for a given direction.
@raises InvalidDirectionError
|
f5239:m1
|
def indent_string(string, num_spaces=<NUM_LIT:2>):
|
indent = '<STR_LIT:U+0020>'.ljust(num_spaces)<EOL>return indent + re.sub('<STR_LIT:\n>', '<STR_LIT:\n>' + indent, string)<EOL>
|
Add indentation to a string.
Replaces all new lines in the string with a new line followed by the
specified number of spaces, and adds the specified number of spaces to the
start of the string.
|
f5240:m3
|
def validate_attribute(attr, name, expected_type=None, required=False):
|
if expected_type:<EOL><INDENT>if type(expected_type) == list:<EOL><INDENT>if not _check_type(attr, expected_type):<EOL><INDENT>raise InvalidTypeError(name, type(attr), expected_type)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not _check_type(attr, [expected_type]):<EOL><INDENT>raise InvalidTypeError(name, type(attr), expected_type)<EOL><DEDENT><DEDENT><DEDENT>if required and not attr:<EOL><INDENT>raise RequiredAttributeError(name)<EOL><DEDENT>
|
Validates that an attribute meets expectations.
This function will check if the given attribute value matches a necessary
type and/or is not None, an empty string, an empty list, etc. It will raise
suitable exceptions on validation failure.
@param attr The value to validate.
@param name The attribute name to use in exceptions.
@param expected_type The type the value must be. If None, no check is
performed. If a list, attr must match one type in the list.
@param required If the value must not be empty, e.g. not an empty string.
@raises InvalidTypeError
@raises RequiredAttributeError
|
f5240:m6
|
def __init__(self, id='<STR_LIT>'):
|
validate_attribute(id, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._id = id<EOL>self._config_data = []<EOL>
|
Constructor.
@param id The configuration set ID.
@type id str
|
f5242:c0:m0
|
@property<EOL><INDENT>def configuration_data(self):<DEDENT>
|
return self._config_data<EOL>
|
The configuration parameters contained in this set.
May be an empty list if this set has no parameters.
|
f5242:c0:m2
|
@property<EOL><INDENT>def id(self):<DEDENT>
|
return self._id<EOL>
|
The configuration set ID.
Used to distinguish this configuration set from others in the RT
Component.
|
f5242:c0:m4
|
def parse_xml_node(self, node):
|
self.id = node.getAttributeNS(RTS_NS, '<STR_LIT:id>')<EOL>self._config_data = []<EOL>for d in node.getElementsByTagNameNS(RTS_NS, '<STR_LIT>'):<EOL><INDENT>self._config_data.append(ConfigurationData().parse_xml_node(d))<EOL><DEDENT>return self<EOL>
|
Parse an xml.dom Node object representing a configuration set into
this object.
|
f5242:c0:m6
|
def parse_yaml(self, y):
|
self.id = y['<STR_LIT:id>']<EOL>self._config_data = []<EOL>if '<STR_LIT>' in y:<EOL><INDENT>for d in y.get('<STR_LIT>'):<EOL><INDENT>self._config_data.append(ConfigurationData().parse_yaml(d))<EOL><DEDENT><DEDENT>return self<EOL>
|
Parse a YAML specification of a configuration set into this
object.
|
f5242:c0:m7
|
def save_xml(self, doc, element):
|
element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT:id>', self.id)<EOL>for c in self._config_data:<EOL><INDENT>new_element = doc.createElementNS(RTS_NS,<EOL>RTS_NS_S + '<STR_LIT>')<EOL>c.save_xml(doc, new_element)<EOL>element.appendChild(new_element)<EOL><DEDENT>
|
Save this configuration set into an xml.dom.Element object.
|
f5242:c0:m8
|
def to_dict(self):
|
d = {'<STR_LIT:id>': self.id}<EOL>data = []<EOL>for c in self._config_data:<EOL><INDENT>data.append(c.to_dict())<EOL><DEDENT>if data:<EOL><INDENT>d['<STR_LIT>'] = data<EOL><DEDENT>return d<EOL>
|
Save this configuration set into a dictionary.
|
f5242:c0:m9
|
def __init__(self, name='<STR_LIT>', data='<STR_LIT>'):
|
validate_attribute(name, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._name = name<EOL>validate_attribute(data, '<STR_LIT>',<EOL>expected_type=string_types(), required=False)<EOL>self._data = data<EOL>
|
Constructor.
@param name The name of the parameter.
@type name str
@param data The parameter's value, if any.
@type data str
|
f5242:c1:m0
|
@property<EOL><INDENT>def data(self):<DEDENT>
|
return self._data<EOL>
|
The value of this configuration parameter.
May be an empty string if the parameter has no value.
|
f5242:c1:m2
|
@property<EOL><INDENT>def name(self):<DEDENT>
|
return self._name<EOL>
|
The name of this configuration parameter.
Used as the parameter's key in the configuration set object.
|
f5242:c1:m4
|
def parse_xml_node(self, node):
|
self.name = node.getAttributeNS(RTS_NS, '<STR_LIT:name>')<EOL>if node.hasAttributeNS(RTS_NS, '<STR_LIT:data>'):<EOL><INDENT>self.data = node.getAttributeNS(RTS_NS, '<STR_LIT:data>')<EOL><DEDENT>else:<EOL><INDENT>self.data = '<STR_LIT>'<EOL><DEDENT>return self<EOL>
|
Parse an xml.dom Node object representing a configuration data into
this object.
|
f5242:c1:m6
|
def parse_yaml(self, y):
|
self.name = y['<STR_LIT:name>']<EOL>if '<STR_LIT:data>' in y:<EOL><INDENT>self.data = y['<STR_LIT:data>']<EOL><DEDENT>else:<EOL><INDENT>self.data = '<STR_LIT>'<EOL><DEDENT>return self<EOL>
|
Parse a YAML specification of a configuration data into this
object.
|
f5242:c1:m7
|
def save_xml(self, doc, element):
|
element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT:name>', self.name)<EOL>if self.data:<EOL><INDENT>element.setAttributeNS(RTS_NS, RTS_NS_S + '<STR_LIT:data>', self.data)<EOL><DEDENT>
|
Save this configuration data into an xml.dom.Element object.
|
f5242:c1:m8
|
def to_dict(self):
|
d = {'<STR_LIT:name>': self.name}<EOL>if self.data:<EOL><INDENT>d['<STR_LIT:data>'] = self.data<EOL><DEDENT>return d<EOL>
|
Save this configuration data into a dictionary.
|
f5242:c1:m9
|
def tag(*tags):
|
def dfn(fn):<EOL><INDENT>_tags = getattr(fn, '<STR_LIT>', set())<EOL>_tags.update(tags)<EOL>fn.tags = _tags<EOL>return fn<EOL><DEDENT>return dfn<EOL>
|
Constructs a decorator that tags a function with specified
strings (@tags). The tags on the decorated function are
available via fn.tags
|
f5245:m1
|
def mime(mime):
|
def dfn(fn):<EOL><INDENT>fn.mime = mime<EOL>return fn<EOL><DEDENT>return dfn<EOL>
|
Constructs a decorator that sets the preferred mime type
to be written in the http response when returning the
function result.
|
f5245:m3
|
def raw(mime='<STR_LIT>'):
|
def dfn(fn):<EOL><INDENT>tags = getattr(fn, '<STR_LIT>', set())<EOL>tags.add('<STR_LIT>')<EOL>fn.tags = tags<EOL>fn.mime = getattr(fn, '<STR_LIT>', mime)<EOL>return fn<EOL><DEDENT>return dfn<EOL>
|
Constructs a decorator that marks the fn
as raw response format
|
f5245:m4
|
def open(self, pysession_id):
|
self.id = id(self)<EOL>self.funcserver = self.application.funcserver<EOL>self.pysession_id = pysession_id<EOL>self.state = self.funcserver.websocks[self.id] = {'<STR_LIT:id>': self.id, '<STR_LIT>': self}<EOL>
|
Called when client opens connection. Initialization
is done here.
|
f5245:c3:m0
|
def on_message(self, msg):
|
msg = json.loads(msg)<EOL>psession = self.funcserver.pysessions.get(self.pysession_id, None)<EOL>if psession is None:<EOL><INDENT>interpreter = PyInterpreter(self.funcserver.define_python_namespace())<EOL>psession = dict(interpreter=interpreter, socks=set([self.id]))<EOL>self.funcserver.pysessions[self.pysession_id] = psession<EOL><DEDENT>else:<EOL><INDENT>interpreter = psession['<STR_LIT>']<EOL>psession['<STR_LIT>'].add(self.id)<EOL><DEDENT>code = msg['<STR_LIT:code>']<EOL>msg_id = msg['<STR_LIT:id>']<EOL>stdout = sys.stdout<EOL>try:<EOL><INDENT>sys.stdout = io.StringIO()<EOL>interpreter.runsource(code)<EOL>output = sys.stdout.getvalue() or interpreter.output<EOL>if isinstance(output, list): output = '<STR_LIT>'.join(output)<EOL>interpreter.output = []<EOL><DEDENT>finally:<EOL><INDENT>sys.stdout = stdout<EOL><DEDENT>msg = {'<STR_LIT:type>': MSG_TYPE_CONSOLE, '<STR_LIT:id>': msg_id, '<STR_LIT:data>': output}<EOL>self.send_message(msg)<EOL>
|
Called when client sends a message.
Supports a python debugging console. This forms
the "eval" part of a standard read-eval-print loop.
Currently the only implementation of the python
console is in the WebUI but the implementation
of a terminal based console is planned.
|
f5245:c3:m1
|
def on_close(self):
|
if self.id in self.funcserver.websocks:<EOL><INDENT>self.funcserver.websocks[self.id] = None<EOL>ioloop = tornado.ioloop.IOLoop.instance()<EOL>ioloop.add_callback(lambda: self.funcserver.websocks.pop(self.id, None))<EOL><DEDENT>psession = self.funcserver.pysessions.get(self.pysession_id, None)<EOL>if psession:<EOL><INDENT>psession['<STR_LIT>'].remove(self.id)<EOL>if not psession['<STR_LIT>']:<EOL><INDENT>del self.funcserver.pysessions[self.pysession_id]<EOL><DEDENT><DEDENT>
|
Called when client closes this connection. Cleanup
is done here.
|
f5245:c3:m2
|
def _clean_kwargs(self, kwargs, fn):
|
<EOL>if not self.server.IGNORE_UNEXPECTED_KWARGS:<EOL><INDENT>return kwargs<EOL><DEDENT>expected_kwargs = set(inspect.getargspec(fn).args)<EOL>got_kwargs = set(kwargs.keys())<EOL>unexpected_kwargs = got_kwargs - expected_kwargs<EOL>for k in unexpected_kwargs:<EOL><INDENT>del kwargs[k]<EOL><DEDENT>return kwargs<EOL>
|
Remove unexpected keyword arguments from the
set of received keyword arguments.
|
f5245:c6:m4
|
def dump_stacks(self):
|
dump = []<EOL>threads = dict([(th.ident, th.name)<EOL>for th in threading.enumerate()])<EOL>for thread, frame in list(sys._current_frames().items()):<EOL><INDENT>if thread not in threads: continue<EOL>dump.append('<STR_LIT>' % (thread, threads[thread]))<EOL>dump.append('<STR_LIT>'.join(traceback.format_stack(frame)))<EOL>dump.append('<STR_LIT:\n>')<EOL><DEDENT>return '<STR_LIT>'.join(dump)<EOL>
|
Dumps the stack of all threads. This function
is meant for debugging. Useful when a deadlock happens.
borrowed from: http://blog.ziade.org/2012/05/25/zmq-and-gevent-debugging-nightmares/
|
f5245:c7:m0
|
def define_log_pre_format_hooks(self):
|
hooks = super(Server, self).define_log_pre_format_hooks()<EOL>if self.args.func == self.run and self.args.debug:<EOL><INDENT>hooks.append(self._send_log_to_ws)<EOL><DEDENT>return hooks<EOL>
|
adds a hook to send to websocket if the run command was selected
|
f5245:c7:m4
|
def prepare_api(self):
|
return None<EOL>
|
Prepare the API object that is exposed as
functionality by the Server
|
f5245:c7:m15
|
def define_headers(self):
|
return {}<EOL>
|
the dictionary returned by define_headers will be used as
header key and value in every response to a client.
|
f5245:c7:m16
|
def run(self):
|
self.log_id = <NUM_LIT:0><EOL>self.websocks = {}<EOL>self.pysessions = {}<EOL>if self.DISABLE_REQUESTS_DEBUG_LOGS:<EOL><INDENT>disable_requests_debug_logs()<EOL><DEDENT>self.threadpool = ThreadPool(self.THREADPOOL_WORKERS)<EOL>self.api = None<EOL>base_handlers = self.prepare_base_handlers()<EOL>handlers = self.prepare_handlers()<EOL>self.template_loader = TemplateLoader([resolve_path(self.TEMPLATE_PATH)])<EOL>_ = self.prepare_template_loader(self.template_loader)<EOL>if _ is not None: self.template_loader = _<EOL>shclass = CustomStaticFileHandler<EOL>shclass.PATHS.append(resolve_path(self.STATIC_PATH))<EOL>_ = self.prepare_static_paths(shclass.PATHS)<EOL>if _ is not None: shclass.PATHS = _<EOL>self.static_handler_class = shclass<EOL>self.nav_tabs = [('<STR_LIT>', '<STR_LIT:/>')]<EOL>if self.args.debug:<EOL><INDENT>self.nav_tabs += [('<STR_LIT>', '<STR_LIT>'), ('<STR_LIT>', '<STR_LIT>')]<EOL><DEDENT>self.nav_tabs = self.prepare_nav_tabs(self.nav_tabs)<EOL>settings = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': self.static_handler_class,<EOL>'<STR_LIT>': self.template_loader,<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT>': self.args.debug,<EOL>}<EOL>all_handlers = handlers + base_handlers<EOL>self.app = self.APP_CLASS(**settings)<EOL>self.app.add_handlers(self.VIRTUAL_HOST, all_handlers)<EOL>sys.funcserver = self.app.funcserver = self<EOL>self.api = self.prepare_api()<EOL>if self.api is not None and not hasattr(self.api, '<STR_LIT>'):<EOL><INDENT>self.api.log = self.log<EOL><DEDENT>if self.args.port != <NUM_LIT:0>:<EOL><INDENT>self.app.listen(self.args.port)<EOL><DEDENT>tornado.ioloop.IOLoop.instance().start()<EOL>
|
prepares the api and starts the tornado funcserver
|
f5245:c7:m17
|
def add(self, a, b):
|
return a + b<EOL>
|
Computes the sum of @a and @b
|
f5249:c0:m1
|
def sub(self, a, b):
|
return a - b<EOL>
|
Computes the difference of @a and @b
|
f5249:c0:m2
|
def mul(self, a, b):
|
return a * b<EOL>
|
Computes the product of @a and @b
|
f5249:c0:m3
|
def div(self, a, b):
|
if self.ignore_divbyzero: return <NUM_LIT:0><EOL>return a / b<EOL>
|
Computes the division of @a by @b
|
f5249:c0:m4
|
def null():
|
pass<EOL>
|
空函数
|
f5251:m0
|
def repeat(f, dt=<NUM_LIT:1>/<NUM_LIT>):
|
stop(f)<EOL>pyglet.clock.schedule_interval(f, dt)<EOL>
|
重复执行函数f,时间间隔dt
|
f5251:m1
|
def run_after(f, dt=<NUM_LIT:1>/<NUM_LIT>):
|
pyglet.clock.schedule_once(f, dt)<EOL>
|
在一定时间之后执行
|
f5251:m2
|
def run():
|
pyglet.app.run()<EOL>
|
在程序的最后运行,进入循环阻塞
|
f5251:m3
|
def on_move(self, f):
|
self._move = f<EOL>
|
注册鼠标移动事件
|
f5252:c0:m1
|
def on_press(self, f):
|
self._press = f<EOL>
|
注册鼠标点击事件
|
f5252:c0:m2
|
def on_release(self, f):
|
self._release = f<EOL>
|
注册鼠标点击事件
|
f5252:c0:m3
|
def on_right_press(self, f):
|
self._right_press = f<EOL>
|
注册鼠标右键点击事件
|
f5252:c0:m4
|
def on_right_release(self, f):
|
self._right_release = f<EOL>
|
注册鼠标右键点击事件
|
f5252:c0:m5
|
def move(self):
|
self._move()<EOL>
|
触发鼠标移动事件
|
f5252:c0:m6
|
def press(self):
|
self.LEFT = True<EOL>self._press()<EOL>
|
触发鼠标左键点击事件
|
f5252:c0:m7
|
def release(self):
|
self.LEFT = False<EOL>self._release()<EOL>
|
触发鼠标左键松开事件
|
f5252:c0:m8
|
def right_press(self):
|
self.RIGHT = True<EOL>self._right_press()<EOL>
|
触发鼠标右击事件
|
f5252:c0:m9
|
def right_release(self):
|
self.RIGHT = False<EOL>self._right_release()<EOL>
|
触发鼠标右键松开事件
|
f5252:c0:m10
|
def __init__(self):
|
if platform.system() =="<STR_LIT>":<EOL><INDENT>template = pyglet.gl.Config(alpha_size=<NUM_LIT:8>, sample_buffers=<NUM_LIT:1>, samples=<NUM_LIT:4>)<EOL>configs = screen.get_matching_configs(template)<EOL>if not configs:<EOL><INDENT>super().__init__()<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>super().__init__(config=configs[<NUM_LIT:0>])<EOL><DEDENT>except Exception: <EOL><INDENT>super().__init__()<EOL><DEDENT><DEDENT><DEDENT>else: <EOL><INDENT>super().__init__()<EOL><DEDENT>self.set_caption("<STR_LIT>")<EOL>self.set_location(location_x, location_y)<EOL>self.axis_batch = None<EOL>
|
初始化,创建一个窗口
|
f5253:c0:m0
|
@property<EOL><INDENT>def w(self):<DEDENT>
|
return self.width<EOL>
|
width
|
f5253:c0:m1
|
@property<EOL><INDENT>def h(self):<DEDENT>
|
return self.height<EOL>
|
height
|
f5253:c0:m2
|
def update_caption(self, mouse):
|
caption = "<STR_LIT>".format(self._title, mouse.x, mouse.y)<EOL>super().set_caption(caption)<EOL>
|
添加坐标显示
|
f5253:c0:m7
|
def __init__(self, path="<STR_LIT>"):
|
self.path = path<EOL>self.ctx = ssl.create_default_context()<EOL>self.ctx.check_hostname = False<EOL>self.ctx.verify_mode = ssl.CERT_NONE<EOL>
|
设置保存路径
|
f5255:c0:m0
|
def md5_8_name(self, url):
|
m = hashlib.md5()<EOL>m.update(url.encode('<STR_LIT:utf-8>'))<EOL>return m.hexdigest()[:<NUM_LIT:8>] + os.path.splitext(url)[<NUM_LIT:1>]<EOL>
|
把下载的文件重命名为地址的md5前8位
|
f5255:c0:m2
|
def pause(url):
|
cache_musics[url].pause()<EOL>
|
暂停播放音效
|
f5257:m2
|
def __init__(self, x=<NUM_LIT:100>, y=<NUM_LIT:100>, w=<NUM_LIT:100>, h=<NUM_LIT:50>, color="<STR_LIT>"):
|
super().__init__(color, gl=pyglet.gl.GL_QUADS)<EOL>self.x, self.y, self.w, self.h = x, y, w, h<EOL>
|
长方形
左下角顶点的位置: x, y
宽度: w
高度: h
颜色: color 默认为 "orange"
|
f5258:c0:m0
|
def update_points(self):
|
x, y, w, h = self.x, self.y, self.w, self.h<EOL>self.points = (x, y, x + w, y, x + w, y + h, x, y + h)<EOL>
|
统一变为多个点组成的多边形,用于处理碰撞
|
f5258:c0:m1
|
def __init__(self, *args):
|
if isinstance(args[-<NUM_LIT:1>], str):<EOL><INDENT>color = args[-<NUM_LIT:1>]<EOL>points = list(args[:len(args)-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>color = "<STR_LIT>"<EOL>points = list(args)<EOL><DEDENT>self._x = sum(points[::<NUM_LIT:2>]) / (len(points) // <NUM_LIT:2>)<EOL>self._y = sum(points[<NUM_LIT:1>::<NUM_LIT:2>]) / (len(points) // <NUM_LIT:2>)<EOL>self._move_x = <NUM_LIT:0><EOL>self._move_y = <NUM_LIT:0><EOL>super().__init__(color, gl=pyglet.gl.GL_POLYGON)<EOL>self.points = self._points = points<EOL>
|
多边形
颜色: color 默认为 "orange"
|
f5259:c0:m0
|
def __init__(self, x=<NUM_LIT:100>, y=<NUM_LIT:100>, r_x=<NUM_LIT:50>, r_y=<NUM_LIT:30>, color="<STR_LIT>"):
|
super().__init__(color, gl=gl.GL_POLYGON)<EOL>self.x, self.y, self.r_x, self.r_y = x, y, r_x, r_y<EOL>
|
圆心: x、y, 默认为100, 100
半径: r_x, r_y 默认为50, 30
颜色: color, 默认为 "orange"
|
f5260:c0:m0
|
def update_points(self):
|
n = max(<NUM_LIT:8>, min(<NUM_LIT>, int(<NUM_LIT:2>*sqrt(self.r_x+self.r_y))))<EOL>d = pi * <NUM_LIT:2> / n<EOL>x, y, r_x, r_y = self.x, self.y, self.r_x, self.r_y<EOL>ps = []<EOL>for i in range(n):<EOL><INDENT>ps += [(x + r_x * sin(d * i)), (y + r_y * cos(d * i))]<EOL><DEDENT>self.points = tuple(ps)<EOL>
|
椭圆的近似图形:72边形
|
f5260:c0:m1
|
def __init__(self, x=<NUM_LIT:100>, y=<NUM_LIT:100>, r=<NUM_LIT:30>, color="<STR_LIT>"):
|
super().__init__(color, gl=pyglet.gl.GL_POLYGON)<EOL>self.x, self.y, self.r = x, y, r<EOL>
|
圆心: x、y, 默认为100, 100
半径: r, 默认为30
颜色: color, 默认为 "orange"
|
f5262:c0:m0
|
def update_points(self):
|
n = max(<NUM_LIT:8>, min(<NUM_LIT>, int(<NUM_LIT:4>*sqrt(self.r))))<EOL>d = pi * <NUM_LIT:2> / n<EOL>x, y, r = self.x, self.y, self.r<EOL>ps = []<EOL>for i in range(n):<EOL><INDENT>ps += [(x + r * sin(d * i)), (y + r * cos(d * i))]<EOL><DEDENT>self.points = tuple(ps)<EOL>
|
圆的近似图形:正多边形
|
f5262:c0:m1
|
def __init__(self, color="<STR_LIT>", gl=pyglet.gl.GL_LINE_LOOP,<EOL>line_width=<NUM_LIT:1>):
|
self.color = color<EOL>self.gl = gl<EOL>self.transform = Transform()<EOL>self.line_width = line_width<EOL>self.points = ()<EOL>self._press = null<EOL>self.point_size = <NUM_LIT:1><EOL>self.opacity = <NUM_LIT:1><EOL>
|
默认参数
颜色 color: "orange"
线条粗细 line_width: 1
|
f5265:c0:m0
|
def draw(self):
|
self.update_all()<EOL>self.vertex_list.draw(self.gl)<EOL>pyglet.gl.glLoadIdentity()<EOL>
|
使用draw方法将图形绘制在窗口里
|
f5265:c0:m1
|
def stroke(self):
|
self.update_all()<EOL>length = len(self.points)<EOL>if self.line_width <= <NUM_LIT:3>:<EOL><INDENT>if length==<NUM_LIT:4>:<EOL><INDENT>self.vertex_list.draw(pyglet.gl.GL_LINES)<EOL><DEDENT>elif length > <NUM_LIT:4>:<EOL><INDENT>self.vertex_list.draw(pyglet.gl.GL_LINE_LOOP)<EOL><DEDENT>return<EOL><DEDENT>color = color_to_tuple(self.color, self.opacity)<EOL>if length == <NUM_LIT:4>:<EOL><INDENT>x, y, x1, y1 = self.points[<NUM_LIT:0>:<NUM_LIT:4>]<EOL>l = max(<NUM_LIT:1>, math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)))<EOL>ly = (x1-x) / l * self.line_width / <NUM_LIT:2><EOL>lx = - (y1-y) / l * self.line_width / <NUM_LIT:2><EOL>points = [x-lx, y-ly, x+lx, y+ly, x1+lx, y1+ly, x1-lx, y1-ly]<EOL>vertex_list = pyglet.graphics.vertex_list(<EOL><NUM_LIT:4>,<EOL>('<STR_LIT>', points),<EOL>('<STR_LIT>', color * <NUM_LIT:4>))<EOL>vertex_list.draw(pyglet.gl.GL_QUADS)<EOL><DEDENT>elif length > <NUM_LIT:4>:<EOL><INDENT>points = []<EOL>for i in range(<NUM_LIT:0>, length, <NUM_LIT:2>):<EOL><INDENT>x, y = self.points[i], self.points[i+<NUM_LIT:1>]<EOL>x1, y1 = self.points[i-<NUM_LIT:2>], self.points[i-<NUM_LIT:1>]<EOL>x2, y2 = self.points[(i+<NUM_LIT:2>) % length], self.points[(i+<NUM_LIT:3>) % length]<EOL>l1 = max(<NUM_LIT:1>, math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)))<EOL>l2 = max(<NUM_LIT:1>, math.sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y)))<EOL>nx1, ny1 = (x - x1) / l1, (y - y1) / l1<EOL>nx2, ny2 = (x - x2) / l2, (y - y2) / l2<EOL>nx, ny = nx1 + nx2, ny1 + ny2<EOL>vx, vy = -ny1, nx1<EOL>t = nx1*nx2 + ny1*ny2<EOL>if t > <NUM_LIT>:<EOL><INDENT>lx = vx * self.line_width / <NUM_LIT:2><EOL>ly = vy * self.line_width / <NUM_LIT:2><EOL>points += [x-lx, y-ly, x+lx, y+ly, x+lx, y+ly, x-lx, y-ly]<EOL><DEDENT>elif t < -<NUM_LIT>:<EOL><INDENT>lx = vx * self.line_width / <NUM_LIT:2><EOL>ly = vy * self.line_width / <NUM_LIT:2><EOL>points += [x+lx, y+ly, x-lx, y-ly]<EOL><DEDENT>else:<EOL><INDENT>radio = <NUM_LIT:1>/(vx*nx + vy*ny)<EOL>if radio < <NUM_LIT:0>: <EOL><INDENT>radio = -radio<EOL><DEDENT>lx = (nx1+nx2) * self.line_width / <NUM_LIT:2> * radio<EOL>ly = (ny1+ny2) * self.line_width / <NUM_LIT:2> * radio<EOL>points += [x+lx, y+ly, x-lx, y-ly]<EOL><DEDENT><DEDENT>batch = pyglet.graphics.Batch()<EOL>for i in range(<NUM_LIT:0>, len(points), <NUM_LIT:4>):<EOL><INDENT>batch.add(<NUM_LIT:4>, pyglet.gl.GL_QUADS, None,<EOL>('<STR_LIT>', (points[i-<NUM_LIT:4>], points[i-<NUM_LIT:3>], points[i-<NUM_LIT:2>], points[i-<NUM_LIT:1>],<EOL>points[i+<NUM_LIT:2>], points[i+<NUM_LIT:3>], points[i], points[i+<NUM_LIT:1>])),<EOL>('<STR_LIT>', color * <NUM_LIT:4>))<EOL><DEDENT>batch.draw()<EOL><DEDENT>pyglet.gl.glLoadIdentity()<EOL>
|
使用stroke方法将图形绘制在窗口里,仅对基本的几何图形有效
|
f5265:c0:m2
|
def update_all(self):
|
self.update_points()<EOL>self.update_vertex_list()<EOL>self.update_anchor()<EOL>pyglet.gl.glLoadIdentity() <EOL>pyglet.gl.glLineWidth(self.line_width)<EOL>pyglet.gl.glPointSize(self.point_size)<EOL>self.transform.update_gl()<EOL>all_shapes.discard(self)<EOL>if(self._press != None):<EOL><INDENT>all_shapes.add(self)<EOL><DEDENT>
|
在绘制之前,针对形变进行计算,通过设置openGL的属性来达到绘制出变形的图形
|
f5265:c0:m3
|
def update_points(self):
|
pass<EOL>
|
translate shapes to points,在子类中实现
|
f5265:c0:m4
|
def update_vertex_list(self):
|
color = color_to_tuple(self.color, self.opacity)<EOL>length = len(self.points) // <NUM_LIT:2><EOL>self.vertex_list = pyglet.graphics.vertex_list(<EOL>length,<EOL>('<STR_LIT>', self.points),<EOL>('<STR_LIT>', color * length))<EOL>
|
使用pyglet来绘制基本图形之前,转为pyglet识别的属性
|
f5265:c0:m5
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.