📄 components_3.py
字号:
canvas.pack(side="top", fill='x', expand='no')
class StandardLEDs(GUICommon):
def __init__(self, master=None, bg=Color.CARD):
for led, label, xpos, ypos, state in [('flt', 'Flt', 0.3, 0.88, 1),
('pwr', 'Pwr', 0.7, 0.88, 2)]:
setattr(self, led, LED(self.card_frame,shape=ROUND,width=8,
status=state, bg=bg))
getattr(self, led).led_frame.place(relx=xpos, rely=ypos,
anchor=CENTER)
Label(self.card_frame, text=label,
font=("verdana", 4), fg="white",
bg=bg).place(relx=xpos,rely=(ypos+0.028), anchor=CENTER)
class CardBlank(GUICommon):
def __init__(self, master=None, width=20, height=396,
appearance="raised", bd=2, base=Color.CARD):
self.base = base
self.set_colors(master)
self.card_frame=Frame(master, relief=appearance, height=height,
width=width, bg=base, bd=bd)
top_pull = CardPuller(self.card_frame, CARD_TOP, width=width)
top_pull.puller_frame.place(relx=.5, rely=0, anchor=N)
bottom_pull = CardPuller(self.card_frame, CARD_BOTTOM, width=width)
bottom_pull.puller_frame.place(relx=.5, rely=1.0, anchor=S)
class CardPuller(GUICommon):
def __init__(self, master, torb, width=20):
self.base = master['background']
self.set_colors(master)
self.puller_frame=Frame(master, width=width, height=32,
bg=self.lbase, relief='flat')
Frame(self.puller_frame, width=width/8, height=8,
bg=self.dbase).place(relx=1.0, rely=[1.0,0][torb],
anchor=[SE,NE][torb])
Frame(self.puller_frame, width=width/3, height=24,
bg=self.vdbase).place(relx=1.0, rely=[0,1.0][torb],
anchor=[NE,SE][torb])
Screw(self.puller_frame, diameter=10, base=self.base,
bg=self.lbase).screw_frame.place(relx=0.3, rely=[0.2,0.8][torb],
anchor=CENTER)
class E10BASETCard(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
yy = 0.26
for i in range(8):
setattr(self, 'j%d' % (i+1), Enet10baseT(self.card_frame,
fid="10Base-T-%d", port=i+1,orient=HW_LEFT, status=STATUS_OFF))
getattr(self, 'j%d' % (i+1)).j45_frame.place(relx=0.5, rely=yy,
anchor=CENTER)
yy = yy + 0.08
xypos = [(0.2,0.1), (0.8,0.1),
(0.2,0.13),(0.8,0.13),
(0.2,0.16),(0.8,0.16),
(0.2,0.19),(0.8,0.19)]
for i in range(8):
xpos,ypos = xypos[i]
setattr(self, 'led%d' % (i+1), LED(self.card_frame,shape=ROUND,
width=6, status=STATUS_ON, bg=bg))
getattr(self, 'led%d' % (i+1)).led_frame.place(relx=xpos,
rely=ypos,anchor=CENTER)
for lbl, ypos in [('1 2', 0.1), ('3 4', 0.13),
('5 6', 0.16),('7 8', 0.19)]:
label=Label(self.card_frame,text=lbl,
font=("verdana", 4), fg="white",bg=bg)
label.place(relx=0.5,rely=ypos,anchor=CENTER)
class FastSerialCard(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
yy = 0.28
for i in range(4):
setattr(self, 'fs%d' % (i+1), J9(self.card_frame,
fid="FastSerial-%d", port=i+1, orient=HW_VERTICAL,
status=STATUS_OFF))
getattr(self, 'fs%d' % (i+1)).j_frame.place(relx=0.5,
rely=yy,anchor=CENTER)
yy = yy + 0.167
xypos = [(0.2,0.1), (0.8,0.1),
(0.2,0.13),(0.8,0.13),
(0.2,0.16),(0.8,0.16),
(0.2,0.19),(0.8,0.19)]
for i in range(8):
xpos,ypos = xypos[i]
setattr(self, 'led%d' % (i+1), LED(self.card_frame,shape=ROUND,
width=6, status=STATUS_ON, bg=bg))
getattr(self, 'led%d' % (i+1)).led_frame.place(relx=xpos,
rely=ypos,anchor=CENTER)
for lbl, ypos in [('1', 0.1), ('2', 0.13),
('3', 0.16),('4', 0.19)]:
label=Label(self.card_frame,text=lbl,
font=("verdana", 4), fg="white",bg=bg)
label.place(relx=0.5,rely=ypos,anchor=CENTER)
class ProcessorCard(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
self.j45=Enet10baseT(self.card_frame,fid="ClockPort",
port=1,orient=HW_LEFT, status=STATUS_OFF)
self.j45.j45_frame.place(relx=0.5,rely=0.25,anchor=CENTER)
lbl=Label(self.card_frame,text="Clock",
font=("verdana", 6), fg="white",bg=bg)
lbl.place(relx=0.5, rely=0.20,anchor=S)
self.cmd=J25(self.card_frame,fid="ControlPort",
port=1,orient=HW_VERTICAL, status=STATUS_OFF)
self.cmd.j_frame.place(relx=0.5,rely=0.65,anchor=CENTER)
lbl=Label(self.card_frame,text="CLI",
font=("verdana", 6), fg="white",bg=bg)
lbl.place(relx=0.5, rely=0.52,anchor=S)
xypos = [(0.3,0.35),(0.7,0.35),
(0.3,0.38),(0.7,0.38),
(0.3,0.41),(0.7,0.41),
(0.3,0.44),(0.7,0.44)]
for i in range(8):
xpos,ypos = xypos[i]
setattr(self, 'led%d' % (i+1), LED(self.card_frame, shape=ROUND,
width=6, status=STATUS_ON, bg=bg))
getattr(self, 'led%d' % (i+1)).led_frame.place(relx=xpos,
rely=ypos,anchor=CENTER)
class SwitchCard(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
xypos = [(0.3,0.35),(0.7,0.35),
(0.3,0.38),(0.7,0.38)]
for i in range(4):
xpos,ypos = xypos[i]
setattr(self, 'led%d' % (i+1), LED(self.card_frame, shape=ROUND,
width=6, status=STATUS_ON, bg=bg))
getattr(self, 'led%d' % (i+1)).led_frame.place(relx=xpos,
rely=ypos,anchor=CENTER)
self.status = PanelText(self.card_frame, text='OK')
self.status.text_frame.place(relx=0.5, rely=0.5, anchor=CENTER)
class T3AccessCard(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
for port, lbl, tag, ypos in [(1,'RX1','T3AccessRX', 0.30),
(2,'TX1','T3AccessTX', 0.40),
(3,'RX2','T3AccessRX', 0.65),
(4,'TX2','T3AccessRX', 0.75)]:
setattr(self, 'bnc%d' % port, BNC(self.card_frame, fid=tag,
port=port))
getattr(self, 'bnc%d' % port).bnc_frame.place(relx=0.5,
rely=ypos,anchor=CENTER)
label=Label(self.card_frame,text=lbl,
font=("verdana", 6), fg="white",bg=bg)
label.place(relx=0.5, rely=(ypos+0.045), anchor=CENTER)
for led, lbl, xpos, ypos, state in [('rxc','RXC',0.3,0.18,2),
('oos','OOS',0.7,0.18,1),
('flt','FLT',0.3,0.23,1),
('syn','SYN',0.7,0.23,2),
('rxc','RXC',0.3,0.53,2),
('oos','OOS',0.7,0.53,1),
('flt','FLT',0.3,0.58,1),
('syn','SYN',0.7,0.58,2)]:
setattr(self, led, LED(self.card_frame,shape=ROUND,width=8,
status=state, bg=bg))
getattr(self, led).led_frame.place(relx=xpos,
rely=ypos,anchor=CENTER)
label=Label(self.card_frame,text=lbl,
font=("verdana", 4), fg="white",bg=bg)
label.place(relx=xpos, rely=(ypos+0.028), anchor=CENTER)
class OC3Card(CardBlank,StandardLEDs):
def __init__(self, master, width=1, height=1):
CardBlank.__init__(self, master=master, width=width, height=height)
bg=master['background']
StandardLEDs.__init__(self, master=master, bg=bg)
yy = 0.28
for i in range(4):
setattr(self, 'oc3%d' % (i+1), FDDI(self.card_frame, fid="OC3-%d",
port=i+1, orient=HW_VERTICAL, status=STATUS_OFF))
getattr(self, 'oc3%d' % (i+1)).fddi_frame.place(relx=0.5,
rely=yy, anchor=CENTER)
yy = yy + 0.167
left = TRUE
yy =0.213
for i in range(8):
if left:
xpos = 0.3
else:
xpos = 0.7
setattr(self, 'led%d' % (i+1), LED(self.card_frame, shape=ROUND,
width=6, status=STATUS_ON, bg=bg))
getattr(self, 'led%d' % (i+1)).led_frame.place(relx=xpos,
rely=yy, anchor=CENTER)
if left:
left = FALSE
else:
left = TRUE
yy = yy + 0.167
class Chassis:
def __init__(self, master):
self.outer=Frame(master, width=540, height=650,
borderwidth=2, bg=Color.PANEL)
self.outer.forget() # We won't display until all
# the widgets have been created
self.inner=Frame(self.outer, width=490, height=650,
borderwidth=2, relief=RAISED, bg=Color.PANEL)
self.inner.place(relx=0.5, rely=0.5, anchor=CENTER)
self.rack = Frame(self.inner, bd=2, width=325, height=416,
bg=Color.CHASSIS)
self.rack.place(relx=0.985, rely=0.853, anchor=SE)
incr = 325/9
x = 0.0
for i in range(9):
if i == 0:
card =ProcessorCard(self.rack, width=incr-1, height=414)
elif i == 1:
card =SwitchCard(self.rack, width=incr-1, height=414)
elif i == 2:
card =OC3Card(self.rack, width=incr-1, height=414)
elif i == 3:
card =E10BASETCard(self.rack, width=incr-1, height=414)
elif i == 4:
card =T3AccessCard(self.rack, width=incr-1, height=414)
elif i > 4:
card =FastSerialCard(self.rack, width=incr-1, height=414)
else:
card =CardBlank(self.rack, width=incr-1, height=414)
card.card_frame.place(x=x, y=0, anchor=NW)
x = x + incr
self.img = PhotoImage(file='images/logo.gif')
self.logo=Label(self.outer, image=self.img, bd=0)
self.logo.place(relx=0.055, rely=0.992, anchor=SW)
self.logo.bind('<Button-1>', self.animate)
for x in [0.02, 0.98]:
for y in [0.0444, 0.3111, 0.6555, 0.9711]:
Screw(self.outer, base="gray50").screw_frame.place(relx=x,
rely=y, anchor=CENTER)
self.psu1 = PowerSupply(self.inner)
self.psu1.psu_frame.place(relx=0.99, rely=0.004, anchor=NE)
self.psu2 = PowerSupply(self.inner)
self.psu2.psu_frame.place(relx=0.65, rely=0.004, anchor=NE)
self.psu2.led.turnoff()
screen1 = Screen(self.inner, width=150, height=600, bg=Color.PANEL)
screen1.screen_frame.place(relx=0.16, rely=0.475, anchor=CENTER)
screen2 = Screen(self.inner, width=330, height=80, bg=Color.PANEL)
screen2.screen_frame.place(relx=0.988, rely=0.989, anchor=SE)
def animate(self, event):
import random
choice = random.choice(range(0, len(st_wid)-1))
op = random.choice(range(0, len(ops)-1))
pstr = 'st_wid[%d].%s()' % (choice, ops[op])
self.cobj = compile(pstr, 'inline', 'exec')
self.rack.after(50, self.doit)
def doit(self):
exec(self.cobj)
self.rack.after(50, self.animate(None))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -