Exemplo n.º 1
0
def FileSaveDialog(initialFile=None):
    dlg = SaveFileDialog()
    dlg.DefaultExt = ".txt"; # Default file extension
    dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
    if initialFile:
        dlg.InitialDirectory = System.IO.Path.GetDirectoryName(initialFile)
        dlg.FileName = System.IO.Path.GetFileName(initialFile)
    if dlg.ShowDialog() == True:
        return dlg.FileNames 
Exemplo n.º 2
0
def HandleExportHeatSource(sender, args):
    NewFileLocation = r"C:\Users"

    dialog = SaveFileDialog()
    dialog.Title = "Export heat source"

    dialog.FileName = "{0}mm_{1}cm-min.xml".format(
        beadSizeInput.Text.replace('.', ','),
        travelSpeedInput.Text.replace('.', ','))
    dialog.Filter = "XML Files|*.xml"
    dialog.InitialDirectory = Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments)

    if dialog.ShowDialog():
        NewFileLocation = dialog.FileName
        file_path = os.path.dirname(os.path.realpath(__file__))
        HeatSourceFile = os.path.join(file_path, 'Heat-source_Power.xml')

        RequiredPower, _ = ReqPowerText.Text.split(' kJ')
        FrontLength, _ = FLEstimate.Text.split(' mm')
        RearLength, _ = RLEstimate.Text.split(' mm')
        WidthLength, _ = WidthEstimate.Text.split(' mm')
        DepthLength, _ = DepthEstimate.Text.split(' mm')

        with open(NewFileLocation, 'w') as NewHeatSource:
            with open(HeatSourceFile, 'r') as Template:
                for line in Template:
                    if "<comment>" in line:
                        line = "<comment>{0}</comment>".format(
                            "Generated by MSC Apex welding toolkit")
                    if "<velocity dimension=" in line:
                        line = '<velocity dimension="7" unit="8">{0}</velocity>'.format(
                            travelSpeedInput.Text)
                    if "<power dimension=" in line:
                        line = '<power dimension="12" unit="0">{0}</power>'.format(
                            RequiredPower)
                    if "<efficiency>" in line:
                        line = '<efficiency>{0}</efficiency>'.format(
                            effParamInput.Text)
                    if "<front_length" in line:
                        line = '<front_length dimension="5" unit="2" value="{0}"/>'.format(
                            FrontLength)
                    if '<rear_length' in line:
                        line = '<rear_length dimension="5" unit="2" value="{0}"/>'.format(
                            RearLength)
                    if '<width dimension' in line:
                        line = '<width dimension="5" unit="2" value="{0}"/>'.format(
                            WidthLength)
                    if '<depth dimension' in line:
                        line = '<depth dimension="5" unit="2" value="{0}"/>'.format(
                            DepthLength)
                    NewHeatSource.write(line)
Exemplo n.º 3
0
def HandleExportHeatSource(sender, args):
    NewFileLocation = r"C:\Users"

    dialog = SaveFileDialog()
    dialog.Title = "Export heat source"

    dialog.FileName = "{0}cm-min_{1}A_{2}V.xml".format(travelSpeedInput.Text,
                                                       elecCurrentInput.Text,
                                                       elecVoltageInput.Text)
    dialog.Filter = "XML Files|*.xml"
    dialog.InitialDirectory = Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments)

    if dialog.ShowDialog():
        NewFileLocation = dialog.FileName
        file_path = os.path.dirname(os.path.realpath(__file__))
        HeatSourceFile = os.path.join(file_path, 'Heat-source.xml')
        with open(NewFileLocation, 'w') as NewHeatSource:
            with open(HeatSourceFile, 'r') as Template:
                for line in Template:
                    if "<comment>" in line:
                        line = "<comment>{0}</comment>".format(
                            "Generated by MSC Apex welding toolkit")
                    if "<velocity dimension=" in line:
                        line = '<velocity dimension="7" unit="8">{0}</velocity>'.format(
                            travelSpeedInput.Text)
                    if "<voltage dimension=" in line:
                        line = '<voltage dimension="20" unit="0">{0}</voltage>'.format(
                            elecVoltageInput.Text)
                    if "<current dimension=" in line:
                        line = '<current dimension="2" unit="0">{0}</current>'.format(
                            elecCurrentInput.Text)
                    if "<efficiency>" in line:
                        line = '<efficiency>{0}</efficiency>'.format(
                            effParamInput.Text)
                    if "<front_length" in line:
                        line = '<front_length dimension="5" unit="2" value="{0}"/>'.format(
                            FLEstimate.Text)
                    if '<rear_length' in line:
                        line = '<rear_length dimension="5" unit="2" value="{0}"/>'.format(
                            RLEstimate.Text)
                    if '<width dimension' in line:
                        line = '<width dimension="5" unit="2" value="{0}"/>'.format(
                            WidthEstimate.Text)
                    if '<depth dimension' in line:
                        line = '<depth dimension="5" unit="2" value="{0}"/>'.format(
                            DepthEstimate.Text)
                    NewHeatSource.write(line)
Exemplo n.º 4
0
    def SaveXMLButton_Click(self, sender, e):
        dlg = SaveFileDialog()
        dlg.Filter = "XML file (*.xml)|*.xml"
        dlg.FilterIndex = 2
        dlg.RestoreDirectory = True

        if dlg.ShowDialog() == True:
            file_name = dlg.FileName
            try:
                with open(file_name, 'wb') as file:
                    results = parse_results(self.file_names)
                    xml = generate_xml(results)
                    file.write(xml)

                self.SaveXMLButton.IsEnabled = False
                self.log_clear()
                self.log_append("XML successfully created.")
            except IOError:
                print("Cannot save current data to file.")