1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Provides a framework for a graphical user interface to YASMon,
20 using Qt4.
21
22 """
23
24
25 from PyQt4.QtCore import *
26 from PyQt4.QtGui import *
27 from PyQt4 import QtSvg
28
29 import re,sys,sysmon,traceback
30
32 """Displays the appropriate error message, based on the given
33 error object.
34 """
35
36 em=QErrorMessage()
37 tb=traceback.format_exc()
38 tb=re.sub(" "," ",tb)
39 em.showMessage(
40 "<html><p>%s</p><p><b>Backtrace:</b></p>%s</html>"
41 % (error,re.sub("\n","<br />",tb)))
42 em.exec_()
43
45 """Displays an "About YASMon" dialog box.
46 """
47 dialog=AboutYasmon(parent)
48 dialog.exec_()
49
51 """Returns a scalable version of YASMon's icon.
52 """
53 return QIcon("/usr/share/icons/hicolor/scalable/apps/yasmon.svg")
54
56 """Returns an QSvgWidget with YASMon's logo
57 """
58 i=QtSvg.QSvgWidget("/usr/share/icons/hicolor/scalable/apps/yasmon.svg")
59 i.setMaximumSize(i.sizeHint())
60 i.setMinimumSize(i.sizeHint())
61 return i
62
64 """Returns a scalable version of QT's logo.
65 """
66 return QIcon()
67
69 """YASMon's about dialog box.
70 """
72 super(AboutYasmon, self).__init__(parent)
73 self.setWindowTitle("About YASMon")
74 overlayout=QVBoxLayout()
75 layout=QHBoxLayout()
76 layout.addWidget(yasmon_image())
77 sublayout=QVBoxLayout()
78 sublayout.addWidget(QLabel("<html><b>"+
79 "Yet Another System Monitor</b></html>"))
80 sublayout.addWidget(QLabel("<html><p>Version %s</p>" % sysmon.version()
81 +"<p>© 2010 Scott Lawrence "
82 +"<<a href='mailto:bytbox@gmail.com'>"
83 +"bytbox@gmail.com</a>></p>"
84 +"<p>Licensed under the GNU GPL version 3 "
85 +"or, at your <br />choice, any later "
86 +"version.</p></html>"))
87 layout.addLayout(sublayout)
88 overlayout.addLayout(layout)
89 bb=QDialogButtonBox(QDialogButtonBox.Ok,Qt.Horizontal,self)
90 bb.setCenterButtons(True)
91 bb.accepted.connect(self.accept)
92 overlayout.addWidget(bb)
93 self.setLayout(overlayout)
94
95
97 """A widget to view information on a scale, with details
98 below.
99
100 """
101 - def __init__(self,name,min=0,max=100,unit='%',default=0):
102 QWidget.__init__(self)
103 self.name=name
104 self.min=min
105 self.max=max
106 self._value=default
107 self.unit=unit
108 self.setToolTip("%d/%d %s" % (int(self.value()),int(max),unit))
109 self.setMaximumSize(QSize(70,100))
110 self.setMinimumSize(QSize(70,100))
111
113 """Returns the current value.
114 """
115 return self._value
116
118 """Sets the maximum value.
119 """
120 self.max=maxval
122 """Sets the minimum value.
123 """
124 self.min=minval
125
127 """Sets the value to be displayed.
128
129 This method sets the value stored in the object and
130 updates the onscreen representation.
131 """
132 self._value=value
133 self.setToolTip("%d/%d %s" % (int(self.value()),int(self.max),self.unit))
134 self.update()
135
137
138 painter=QPainter(self)
139 painter.setPen(QPen())
140 painter.setBrush(QBrush())
141
142
143 painter.drawRect(QRect(7,0,56,64))
144 height=(float(self.value())-self.min)*64.0/self.max
145 painter.fillRect(QRect(7,64,56,-height),QColor.fromRgb(height*3.9,0,0))
146
147 painter.drawText(QRect(0,0,70,100),
148 Qt.AlignHCenter | Qt.AlignBottom,
149 self.name+"\n"+str(float(int((self.value()-self.min)*1000.0/self.max))/10)+'%')
150
151
154
155
156
158 """A widget to view cpu usage information et al. for a single
159 CPU.
160
161 This consists of a simple graphic, with a single vertical
162 "progress bar" (labelled as appropriate) and two numbers
163 below: the exact percentage usage and the current temperature,
164 if available.
165
166 Although this view is meant for a single CPU, it may actually
167 represent multiple CPUs, depending on the implementation of
168 the backend object.
169 """
176
180
181
183 """A widget to view processor information for multiple
184 processors.
185
186 This will normally be significantly wider than it is tall, as
187 it consists simply of a horizontal row of CPUViews.
188 """
190 QWidget.__init__(self)
191 layout=QHBoxLayout()
192 layout.setMargin(0)
193 self.setLayout(layout)
194
195 for processor in processorlist:
196 layout.addWidget(CPUView(processor))
197
199 """A widget to display the current memory usage in a memory
200 bank (RAM).
201
202 """
207
211
213 """A widget to display the current system uptime.
214 """
220
222 uptime=int(self.uptime.uptime())
223 days=uptime/(60*60*24)
224 hours=(uptime/(60*60))%24
225 mins=((uptime/60)%60)
226 secs=uptime%60
227 self.setText("Up %d days, %02d:%02d:%02d" % (days,hours,mins,secs))
228
231
233 """Displays current information for the most general (and
234 critical) parts of a single system.
235
236 This generally means the processors, memory, and hard disk
237 usage.
238 """
250
251 -class HistoryView(QFrame):
252 """Displays most of OverviewView's content, as a history.
253
254 This view consists of a set of a few graphs, each containing in
255 somewhat condensed for the history of some measure of
256 performance. In general, single pixel is used for every related
257 update fired.
258 """
259 - def __init__(self,system):
260 QFrame.__init__(self)
261
263 """Displays a top-like view of a system.
264 """
267
269 """Displays a detailed system view, consisting of a HistoryView
270 and a TopView.
271 """
274
275 -class MainView(QWidget):
276 - def __init__(self,systems):
277 QWidget.__init__(self)
278 layout=QVBoxLayout()
279 sublayout=QHBoxLayout()
280 self.setLayout(layout)
281 tabWidget=QTabWidget()
282 tabWidget.setTabPosition(QTabWidget.South)
283 for system in systems:
284 tabid=tabWidget.addTab(DetailedSystemView(systems[system]),QString(system))
285 tabWidget.setTabToolTip(tabid,QString("View information for %s" % system))
286
287 sublayout.addWidget(SystemView(systems[system]))
288 layout.addLayout(sublayout)
289 layout.addWidget(tabWidget)
290