File: GUIdemo_OO.py

package info (click to toggle)
python-simpy 2.3.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,864 kB
  • sloc: python: 11,171; makefile: 143
file content (58 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
__doc__=""" GUIdemo_OO.py
This is a very basic model, demonstrating the ease
of interfacing to SimGUI.
"""
from SimPy.Simulation  import *
from SimPy.Monitor import *
from random import *
from SimPy.SimGUI import *

## Model components ---------------------------------------

class Launcher(Process):
    nrLaunched=0
    def launch(self):
        while True:
            gui.writeConsole("Launch at %.1f"%self.sim.now())
            Launcher.nrLaunched+=1
            gui.launchmonitor.observe(Launcher.nrLaunched)
            yield hold,self,uniform(1,gui.params.maxFlightTime)
            gui.writeConsole("Boom!!! Aaaah!! at %.1f"%self.sim.now())
            
## Model --------------------------------------------------
class GUIdemoModel(Simulation):
    def run(self):
        self.initialize()
        gui.launchmonitor=Monitor(name="Rocket counter",
                              ylab="nr launched",tlab="time",sim=self)
        Launcher.nrLaunched=0
        for i in range(gui.params.nrLaunchers):
            lau=Launcher(sim=self)
            self.activate(lau,lau.launch())
        self.simulate(until=gui.params.duration)
        gui.noRunYet=False
        gui.writeStatusLine("%s rockets launched in %.1f minutes"%
                        (Launcher.nrLaunched,self.now()))
                        
## Model GUI ----------------------------------------------

class MyGUI(SimGUI):
    def __init__(self,win,**par):
        SimGUI.__init__(self,win,**par)
        self.run.add_command(label="Start fireworks",
                             command=GUIdemoModel().run,underline=0)
        self.params=Parameters(duration=duration,
                               maxFlightTime=maxFlightTime,
                               nrLaunchers=nrLaunchers)
        
## Experiment data ----------------------------------------

duration=2000
maxFlightTime=11.7
nrLaunchers=3

## Experiment/Display  ------------------------------------

root=Tk()
gui=MyGUI(root,title="RocketGUI",doc=__doc__,consoleHeight=40)
gui.mainloop()