📄 components_4.py
字号:
def focus_out(self, event):
self.canvas.itemconfig(self.bnc, fill=self.last_background)
self.update()
def update(self):
# First do the blink, if set to blink
if self.blink:
if self.on:
if not self.onState:
self.onState = self.status
self.status = STATUS_OFF
self.on = 0
else:
if self.onState:
self.status = self.onState # Current ON color
self.on = 1
# now update the status
self.canvas.itemconfig(self.bnc, fill=self.Colors[self.status])
self.canvas.itemconfig(self.pins, fill=self.Colors[self.status])
self.bnc_frame.update_idletasks()
if self.blink:
self.bnc_frame.after(self.blinkrate * 1000, self.update)
class FDDI(GUICommon):
def __init__(self, master, status=STATUS_OFF, orient=HW_HORIZONTAL,
port=-1, fid=''):
self.hitID = fid
self.status = status
self.blink = 0
self.blinkrate = 1
self.on = 0
self.onState = None
self.high = FALSE
self.Colors = [None, Color.DISP, Color.ON,
Color.WARN, Color.ALARM, '#00ffdd']
if orient == HW_HORIZONTAL:
width = 46
height = 20
iwidth = 16
iheight = 15
ix = 0
else:
width = 20
height = 46
iwidth = 15
iheight = 16
ix = 1
st_wid.append(self) # register for animation
self.fddi_frame = Frame(master, relief="raised", width=width,
height=height, bg=Color.DISP, bd=1,
takefocus=1)
self.fddi_frame.bind('<FocusIn>', self.focus_in)
self.fddi_frame.bind('<FocusOut>', self.focus_out)
self.rx = Frame(self.fddi_frame, relief="sunken", width=iwidth,
height=iheight, bg=Color.INSIDE, bd=1)
self.rx.place(relx=[0.05,0.06][ix], rely=0.05, anchor=NW)
self.tx = Frame(self.fddi_frame, relief="sunken", width=iwidth,
height=iheight, bg=Color.INSIDE, bd=1)
self.tx.place(relx=0.95, rely=[0.05,0.95][ix], anchor=[NE,SE][ix])
if self.hitID:
self.hitID = '%s.%d' % (self.hitID, port)
for widget in [self.fddi_frame, self.rx, self.tx]:
widget.bind('<KeyPress-space>', self.panelMenu)
widget.bind('<Button-1>', self.panelMenu)
def focus_in(self, event):
self.last_background = self.fddi_frame['background']
self.fddi_frame['background'] = Color.HIGHLIGHT
self.high = TRUE
self.update()
def focus_out(self, event):
self.fddi_frame['background'] = self.last_background
self.high = FALSE
self.update()
def update(self):
# First do the blink, if set to blink
if self.blink:
if self.on:
if not self.onState:
self.onState = self.status
self.status = STATUS_OFF
self.on = 0
else:
if self.onState:
self.status = self.onState # Current ON color
self.on = 1
# Set color for current status
if not self.high:
self.fddi_frame['background'] = self.Colors[self.status]
self.fddi_frame.update_idletasks()
if self.blink:
self.fddi_frame.after(self.blinkrate * 1000, self.update)
class JConnector(GUICommon):
def __init__(self, master, width, height, orient=HW_HORIZONTAL,
port=-1, fid='', status=STATUS_OFF):
self.hitID = fid
self.status = status
self.blink = 0
self.blinkrate = 1
self.on = 0
self.onState = None
if orient == HW_HORIZONTAL:
use_width = width
use_height = height
else:
use_width = height
use_height = width
st_wid.append(self) # register for animation
self.j_frame = Frame(master, relief="raised", width=use_width,
height=use_height, bg=Color.CHROME, bd=2,
takefocus=1)
self.j_frame.bind('<FocusIn>', self.focus_in)
self.j_frame.bind('<FocusOut>', self.focus_out)
self.body = Frame(self.j_frame, relief="sunken", width=use_width-6,
height=use_height-6, bg=Color.CHROME, bd=2)
self.body.place(relx=0.5, rely=0.5, anchor=CENTER)
self.i1 = Frame(self.body, relief="sunken", width=use_width-8,
height=use_height-8,
bg=Color.INSIDE, bd=1)
self.i1.place(relx=0.5, rely=0.5, anchor=CENTER)
if self.hitID:
self.hitID = '%s.%d' % (self.hitID, port)
for widget in [self.j_frame, self.body, self.i1]:
widget.bind('<KeyPress-space>', self.panelMenu)
widget.bind('<Button-1>', self.panelMenu)
def update(self):
# First do the blink, if set to blink
if self.blink:
if self.on:
if not self.onState:
self.onState = self.status
self.status = STATUS_OFF
self.on = 0
else:
if self.onState:
self.status = self.onState # Current ON color
self.on = 1
self.j_frame.update_idletasks()
if self.blink:
self.j_frame.after(self.blinkrate * 1000, self.update)
def turnon(self):
self.j_frame['background'] = Color.ON
self.body['background'] = Color.CHROME
self.update()
def turnoff(self):
self.j_frame['background'] = Color.CHROME
self.body['background'] = Color.CHROME
self.update()
def warn(self):
self.j_frame['background'] = Color.WARN
self.body['background'] = Color.WARN
self.update()
def alarm(self):
self.j_frame['background'] = Color.ALARM
self.body['background'] = Color.ALARM
self.update()
def focus_in(self, event):
self.last_j_frame_background = self.j_frame['background']
self.last_body_background = self.body['background']
self.j_frame['background'] = Color.HIGHLIGHT
self.body['background'] = Color.HIGHLIGHT
self.update()
def focus_out(self, event):
self.j_frame['background'] = self.last_j_frame_background
self.body['background'] = self.last_body_background
self.update()
class J9(JConnector):
def __init__(self, master, port=-1, fid='', orient=HW_HORIZONTAL,
status=STATUS_OFF):
JConnector.__init__(self, master=master, width=40, height=22,
port=port, fid=fid,
status=status, orient=orient)
class J25(JConnector):
def __init__(self, master, port=-1, fid='', orient=HW_HORIZONTAL,
status=STATUS_OFF):
JConnector.__init__(self, master=master, width=100, height=22,
port=port, fid=fid,
status=status, orient=orient)
class J50(JConnector):
def __init__(self, master, port=-1, fid='', orient=HW_HORIZONTAL,
status=STATUS_OFF):
JConnector.__init__(self, master=master, width=90, height=18,
port=port, fid=fid,
status=status, orient=orient)
class FastSerial(JConnector):
def __init__(self, master, port=-1, fid='', orient=HW_HORIZONTAL,
status=STATUS_OFF):
JConnector.__init__(self, master=master, width=66, height=24,
port=port, fid=fid,
status=status, orient=orient)
class PanelText:
def __init__(self, master=None, appearance="flat", width=0,
bg='gray15', bd=0, text="", fg='yellow'):
# preserve various values
self.text_frame = Frame(master, relief=appearance, bg=bg, bd=bd,
highlightthickness=0, takefocus=0)
# font = ("PixelPoint", 10)
font = ("Verdana", 10)
self.text=Label(self.text_frame, text=text[:2], fg=fg,
bg=bg, font=font)
self.text.pack()
def display(self, newtext):
self.text['text'] = newtext
self.update()
class PowerSupply(GUICommon):
def __init__(self, master, width=160, height=130, bg=Color.PANEL,
status=STATUS_ON):
self.base = bg
self.set_colors(master)
self.psu_frame = Frame(master, relief=SUNKEN, bg=self.dbase, bd=2,
width=width, height=height)
Label(self.psu_frame, text='DC OK', fg='white',
bg=self.dbase, font=('Verdana', 10, 'bold'),
bd=0).place(relx=.8, rely=.15, anchor=CENTER)
self.led = LED(self.psu_frame, height=12, width=12, shape=ROUND,
bg=self.dbase)
self.led.led_frame.place(relx=0.8, rely=0.31, anchor=CENTER)
lsub = Frame(self.psu_frame, width=width/1.2, height=height/2,
bg=self.dbase, bd=1, relief=GROOVE)
lsub.place(relx=0.5, rely=0.68, anchor=CENTER)
pwr=PowerConnector(lsub)
pwr.socket_frame.place(relx=0.30, rely=0.5, anchor=CENTER)
sw=PowerSwitch(lsub)
sw.switch_frame.place(relx=0.75, rely=0.5, anchor=CENTER)
class Screw(GUICommon):
def __init__(self, master, diameter=18, base="gray40", bg=Color.PANEL):
self.base = base
basesize = diameter+6
self.screw_frame = Frame(master, relief="flat", bg=bg, bd=0,
highlightthickness=0)
self.set_colors(self.screw_frame)
canvas=Canvas(self.screw_frame, width=basesize, height=basesize,
highlightthickness=0, bg=bg, bd=0)
center = basesize/2
r = diameter/2
r2 = r - 4.0
canvas.create_oval(center-r, center-r, center+r, center+r,
fill=self.base, outline=self.lbase)
canvas.create_rectangle(center-r2, center-0.2,
center+r2, center+0.2,
fill=self.dbase, width=0)
canvas.create_rectangle(center-0.2, center-r2,
center+0.2, center+r2,
fill=self.dbase, width=0)
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(self.card_frame,text=lbl,
font=("verdana", 4), fg="white",
bg=bg).place(relx=0.5,rely=ypos,anchor=CENTER)
class FastSerialCard(CardBlank,StandardLEDs):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -