-
Notifications
You must be signed in to change notification settings - Fork 57
/
state_label.py
58 lines (48 loc) · 1.96 KB
/
state_label.py
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
#!/usr/bin/env python
# coding:utf-8
import wx
from common import *
from conf import Conf
from module.module_factory import ModuleFactory
from wx.lib.stattext import GenStaticText
import webbrowser
class StateLabel(GenStaticText):
"""
根据状态显示不同的颜色显示
"""
def __init__(self, parent, id=-1, label='', pos=(-1, -1),
size=(-1, -1), style=0, name=''):
GenStaticText.__init__(self, parent, id, label, pos, size, style, name)
self.state_config = Conf().get('state_style')
font = 'Verdana'
self.normal_font = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False, font)
self.underline_font = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, True, font)
self.SetFont(self.normal_font)
self.SetForegroundColour('red')
self.SetBackgroundColour('white')
self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_event)
self.Bind(wx.EVT_MOTION, self.on_mouse_event)
def on_mouse_event(self, event):
if event.Moving():
self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
self.SetFont(self.underline_font)
elif event.LeftUp():
mod = ModuleFactory.factory(self.GetName())
state = mod.get_state().upper()
if state == RUNNING:
mod.stop_service()
elif state == STOPPED:
mod.start_service()
else:
self.SetCursor(wx.NullCursor)
self.SetFont(self.normal_font)
event.Skip()
def set_label(self, label):
super(StateLabel, self).SetLabel(label)
label = label.upper()
state_style = self.state_config[label]
if label in [RUNNING,STOPPED,UNKNOWN]:
if 'background' in state_style:
self.SetBackgroundColour(state_style['background'])
if 'foreground' in state_style:
self.SetForegroundColour(state_style['foreground'])