def __serialize_to_xml__(iaddin_custom_frame_instance, file_full_name):
        done = False
        try:
            sb = StringBuilder()
            xml_writer_settings = XmlWriterSettings()
            xml_writer_settings.Indent = True
            xml_writer_settings.ConformanceLevel = ConformanceLevel.Fragment
            xml_writer_settings.OmitXmlDeclaration = True
            writer = None
            try:
                writer = XmlWriter.Create(sb, xml_writer_settings)
                if writer:
                    mgr = XamlDesignerSerializationManager(writer)
                    if mgr:
                        mgr.XamlWriterMode = XamlWriterMode.Expression
                        XamlWriter.Save(iaddin_custom_frame_instance, mgr)
                        filewriter = None
                        try:
                            filewriter = File.CreateText(file_full_name)
                            if filewriter:
                                filewriter.Write(sb.ToString())
                                done = True
                        finally:
                            if filewriter:
                                filewriter.Dispose()
                                filewriter = None
            finally:
                if writer:
                    writer.Dispose()
                    writer = None
        except Exception as e:
            CommonUtil.sprint("Failed to serialize: {}".format(e))
            done = False

        return done
    def __deserialize_from_xml(file_full_name):
        iaddin_custom_frame_instance = None
        try:
            filereader = None
            try:
                filereader = File.OpenText(file_full_name)
                if filereader:
                    content = filereader.ReadToEnd()
                    stringreader = StringReader(content)
                    xmlreader = None
                    try:
                        xmlreader = XmlReader.Create(stringreader)
                        if xmlreader:
                            iaddin_custom_frame_instance = XamlReader.Load(
                                xmlreader)
                    finally:
                        if xmlreader:
                            xmlreader.Dispose()
                            xmlreader = None
            finally:
                if filereader:
                    filereader.Dispose()
                    filereader = None
        except Exception as e:
            CommonUtil.sprint("Failed to desrialize: {}".format(e))
            iaddin_custom_frame_instance = None

        return iaddin_custom_frame_instance
示例#3
0
 def get_dockable_user_control_properties(d):
     propList = None
     try:
         if d:
             propList = List[KeyValuePair[str, str]]()
             for _, value in enumerate(d):
                 pair = KeyValuePair[str, str](value,d[value])
                 propList.Add(pair)
     except Exception as e:
         CommonUtil.sprint("Failed to Create Properties: {}".format(e))
     return propList
示例#4
0
 def PrintContent(self, printScale):
     try:
         if self.ControlContent:
             tempScale = self.LayoutPageScale
             self.LayoutPageScale = printScale
             printContent = InactiveLayoutContent(self.ControlContent)
             self.LayoutPageScale = tempScale
             return printContent
     except Exception as e:
         CommonUtil.sprint("Failed to Print: {}".format(e))
     return None
示例#5
0
 def create_user_control(filename):
     userControl = None
     try:
         s = None
         if filename:
             s = StreamReader(filename)
             userControl = XamlReader.Load(s.BaseStream)
     except Exception as e:
         CommonUtil.sprint("Failed to Create UserControl: {}".format(e))
     finally:
         if s:
             s.Close()
             s.Dispose()
     return userControl
示例#6
0
 def image_path_to_bitmap(fname):
     try:
         if fname:
             bitmap = BitmapImage()
             bitmap.BeginInit()
             bitmap.UriSource = CommonUtil.path_to_uri(fname)
             bitmap.CacheOption = BitmapCacheOption.OnLoad
             bitmap.CreateOptions = BitmapCreateOptions.DelayCreation
             bitmap.EndInit()
             bitmap.Freeze()
             return bitmap
     except:
         pass
示例#7
0
    def load(self):
        try:
            # uncomment these lines to debug the python script using VSCODE
            # Install ptvsd package into your environment using "pip install ptvsd"
            # Debug in VSCODE with Python: Attach configuration

            # here initialize the addin class
            if self._imapinfopro:
                # obtain the handle to current application if needed
                # thisApplication = self._imapinfopro.GetMapBasicApplication(os.path.splitext(__file__)[0] + ".mbx")
                # self._addin = MyAddin(self._imapinfopro, thisApplication)
                self._addin = None
                CommonUtil.sprint("Hello from Python Addin!")
                CommonUtil.do("""
print "Hello from (MapBasic code inside) Python Addin!"
                """)
                CommonUtil.sprint("sys.path => " + pathMsg)

        except Exception as e:
            CommonUtil.sprint("Failed to load: {}".format(e))
示例#8
0
 def unload(self):
     try:
         CommonUtil.sprint("Unload addin")
         self._addin = None
     except Exception as e:
         CommonUtil.sprint("Failed to unload: {}".format(e))
示例#9
0
 def reconstruct(self, fileName, xPosition, yPosition, width, height,
                 penMapBasicCommand, brushMapBasicCommand, zIndex, name):
     try:
         CommonUtil.sprint("Reconstruct addin")
     except Exception as e:
         CommonUtil.sprint("Failed to reconstruct: {}".format(e))