Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import clr,os
- clr.AddReference("System.Windows.Forms")
- clr.AddReference("System.Drawing")
- from System import *
- from System.Windows.Forms import *
- from System.Drawing import *
- class IPY2EXE(Form):
- def __init__(self):
- self.initUI()
- def initUI(self):
- def initWidgets():
- #Label 1
- self.label1 = Label()
- self.label1.AutoSize = True
- self.label1.Location = Point(9, 13)
- self.label1.Name = 'label1'
- self.label1.Size = Size(89, 13)
- self.label1.TabIndex = 2
- self.label1.Text = 'IronPython script:'
- self.Controls.Add(self.label1)
- # label2
- self.label2 = Label()
- self.label2.AutoSize = True
- self.label2.Location = Point(13, 55)
- self.label2.Name = 'label2'
- self.label2.Size = Size(41, 13)
- self.label2.TabIndex = 7
- self.label2.Text = 'Target:'
- self.Controls.Add(self.label2)
- # CompileBtn
- self.CompileBtn = Button()
- self.CompileBtn.Location = Point(291, 80)
- self.CompileBtn.Name = 'CompileBtn'
- self.CompileBtn.Size = Size(87, 36)
- self.CompileBtn.TabIndex = 6
- self.CompileBtn.Text = 'Compile'
- self.CompileBtn.UseVisualStyleBackColor = True
- self.CompileBtn.Click += self.compile
- self.Controls.Add(self.CompileBtn)
- # BrowseScriptBtn
- self.BrowseScriptBtn = Button()
- self.BrowseScriptBtn.Location = Point(303, 26)
- self.BrowseScriptBtn.Name = 'BrowseScriptBtn'
- self.BrowseScriptBtn.Size = Size(75, 28)
- self.BrowseScriptBtn.TabIndex = 0
- self.BrowseScriptBtn.Text = 'Browse'
- self.BrowseScriptBtn.UseVisualStyleBackColor = True
- self.BrowseScriptBtn.Click += self.BrowseScriptBtnClick
- self.Controls.Add(self.BrowseScriptBtn)
- # ScriptPathTxtBx
- self.ScriptPathTxtBx = TextBox()
- self.ScriptPathTxtBx.Location = Point(12, 31)
- self.ScriptPathTxtBx.Name = 'ScriptPathTxtBx'
- self.ScriptPathTxtBx.Size = Size(285, 20)
- self.ScriptPathTxtBx.TabIndex = 1
- self.Controls.Add(self.ScriptPathTxtBx)
- # listBox1
- self.listBox1 = ListBox()
- self.listBox1.FormattingEnabled = True
- self.listBox1.Items.AddRange(Array[Object](('dll', 'exe', 'winexe', )))
- self.listBox1.Location = Point(16, 73)
- self.listBox1.Name = 'listBox1'
- self.listBox1.Size = Size(120, 43)
- self.listBox1.TabIndex = 8
- self.Controls.Add(self.listBox1)
- # checkBox1
- self.checkBox1 = CheckBox()
- self.checkBox1.AutoSize = True
- self.checkBox1.Location = Point(142, 95)
- self.checkBox1.Name = 'checkBox1'
- self.checkBox1.Size = Size(128, 17)
- self.checkBox1.TabIndex = 9
- self.checkBox1.Text = 'Standalone (not dll)'
- self.checkBox1.UseVisualStyleBackColor = True
- self.Controls.Add(self.checkBox1)
- self.Text = 'IPY2EXE'
- self.Name = 'IPY2EXE'
- self.ClientSize = Size(390, 124)
- self.ResumeLayout(False)
- self.PerformLayout()
- initWidgets()
- def BrowseScriptBtnClick(self, Object, EventArg):
- dialog = OpenFileDialog()
- dialog.Title = 'Open .py'
- dialog.Filter = 'Py Files(*.py)|*.py'
- if dialog.ShowDialog() != 0:
- self.ScriptPathTxtBx.Text = dialog.FileName
- def compile(self, Object, EventArg):
- try:
- if self.listBox1.SelectedItem == None:
- MessageBox.Show('Please select a target', 'Error', MessageBoxButtons.OK,MessageBoxIcon.Error)
- return False
- target = self.listBox1.SelectedItem.ToString()
- if self.checkBox1.Checked:standAlone = '/embed /standalone'
- else: standAlone = ''
- if self.ScriptPathTxtBx.Text == '':
- MessageBox.Show('Please select a script', 'Error', MessageBoxButtons.OK,MessageBoxIcon.Error)
- return False
- scriptPath = self.ScriptPathTxtBx.Text
- dialog = SaveFileDialog()
- dialog.Title = 'Compile'
- dialog.Filter = 'Windows executable(*.exe)|*.exe'
- if dialog.ShowDialog() != 0:
- output = dialog.FileName
- else:
- return False
- pycArg = 'ipy.exe Tools\Scripts\pyc.py /target:{0} {1} /out:{2} /main:{3}'.format(target,standAlone,output,scriptPath)
- os.system(pycArg)
- MessageBox.Show('Script Compiled','IPY2EXE',MessageBoxButtons.OK,MessageBoxIcon.Information)
- except AttributeError:
- MessageBox.Show('Is this program located in the Ironpython folder and\nhas been started as administrator?', 'Unknow Error', MessageBoxButtons.OK,MessageBoxIcon.Error)
- form = IPY2EXE()
- Application.Run(form)
Advertisement
Add Comment
Please, Sign In to add comment