opc_ua/opcua_client_maker.py
branchwxPython4
changeset 3667 49e6b73de505
parent 3666 bf3b5f58c832
child 3674 d10a7907fb43
equal deleted inserted replaced
3666:bf3b5f58c832 3667:49e6b73de505
   286         self.OnClose()
   286         self.OnClose()
   287 
   287 
   288     def OnConnectButton(self, event):
   288     def OnConnectButton(self, event):
   289         if self.connect_button.GetValue():
   289         if self.connect_button.GetValue():
   290             
   290             
   291             self.tree_panel = wx.Panel(self)
       
   292             self.tree_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
       
   293             self.tree_sizer.AddGrowableCol(0)
       
   294             self.tree_sizer.AddGrowableRow(0)
       
   295 
       
   296             self.tree = gizmos.TreeListCtrl(self.tree_panel, -1, style=0, agwStyle=
       
   297                                             gizmos.TR_DEFAULT_STYLE
       
   298                                             | gizmos.TR_MULTIPLE
       
   299                                             | gizmos.TR_FULL_ROW_HIGHLIGHT
       
   300                                        )
       
   301 
       
   302             prepare_image_list()
       
   303             self.tree.SetImageList(il)
       
   304 
       
   305             for idx,(colname, width) in enumerate(zip(treecolnames, treecolwidths)):
       
   306                 self.tree.AddColumn(colname)
       
   307                 self.tree.SetColumnWidth(idx, width)
       
   308 
       
   309             self.tree.SetMainColumn(0)
       
   310 
       
   311             config = self.config_getter()
   291             config = self.config_getter()
   312             self.client = Client(config["URI"])
   292             self.client = Client(config["URI"])
       
   293             self.log("OPCUA browser: connecting to {}\n".format(config["URI"]))
   313             
   294             
   314             AuthType = config["AuthType"]
   295             AuthType = config["AuthType"]
   315             if AuthType=="UserPasword":
   296             if AuthType=="UserPasword":
   316                 self.client.set_user(config["User"])
   297                 self.client.set_user(config["User"])
   317                 self.client.set_password(config["Password"])
   298                 self.client.set_password(config["Password"])
   318             elif AuthType=="x509":
   299             elif AuthType=="x509":
   319                 self.client.set_security_string(
   300                 self.client.set_security_string(
   320                     "{Policy},{Mode},{Certificate},{PrivateKey}".format(**config))
   301                     "{Policy},{Mode},{Certificate},{PrivateKey}".format(**config))
   321 
   302 
   322             self.client.connect()
   303             try :
       
   304                 self.client.connect()
       
   305             except Exception as e:
       
   306                 self.log("OPCUA browser: "+str(e)+"\n")
       
   307                 self.client = None
       
   308                 self.connect_button.SetValue(False)
       
   309                 return
       
   310 
       
   311             self.tree_panel = wx.Panel(self)
       
   312             self.tree_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
       
   313             self.tree_sizer.AddGrowableCol(0)
       
   314             self.tree_sizer.AddGrowableRow(0)
       
   315 
       
   316             self.tree = gizmos.TreeListCtrl(self.tree_panel, -1, style=0, agwStyle=
       
   317                                             gizmos.TR_DEFAULT_STYLE
       
   318                                             | gizmos.TR_MULTIPLE
       
   319                                             | gizmos.TR_FULL_ROW_HIGHLIGHT
       
   320                                        )
       
   321 
       
   322             prepare_image_list()
       
   323             self.tree.SetImageList(il)
       
   324 
       
   325             for idx,(colname, width) in enumerate(zip(treecolnames, treecolwidths)):
       
   326                 self.tree.AddColumn(colname)
       
   327                 self.tree.SetColumnWidth(idx, width)
       
   328 
       
   329             self.tree.SetMainColumn(0)
       
   330 
   323             self.client.load_type_definitions()  # load definition of server specific structures/extension objects
   331             self.client.load_type_definitions()  # load definition of server specific structures/extension objects
   324             rootnode = self.client.get_root_node()
   332             rootnode = self.client.get_root_node()
   325 
   333 
   326             rootitem = self.AddNodeItem(self.tree.AddRoot, rootnode)
   334             rootitem = self.AddNodeItem(self.tree.AddRoot, rootnode)
   327 
   335