interrupt_gui.py
Go to the documentation of this file.
9 
10 import wx
11 import threading
12 from gams import *
13 
15  def __init__(self, textCtrl):
16  self.textCtrl = textCtrl
17 
18  def write(self, text):
19  self.textCtrl.AppendText(text)
20 
21  def flush(self):
22  self.textCtrl.Update()
23  self.textCtrl.Refresh()
24 
25 class InterruptGui(wx.Frame):
26 
27  def close(self, event):
28  self.Close()
29 
30  def cancel(self, event):
31  self.t1.interrupt()
32 
33  def run_gams(self):
34  writer = TextCtrlWriter(self.log)
35  ws = GamsWorkspace()
36  ws.gamslib("lop")
37  opt = ws.add_options()
38  opt.all_model_types = "soplex"
39  self.t1 = ws.add_job_from_file("lop.gms")
40  self.t1.run(opt, output=writer)
41  self.bu_run.Enable()
42  self.bu_cancel.Disable()
43  self.bu_close.Enable()
44 
45  def run(self, event):
46  self.log.Clear()
47  self.bu_run.Disable()
48  self.bu_close.Disable()
49  self.bu_cancel.Enable()
50  threading.Thread(target=self.run_gams).start()
51 
52  def __init__(self, parent, id, title, size):
53  wx.Frame.__init__(self, parent, id, title, size=size)
54  self.SetBackgroundColour('lightgrey')
55 
56  wx.StaticText(self, -1, "GAMS Log:", (10, 10))
57  self.log = wx.TextCtrl(self, pos=(10, 30), size=(565, 485), style=wx.TE_MULTILINE)
58 
59  self.bu_run = wx.Button(self, -1, "Run", (10,520), (137, 33))
60  self.bu_run.Bind(wx.EVT_BUTTON, self.run)
61 
62  self.bu_cancel = wx.Button(self, -1, "Cancel", (360,520), (105, 33))
63  self.bu_cancel.Bind(wx.EVT_BUTTON, self.cancel)
64  self.bu_cancel.Disable()
65 
66  self.bu_close = wx.Button(self, -1, "Close", (470,520), (105, 33))
67  self.bu_close.Bind(wx.EVT_BUTTON, self.close)
68 
69 if __name__ == '__main__':
70  app = wx.PySimpleApp()
71  frame = InterruptGui(None, -1, 'Interrupt Example', (600, 600))
72  frame.Show()
73  app.MainLoop();
def cancel(self, event)
def __init__(self, textCtrl)
def close(self, event)
def __init__(self, parent, id, title, size)