def __init__(self, name, data, context=None):
        self.name = name
        self.data = data
        self.context = context  # I may need to know the larger context (the model) to resolve types
        self.iconFile = data.get("icon", "generic.svg")
        self.customInstantiator = None
        f = open(common.fileResolver(self.iconFile), "r")
        self.iconSvg = svg.Svg(f.read(), (256, 128))
        f.close()

        self.buttonFile = data.get("button", "generic_button.svg")
        f = open(common.fileResolver(self.buttonFile), "r")
        self.buttonSvg = svg.Svg(f.read(), (32, 32))
        f.close()
  def __init__(self,name, data, context=None):
    self.name = name
    self.data = data
    self.context = context  # I may need to know the larger context (the model) to resolve types
    self.iconFile = data.get("icon", "generic.svg")
    self.customInstantiator = None
    f = open(common.fileResolver(self.iconFile),"r")
    self.iconSvg =  svg.Svg(f.read(),(256,128))
    f.close()

    self.buttonFile = data.get("button", "generic_button.svg")
    f = open(common.fileResolver(self.buttonFile),"r")
    self.buttonSvg =  svg.Svg(f.read(),(32,32))
    f.close()
    def __init__(self):
        """Constructor"""
        wx.Dialog.__init__(self, None, title="New project", size=(430, 240))
        LabelSize = (100, 25)
        EntrySize = (300, 25)
        prjname_sizer = wx.BoxSizer(wx.HORIZONTAL)

        prj_lbl = wx.StaticText(self, label="Project name", size=LabelSize)
        prjname_sizer.Add(prj_lbl, 0, wx.ALL | wx.CENTER, 5)
        self.prjName = wx.TextCtrl(self, size=EntrySize)
        prjname_sizer.Add(self.prjName, 10, wx.ALL | wx.EXPAND, 5)

        prjlocation_sizer = wx.BoxSizer(wx.HORIZONTAL)
        prj_location_lbl = wx.StaticText(self,
                                         label="Location",
                                         size=LabelSize)
        prjlocation_sizer.Add(prj_location_lbl, 0, wx.ALL | wx.CENTER, 5)

        self.prjLocation = wx.DirPickerCtrl(
            self,
            message="Choose a project location",
            style=wx.DIRP_DEFAULT_STYLE | wx.DIRP_USE_TEXTCTRL,
            size=EntrySize)
        self.prjLocation.SetPath(common.getMostRecentPrjDir())
        prjlocation_sizer.Add(self.prjLocation, 0, wx.ALL, 5)

        datamodel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        datamodel_lbl = wx.StaticText(self, label="Data model", size=LabelSize)
        datamodel_sizer.Add(datamodel_lbl, 0, wx.ALL | wx.CENTER, 5)

        defaultModel = common.fileResolver("SAFplusAmf.yang")
        self.datamodel = wx.FilePickerCtrl(
            self,
            message="Choose a file",
            path="SAFplusAmf.yang",
            style=wx.FLP_DEFAULT_STYLE | wx.FLP_USE_TEXTCTRL,
            wildcard="Data model (*.yang)|*.yang",
            size=EntrySize)
        datamodel_sizer.Add(self.datamodel, 0, wx.ALL, 5)

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.Add(prjname_sizer, 0, wx.ALL, 5)
        main_sizer.Add(prjlocation_sizer, 0, wx.ALL, 5)
        main_sizer.Add(datamodel_sizer, 0, wx.ALL, 5)

        OK_btn = wx.Button(self, label="OK")
        OK_btn.Bind(wx.EVT_BUTTON, self.onBtnHandler)
        cancel_btn = wx.Button(self, label="Cancel")
        cancel_btn.Bind(wx.EVT_BUTTON, self.onBtnHandler)

        btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
        btn_sizer.Add(OK_btn, 0, wx.ALL | wx.CENTER, 5)
        btn_sizer.Add(cancel_btn, 0, wx.ALL | wx.CENTER, 5)

        main_sizer.Add(btn_sizer, 0, wx.ALL | wx.CENTER, 5)

        self.SetSizer(main_sizer)
        main_sizer.Layout()
        prjname_sizer.Layout()
Esempio n. 4
0
  def loadPyTemplate(self,fname):
    """Load a template file and return it as a string"""
    if self.cache.has_key(fname): return self.cache[fname]

    fname = common.fileResolver(fname);
    f = open(fname,"r")
    s = f.read()
    t = Template(s)
    self.cache[fname] = t
    return t
 def __init__(self, filename):
   global observer
   global handler
   print filename
   self.filename = common.fileResolver(filename)
   realfile = os.path.realpath(self.filename)  # Chase thru symbolic links
   handler.files[realfile] = self
   # Parse the yang file into a pythonic dictionary structure
   self.ytypes, self.yobjects  = yang.go(os.getcwd(),[self.filename])
   # Now let's watch this file for changes
   observer.schedule(handler, os.path.dirname(realfile), recursive=False)
   # Parse the yang module into entity types
   self.entityTypes = {}
   for i in self.yobjects.items(): # Load the top level defined entities (like node, sg)
     if i[1].get("ui-entity",False):
       self.entityTypes[i[0]] = entity.EntityType(i[0],i[1])  # create a new entity type, with the member fields (located in i[1])
    def __init__(self):
        """Constructor"""
        wx.Dialog.__init__(self, None, title="New project", size=(430,240))
        LabelSize = (100,25) 
        EntrySize = (300,25)
        prjname_sizer = wx.BoxSizer(wx.HORIZONTAL)
 
        prj_lbl = wx.StaticText(self, label="Project name", size=LabelSize)
        prjname_sizer.Add(prj_lbl, 0, wx.ALL|wx.CENTER, 5)
        self.prjName = wx.TextCtrl(self,size=EntrySize)
        prjname_sizer.Add(self.prjName, 10, wx.ALL | wx.EXPAND, 5)

        prjlocation_sizer = wx.BoxSizer(wx.HORIZONTAL)
        prj_location_lbl = wx.StaticText(self, label="Location", size=LabelSize)
        prjlocation_sizer.Add(prj_location_lbl, 0, wx.ALL|wx.CENTER, 5)
        
        self.prjLocation = wx.DirPickerCtrl(self, message="Choose a project location", style=wx.DIRP_DEFAULT_STYLE|wx.DIRP_USE_TEXTCTRL,size=EntrySize) 
        self.prjLocation.SetPath(common.getMostRecentPrjDir())
        prjlocation_sizer.Add(self.prjLocation, 0, wx.ALL, 5)
 
        datamodel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        datamodel_lbl = wx.StaticText(self, label="Data model", size=LabelSize)
        datamodel_sizer.Add(datamodel_lbl, 0, wx.ALL|wx.CENTER, 5)
        
        defaultModel = common.fileResolver("SAFplusAmf.yang")
        self.datamodel = wx.FilePickerCtrl(self, message="Choose a file", path="SAFplusAmf.yang", style=wx.FLP_DEFAULT_STYLE|wx.FLP_USE_TEXTCTRL,  wildcard="Data model (*.yang)|*.yang", size=EntrySize)
        datamodel_sizer.Add(self.datamodel, 0, wx.ALL, 5)
 
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.Add(prjname_sizer, 0, wx.ALL, 5)
        main_sizer.Add(prjlocation_sizer, 0, wx.ALL, 5)
        main_sizer.Add(datamodel_sizer, 0, wx.ALL, 5)
 
        OK_btn = wx.Button(self, label="OK")
        OK_btn.Bind(wx.EVT_BUTTON, self.onBtnHandler)
        cancel_btn = wx.Button(self, label="Cancel")
        cancel_btn.Bind(wx.EVT_BUTTON, self.onBtnHandler)
  
        btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
        btn_sizer.Add(OK_btn, 0, wx.ALL|wx.CENTER, 5)
        btn_sizer.Add(cancel_btn, 0, wx.ALL|wx.CENTER, 5)  
              
        main_sizer.Add(btn_sizer, 0, wx.ALL|wx.CENTER, 5)

        self.SetSizer(main_sizer)
        main_sizer.Layout()
        prjname_sizer.Layout()
Esempio n. 7
0
  def load(self, fileOrString):
    """Load an XML representation of the model"""
    if fileOrString[0] != "<":  # XML must begin with opener
      self.filename = common.fileResolver(fileOrString)
      f = open(self.filename,"r")
      fileOrString = f.read()
      f.close()
    dom = xml.dom.minidom.parseString(fileOrString)
    self.data = microdom.LoadMiniDom(dom.childNodes[0])

    self.loadModules()

    # Populate the helper variables from the microdom
    entities = self.data.getElementsByTagName("entities")
    ideEntities = self.data.getElementsByTagName("ide_entity_info")
    if ideEntities: ideEntities = ideEntities[0]  # Get first item in the list
    if entities:
      assert(len(entities)==1)
      entities = entities[0]
      fileEntLst = []
      for ed in entities.children(microdom.microdomFilter):
        name = ed["name"].data_
        entType = self.entityTypes[ed.tag_]

        pos = None
        size = None
        if ideEntities: # Load the pos and size from the model (if it exists)
          ideInfo = ideEntities.getElementsByTagName(name)
          if ideInfo:
            ideInfo = ideInfo[0]
            pos = common.str2Tuple(ideInfo["position"].data_)
            size = common.str2Tuple(ideInfo["size"].data_)

        if pos is None:
          pos = self.makeUpAScreenPosition()
          size = entType.iconSvg.size
        eo = entity.Entity(entType,pos,size,name)
        eo.updateDataFields(ed)
        self.entities[name] = eo
        fileEntLst.append((ed,eo))

      # Look for relationships.  I can't do this until all the entities are created
      for (ed,eo) in fileEntLst:        
        for et in self.entityTypes.items():   # Look through all the children for a key that corresponds to the name of an entityType (+ s), eg: "ServiceGroups"
          if ed.child_.has_key(et[0] + 's'):
            linkstr = ed.child_[et[0] + 's'].data_
            linklst = linkstr.split(",")
            for link in linklst:
              contained = self.entities.get(link,None)
              if contained:
                # TODO: look the positions up in the GUI section of the xml file
                (beginOffset, endOffset, midpoints) = self.getContainmemtArrowPos(ideEntities, eo, contained)
                ca = entity.ContainmentArrow(eo,beginOffset,contained,endOffset,midpoints)
                eo.containmentArrows.append(ca)
              else:  # target of the link is missing, so drop the link as well.  This could happen if the user manually edits the XML
                # TODO: create some kind of warning/audit log in share.py that we can post messages to.
                pass
      # Recreate all the images in case loading data would have changed them.
      for (ed,eo) in fileEntLst: 
        eo.recreateBitmap()       

      # Get instance lock fields
      ide = self.data.getElementsByTagName("ide")
      if ide:
        for (name,e) in self.entities.items():
          etType = ide[0].getElementsByTagName(e.et.name)
          if etType:
            et = etType[0].getElementsByTagName(name)
            if et:
              for ed in et[0].children(microdom.microdomFilter):
                e.instanceLocked[str(ed.tag_)] = ed.data_


    instances = self.data.find("instances")
    if instances:
      for (path, obj) in instances:
        fileEntLst = []
        for entityType in self.entityTypes.keys():
          for instance in obj.children(lambda(x): x if (type(x) is types.InstanceType and x.__class__ is microdom.MicroDom and x.tag_ == entityType) else None):
            if instance.child_.has_key("%sType"%entityType):
              entityTypeName = instance.child_.get("%sType"%entityType).data_

              # Entity of this instance
              entityParent = self.entities.get(entityTypeName)
              entityInstance = entity.Instance(entityParent, instance, (0,0), (10,10), instance.name.data_)
              entityInstance.updateDataFields(instance)
    
              # Copy instance locked, then bind to readonly wxwidget
              entityInstance.instanceLocked = entityParent.instanceLocked.copy()
              self.instances[instance.name.data_] = entityInstance
              fileEntLst.append((instance,entityInstance))
  
      for (ed,eo) in fileEntLst:
        for et in self.entityTypes.items():   # Look through all the children for a key that corresponds to the name of an entityType (+ s), eg: "ServiceGroups"
          child = et[0][0].lower() + et[0][1:] + 's'
          for ch in ed.children(lambda(x): x if (type(x) is types.InstanceType and x.__class__ is microdom.MicroDom and x.tag_ == child) else None):
            # Strip out instance-identifier if any
            childName = str(ch.data_)[str(ch.data_).rfind("/")+1:]
            contained = self.instances.get(childName,None)
            if contained:
              # TODO: look the positions up in the GUI section of the xml file
              ca = entity.ContainmentArrow(eo,(0,0),contained,(0,0),[])
              contained.childOf.add(eo)
              eo.containmentArrows.append(ca)
            else:  # target of the link is missing, so drop the link as well.  This could happen if the user manually edits the XML
              # TODO: create some kind of warning/audit log in share.py that we can post messages to.
              pass
Esempio n. 8
0
def SvgFile(filename):
    filename = common.fileResolver(filename)
    f = open(filename, "r")
    data = f.read()
    f.close()
    return Svg(data)