Esempio n. 1
0
class ConsoleForm(Form):

	def __init__(self):
		self.Text = "SolverStudio Julia Console"
		self.FormBorderStyle = FormBorderStyle.FixedDialog    
		self.Height= 130
		self.Width = 460

		# self.Closed += CallTarget2(self.OnClosed)   # Kill any running command
		self.Closed += self.FormClosed # Never got this to work
		# self.ControlBox = False # Force the user to quit using the Close button which we can handle; getting a closing/closed event from the form is too hard

		self.label = Label()
		self.label.Text = "Please enter your Julia command:"
		self.label.Location = Point(10,10)
		self.label.Height  = 20
		self.label.Width = 230

		self.KeyText = TextBox()
		self.KeyText.Location = Point(10,30)
		self.KeyText.Width = 340
		self.KeyText.Height  = 20

		self.bRun=Button()
		self.bRun.Text = "Run"
		self.bRun.Location = Point(370,28)
		# self.bRun.Width = 100
		self.bRun.Click += self.Run
		
		self.bCancel=Button()
		self.bCancel.Text = "Close"
		self.bCancel.Location = Point(370,65)
		self.bCancel.Click += self.cancel

		self.AcceptButton = self.bRun
		self.CancelButton = self.bCancel

		self.Controls.Add(self.label)
		self.Controls.Add(self.KeyText)	# Add first to get focus
		self.Controls.Add(self.bRun)
		self.Controls.Add(self.bCancel)
		self.CenterToScreen()

	def FormClosed(self, sender, event):
		KillAnyRunningCommand()

	def cancel(self,sender,event):
		KillAnyRunningCommand()
		self.Close()
		
	# This did not work with a weird error
	#def commandCompletedCallback(self,processExited):
	#	# This gets called on a different thread; use invoke to call it on the creating thread as needed to access controls and forms
	#	if self.InvokeRequired:
	#		 self.Invoke( commandCompletedCallback(self,processExited) );
	#		 return
	#	self.bRun.Enabled = True

	def commandCompletedCallback(self,processExited):
		# commandCompletedCallback gets called on a different thread; use invoke to change to the creating thread as needed to access controls and forms
			# See http://www.ironpython.info/index.php?title=Invoking_onto_the_GUI_%28Control%29_Thread
		def EnableRunButton():
			self.bRun.Enabled = True
			self.bRun.Text = "Run"
		# self.bRun.Invoke( CallTarget0(EnableRunButton) );
		self.bRun.Invoke( CallTarget0(EnableRunButton) );   # Use CallTarget0 if IronPython is unable to convert to a delegate by itself; see http://www.voidspace.org.uk/ironpython/dark-corners.shtml

	def Run(self,sender,event):
		interactiveExe = SolverStudio.InteractiveExes.GetInteractiveExe("Julia")
		if not interactiveExe.IsRunning:
			SolverStudio.AppendToTaskPane( "## Starting Julia ("+interactiveExe.Executable+") console\r\n")
			interactiveExe.Start()
			# print "Working Dir =",interactiveExe.WorkingDirectory;
		commandToSend = self.KeyText.Text
		SolverStudio.AppendToTaskPane(">"+commandToSend+"\r\n") # Print does not work
		#try:
		self.bRun.Enabled = False
		self.bRun.Text = "Running..."
		interactiveExe.SendCommand(self.KeyText.Text, False, self.commandCompletedCallback) # NB: Cannot run in the main thread as it deadlocks if we wait for completion