445 for direction in directions: |
445 for direction in directions: |
446 self.selected_models[direction].ResetData() |
446 self.selected_models[direction].ResetData() |
447 |
447 |
448 |
448 |
449 class OPCUAClientList(list): |
449 class OPCUAClientList(list): |
450 def __init__(self, log = lambda m:None): |
450 def __init__(self, log, change_callback): |
451 super(OPCUAClientList, self).__init__(self) |
451 super(OPCUAClientList, self).__init__(self) |
452 self.log = log |
452 self.log = log |
|
453 self.change_callback = change_callback |
453 |
454 |
454 def append(self, value): |
455 def append(self, value): |
455 v = dict(zip(lstcolnames, value)) |
456 v = dict(zip(lstcolnames, value)) |
456 |
457 |
457 if type(v["IEC"]) != int: |
458 if type(v["IEC"]) != int: |
478 self.log("Variable {} (Id={}) already in list\n".format(v["Name"],v["Id"])) |
479 self.log("Variable {} (Id={}) already in list\n".format(v["Name"],v["Id"])) |
479 return False |
480 return False |
480 |
481 |
481 list.append(self, [v[n] for n in lstcolnames]) |
482 list.append(self, [v[n] for n in lstcolnames]) |
482 |
483 |
|
484 self.change_callback() |
|
485 |
483 return True |
486 return True |
484 |
487 |
|
488 def __delitem__(self, index): |
|
489 list.__delitem__(self, index) |
|
490 self.change_callback() |
|
491 |
485 class OPCUAClientModel(dict): |
492 class OPCUAClientModel(dict): |
486 def __init__(self, log = lambda m:None): |
493 def __init__(self, log, change_callback = lambda : None): |
487 super(OPCUAClientModel, self).__init__() |
494 super(OPCUAClientModel, self).__init__() |
488 for direction in directions: |
495 for direction in directions: |
489 self[direction] = OPCUAClientList(log) |
496 self[direction] = OPCUAClientList(log, change_callback) |
490 |
497 |
491 def LoadCSV(self,path): |
498 def LoadCSV(self,path): |
492 with open(path, 'rb') as csvfile: |
499 with open(path, 'rb') as csvfile: |
493 reader = csv.reader(csvfile, delimiter=',', quotechar='"') |
500 reader = csv.reader(csvfile, delimiter=',', quotechar='"') |
494 buf = {direction:[] for direction, _model in self.iteritems()} |
501 buf = {direction:[] for direction, _model in self.iteritems()} |
495 for direction, model in self.iteritems(): |
502 for direction, model in self.iteritems(): |
496 self[direction][:] = [] |
503 self[direction][:] = [] |
497 for row in reader: |
504 for row in reader: |
498 direction = row[0] |
505 direction = row[0] |
499 self[direction].append(row[1:]) |
506 # avoids calling change callback whe loading CSV |
|
507 list.append(self[direction],row[1:]) |
500 |
508 |
501 def SaveCSV(self,path): |
509 def SaveCSV(self,path): |
502 with open(path, 'wb') as csvfile: |
510 with open(path, 'wb') as csvfile: |
503 for direction, data in self.iteritems(): |
511 for direction, data in self.iteritems(): |
504 writer = csv.writer(csvfile, delimiter=',', |
512 writer = csv.writer(csvfile, delimiter=',', |