diff -r 0dd1a5f2a7a1 -r 6083dcecd2c5 PLCControler.py --- a/PLCControler.py Fri Oct 09 17:34:18 2009 +0200 +++ b/PLCControler.py Mon Oct 12 10:20:09 2009 +0200 @@ -597,14 +597,12 @@ pou.setpouType(pou_type) self.BufferProject() - def ProjectCreatePouFrom(self, name, from_name): - if self.Project is not None: - pou = self.Project.getpou(from_name) + def GetPouXml(self, pou_name): + if self.Project is not None: + pou = self.Project.getpou(pou_name) if pou is not None: - new_pou = self.Copy(pou) - new_pou.setname(name) - self.Project.insertpou(-1, new_pou) - self.BufferProject() + return pou.generateXMLText('pou', 0) + return None def PastePou(self, pou_type, pou_xml): ''' @@ -627,23 +625,20 @@ # function blocks cannot be pasted as functions, # programs cannot be pasted as functions or function blocks if orig_type == 'functionBlock' and pou_type == 'function' or \ - orig_type == 'program' and pou_type in ['function', 'functionBlock']: + orig_type == 'program' and pou_type in ['function', 'functionBlock']: return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type) - - while self.Project.getpou(name): + + idx = 0 + new_name = name + while self.Project.getpou(new_name): # a POU with that name already exists. # make a new name and test if a POU with that name exists. - - # append an incrementing numeric suffix to the POU name. it - # doesn't count up perfectly, but as long as it's unique who cares? - if name[-1] >= '0' and name[-1] <= '9': - last_digit = int(name[-1]) - name = name[0:-1] + str(last_digit+1) - else: - name = name + '1' - + # append an incrementing numeric suffix to the POU name. + idx += 1 + new_name = "%s%d" % (name, idx) + # we've found a name that does not already exist, use it - new_pou.setname(name) + new_pou.setname(new_name) new_pou.setpouType(pou_type) self.Project.insertpou(-1, new_pou)