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