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