Gnome SHELL Generic Monitor

Gnome SHELL Generic Monitor Commit Details

Date:2020-05-05 09:56:59 (6 months 24 days ago)
Author:Grégory Soutadé
Branch:master
Commit:f536c89e369ca8235172faaab898eead2820bc1e
Parents: 506660f1da376e9ab0bd40819fe267f0906f4085
Message:Add box property management Widgets can be put in left, center or right box. Warning: right box is available (no error), but seems undefined (Gnome Shell 3.36)...

Changes:
Mexamples/dbusitem.py (1 diff)
Mexamples/timer.py (1 diff)
Mextension.js (8 diffs)

File differences

examples/dbusitem.py
11
22
3
3
44
55
66
77
88
99
10
10
11
1112
1213
1314
1415
1516
17
18
1619
1720
1821
19
22
2023
2124
2225
class DBUSItem:
def __init__(self, name, text='', style='', icon='', iconStyle='', onClick=''):
def __init__(self, name, text='', style='', icon='', iconStyle='', onClick='', box=''):
self.name = name
self.text = text
self.style= style
self.icon = icon
self.iconStyle = iconStyle
self.onClick = onClick
self.box = box
self._checkValues()
def _checkValues(self):
if self.onClick and not self.onClick in ('signal', 'delete'):
raise ValueError('Invalid onClick value')
if self.box and not self.box in ('left', 'center', 'right'):
raise ValueError('Invalid box value')
def toMap(self):
myMap = {"name":self.name}
for p in ('text', 'style', 'icon'):
for p in ('text', 'style', 'icon', 'box'):
if self.__dict__[p]:
myMap[p] = self.__dict__[p]
if self.iconStyle:
examples/timer.py
4545
4646
4747
48
48
4949
5050
5151
def _displayTimerValue(self):
encoder = json.JSONEncoder()
res = {'group':'Timer', 'items':[]}
item = DBUSItem('timer', onClick='signal')
item = DBUSItem('timer', onClick='signal', box='right')
curValue = self.timers[self.curTimer]
item.text = '%02d:%02d' % (int(curValue/60)%60, curValue%60)
if curValue >= (60*60):
extension.js
2727
2828
2929
30
30
3131
3232
3333
3434
3535
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
3657
3758
3859
......
5677
5778
5879
59
60
61
80
81
82
83
84
85
86
87
88
89
6290
63
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
64120
121
122
123
124
65125
66126
67127
68128
69
129
70130
131
132
133
134
135
71136
72
137
73138
74139
75140
141
142
143
76144
77145
78146
......
107175
108176
109177
110
111178
112179
113180
......
129196
130197
131198
199
200
201
202
132203
133204
134205
......
239310
240311
241312
242
313
314
315
316
243317
244318
245319
246320
247321
248
249322
250323
324
251325
252
253
254
255
256
257
258
259326
260327
261328
......
271338
272339
273340
274
275
276
277341
278
279
280
281
282
283
284
285
286
287
288342
289343
290344
291345
292
293
294
295
296
297
298
299346
300347
301
348
302349
303350
304351
......
342389
343390
344391
345
392
346393
347394
348395
......
355402
356403
357404
358
405
359406
360407
361408
const clutter = imports.gi.Clutter;
class MonitorWidget {
constructor(name, group, text, style, icon, iconStyle, onClick) {
constructor(name, group, text, style, icon, iconStyle, onClick, box, lastWidget) {
this.name = name;
this.group = group;
this._createIcon(icon, iconStyle);
this._createText(text, style);
this.onClick = onClick;
switch(box) {
case 'left':
this.box = Main.panel._leftBox;
break;
case 'right':
this.box = Main.panel._rigthBox;
break;
default:
case 'center':
this.box = Main.panel._centerBox;
break;
}
// Don't know why, _rightBox seems undefined on shell 3.36 !!
if (this.box === undefined) {
log(`${box} is undefined, falling back to centerBox`);
this.box = Main.panel._centerBox;
}
this._addToBox(lastWidget);
}
_createText(text, style) {
}
}
update(text, style, icon, iconStyle) {
if (!this.widget) {
this._createText(text, style);
_addToBox(lastWidget) {
// lastWidget => NULL, insert at the end
// Add to box
if (this.box !== Main.panel._rigthBox || lastWidget) {
if (this.icon) {
this.box.insert_child_above(this.icon, lastWidget);
lastWidget = this.icon;
}
if (this.widget)
this.box.insert_child_above(this.widget, lastWidget);
} else {
if (text !== '')
if (this.icon) {
this.box.insert_child_at_index(this.icon, 0);
lastWidget = this.icon;
}
if (this.widget) {
if (lastWidget)
this.box.insert_child_above(this.widget, lastWidget);
else
this.box.insert_child_at_index(this.icon, 0);
}
}
}
removeFromBox() {
if (this.widget)
this.box.remove_child(this.widget);
if (this.icon)
this.box.remove_child(this.icon);
}
update(text, style, icon, iconStyle) {
let prevWidget = this.widget;
let prevIcon = this.icon;
if (text !== '') {
if (!this.widget) {
this._createText(text, style);
this.box.insert_child_above(this.widget, this.icon);
} else {
this.widget.label = text;
}
}
if (style !== '' && this.widget) {
this.style = style;
this.widget.set_style(this.style);
}
if (icon !== '')
if (icon !== '') {
this._createIcon(icon, iconStyle);
if (prevIcon)
this.box.insert_child_above(this.icon, prevIcon);
else
this.box.insert_child_before(this.icon, prevWidget);
}
if (icon === '' && iconStyle !== '' && this.icon) {
if (iconStyle !== '' && this.icon) {
this.iconStyle = style;
this.icon.set_style(this.iconStyle);
}
if (prevIcon && icon !== '')
this.box.remove_child(prevIcon);
}
}
this.monitor_groups = {};
this.actor_clicked = {};
this.clutterSettings = clutter.Settings.get_default();
this.box = Main.panel._centerBox;
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
}
if (item['on-click'] !== 'signal' && item['on-click'] !== 'delete')
throw new Error('Invalid on-click value');
}
if (item.hasOwnProperty('box')) {
if (item['box'] !== 'left' && item['box'] !== 'center' && item['box'] !== 'right')
throw new Error('Invalid box value');
}
}
}
let onClick = '';
if (item.hasOwnProperty('on-click'))
onClick = item['on-click'];
let box = 'center';
if (item.hasOwnProperty('box'))
box = item['box'];
let monitorWidget = this._getItemFromGroup(group, item['name']);
let lastWidget = null;
// New widget
if (monitorWidget === null) {
monitorWidget = new MonitorWidget(item['name'], groupName, text, style, icon, iconStyle, onClick);
if (group.length)
lastWidget = group[group.length - 1].widget;
monitorWidget = new MonitorWidget(item['name'], groupName, text, style, icon, iconStyle, onClick, box, lastWidget);
group.push(monitorWidget);
// lastWidget => NULL, insert at the end
if (monitorWidget.icon) {
this.box.insert_child_above(monitorWidget.icon, lastWidget);
lastWidget = monitorWidget.icon;
}
if (monitorWidget.widget)
this.box.insert_child_above(monitorWidget.widget, lastWidget);
// Connect signals
if (onClick !== '') {
if (monitorWidget.widget)
}
}
} else {
let prevWidget = monitorWidget.widget;
let prevIcon = monitorWidget.icon;
monitorWidget.update(text, style, icon, iconStyle);
if (monitorWidget.icon) {
if (prevIcon)
this.box.remove_child(prevIcon);
this.box.insert_child_above(monitorWidget.icon, lastWidget);
lastWidget = monitorWidget.icon;
}
if (!prevWidget && monitorWidget.widget)
this.box.insert_child_above(monitorWidget.widget, lastWidget);
}
}
}
_removeItemFromBox(item) {
if (item.widget)
this.box.remove_child(item.widget);
if (item.icon)
this.box.remove_child(item.icon);
}
deleteItem(item, groupName) {
let group = this.monitor_groups[groupName];
this._removeItemFromBox(item);
item.removeFromBox();
group = this._removeFromArray(group, item);
if (group.length === 0)
delete this.monitor_groups[groupName];
continue;
let group = this.monitor_groups[groupName];
for (let itemIndex in group)
this._removeItemFromBox(group[itemIndex]);
group[itemIndex].removeFromBox();
groupsToDelete.push(groupName);
}
for (let groupDeleteIndex in groupsToDelete) {
for (let groupIndex in this.monitor_groups) {
let group = this.monitor_groups[groupIndex];
for (let itemIndex in group)
this._removeItemFromBox(group[itemIndex]);
group[itemIndex].removeFromBox();
}
this.monitor_groups = {};
this._dbusImpl.unexport();

Archive Download the corresponding diff file

Branches

Tags