def _get_valve_names(self): setup_file = os.path.join(paths.extraction_line_dir, 'valves.xml') if os.path.isfile(setup_file): parser = SwitchParser(setup_file) valves = [(v.text.strip(), v.find('description').text.strip()) for g in parser.get_groups() + [None] for v in parser.get_valves(group=g)] self.valve = valves[0][0] else: valves = [] return valves
def _get_valve_names(self): setup_file = os.path.join(paths.extraction_line_dir, 'valves.xml') if os.path.isfile(setup_file): parser = SwitchParser(setup_file) valves = [(v.text.strip(), v.find('description').text.strip()) for g in parser.get_groups() + [None] for v in parser.get_valves(group=g) ] self.valve = valves[0][0] else: valves = [] return valves
def _load_descriptions(self): descriptions = [] parser = SwitchParser() if not parser.load(self.valves_path): self.warning_dialog('"{}" not a valid file'.format(self.valves_path)) else: for v in parser.get_all_switches(): d = v.find('description') if d is not None: descriptions.append(d.text) if descriptions: self.description = descriptions[0] self.descriptions = descriptions
def _load_descriptions(self): descriptions = [] parser = SwitchParser() if not parser.load(self.valves_path): self.warning_dialog('"{}" not a valid file'.format( self.valves_path)) else: for v in parser.get_all_switches(): d = v.find('description') if d is not None: descriptions.append(d.text) if descriptions: self.description = descriptions[0] self.descriptions = descriptions
def _load_switchables(self, cp, origin, vpath): ox, oy = origin ndict = dict() vp = SwitchParser(vpath) for s in cp.get_elements('switch'): key = s.text.strip() x, y = self._get_floats(s, 'translation') radius = 0.75 r = s.find('radius') if r: radius = float(r.text.strip()) v = Switch(x + ox, y + oy, name=key, radius=radius) l = s.find('slabel') if l is not None: label = l.text.strip() if l.get('offset'): x, y = map(float, l.get('offset').split(',')) else: x = 0 y = 22 v.set_label(label, x, y) self.add_item(v, layer=1) ndict[key] = v for v in cp.get_elements('valve'): key = v.text.strip() x, y = self._get_floats(v, 'translation') # get the description from valves.xml vv = vp.get_valve(key) desc = '' if vv is not None: desc = vv.find('description') desc = desc.text.strip() if desc is not None else '' v = Valve(x + ox, y + oy, name=key, description=desc, border_width=3) # v.translate = x + ox, y + oy # sync the states if key in self.valves: vv = self.valves[key] v.state = vv.state v.soft_lock = vv.soft_lock self.add_item(v, layer=1) ndict[key] = v for rv in cp.get_elements('rough_valve'): key = rv.text.strip() x, y = self._get_floats(rv, 'translation') v = RoughValve(x + ox, y + oy, name=key) self.add_item(v, layer=1) ndict[key] = v for mv in cp.get_elements('manual_valve'): key = mv.text.strip() x, y = self._get_floats(mv, 'translation') vv = vp.get_manual_valve(key) desc = '' if vv is not None: desc = vv.find('description') desc = desc.text.strip() if desc is not None else '' v = ManualSwitch(x + ox, y + oy, display_name=desc, name=key) self.add_item(v, layer=1) ndict[key] = v self.valves = ndict
def _load_switchables(self, cp, origin, vpath): ox, oy = origin ndict = dict() vp = SwitchParser(vpath) for s in cp.get_elements('switch'): key = s.text.strip() x, y = self._get_translation(cp, s) # x, y = self._get_floats(s, 'translation') radius = 0.75 r = s.find('radius') if r: radius = float(r.text.strip()) v = Switch(x + ox, y + oy, name=key, radius=radius) l = s.find('slabel') if l is not None: label = l.text.strip() if l.get('offset'): x, y = map(float, l.get('offset').split(',')) else: x = 0 y = 22 v.set_label(label, x, y) associations = s.findall('association') if associations: for a in associations: v.associations.append(a.text.strip()) self.add_item(v, layer=1) ndict[key] = v for v in cp.get_elements('valve'): key = v.text.strip() # x, y = self._get_floats(v, 'translation') x, y = self._get_translation(cp, v) # get the description from valves.xml vv = vp.get_valve(key) desc = '' if vv is not None: desc = vv.find('description') desc = desc.text.strip() if desc is not None else '' v = Valve(x + ox, y + oy, name=key, description=desc, border_width=3) # v.translate = x + ox, y + oy # sync the states if key in self.valves: vv = self.valves[key] v.state = vv.state v.soft_lock = vv.soft_lock self.add_item(v, layer=1) ndict[key] = v for rv in cp.get_elements('rough_valve'): key = rv.text.strip() # x, y = self._get_floats(rv, 'translation') x, y = self._get_translation(cp, rv) v = RoughValve(x + ox, y + oy, name=key) self.add_item(v, layer=1) ndict[key] = v for mv in cp.get_elements('manual_valve'): key = mv.text.strip() x, y = self._get_translation(cp, mv) # x, y = self._get_floats(mv, 'translation') vv = vp.get_manual_valve(key) desc = '' if vv is not None: desc = vv.find('description') desc = desc.text.strip() if desc is not None else '' v = ManualSwitch(x + ox, y + oy, display_name=desc, name=key) self.add_item(v, layer=1) ndict[key] = v self.valves = ndict