~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to backends/youker-assistant-daemon/src/beautify/unity.py

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
 
### BEGIN LICENSE
4
 
 
5
 
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
6
 
# This program is free software: you can redistribute it and/or modify it
7
 
# under the terms of the GNU General Public License version 3, as published
8
 
# by the Free Software Foundation.
9
 
#
10
 
# This program is distributed in the hope that it will be useful, but
11
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
 
# PURPOSE.  See the GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along
16
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
### END LICENSE
18
 
 
19
 
import os
20
 
import gsettings
21
 
from compizsettings import CompizSetting
22
 
 
23
 
class Unity:
24
 
    '''if compiz: key is icon_size; else if gsettins: key is icon-size'''
25
 
    desktop = None
26
 
 
27
 
    def __init__(self):
28
 
        self.desktop = os.getenv('XDG_CURRENT_DESKTOP')
29
 
        if self.desktop is None:
30
 
             self.desktop = os.getenv('XDG_SESSION_DESKTOP')
31
 
    #    self.setting = CompizSetting("%s.%s" % (name, key))
32
 
 
33
 
    # ---------------launcher---------------
34
 
    # -----------------默认值-----------------
35
 
    # Get Default Value
36
 
    def get_default_schema_value(self, name, key):
37
 
        compizsetting = CompizSetting("%s.%s" % (name, key))
38
 
        return compizsetting.get_schema_value()
39
 
 
40
 
    # Set Default Value  min=32, max=64, step=16, key="unityshell.icon_size"
41
 
    #def set_default_schema_value(self, key, name, type, value):
42
 
    def set_default_schema_value(self, key, type, value):
43
 
        #default_value = self.get_default_schema_value(name, key)
44
 
        #if default_value is not None:
45
 
        return gsettings.set('org.compiz.unityshell',
46
 
                            '/org/compiz/profiles/unity/plugins/unityshell/',
47
 
                            key, type, value)
48
 
        #else:
49
 
        #    raise NotImplemented
50
 
 
51
 
    # launcher auto hide mode, True/False
52
 
    def set_launcher_autohide(self, flag):
53
 
        return gsettings.set('org.compiz.unityshell',
54
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
55
 
            'launcher-hide-mode',
56
 
            'int', flag)
57
 
 
58
 
    # get launcher auto hide mode
59
 
    def get_launcher_autohide(self):
60
 
        try:
61
 
            value = gsettings.get('org.compiz.unityshell',
62
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
63
 
                'launcher-hide-mode', 'int')
64
 
            if value == 0:
65
 
                return False
66
 
            elif value == 1:
67
 
                return True
68
 
            else:
69
 
                return None
70
 
        except Exception, e:
71
 
            return False
72
 
 
73
 
    # launcher icon size 32-64
74
 
    def set_launcher_icon_size(self, size):
75
 
        return gsettings.set('org.compiz.unityshell',
76
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
77
 
            'icon-size',
78
 
            'int', size)
79
 
 
80
 
    # get launcher icon size
81
 
    def get_launcher_icon_size(self):
82
 
        try:
83
 
            return gsettings.get('org.compiz.unityshell',
84
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
85
 
                'icon-size', 'int')
86
 
        except Exception, e:
87
 
            return 0
88
 
 
89
 
    # launcher 'show desktop' icon True/False
90
 
    def set_launcher_have_showdesktopicon(self, flag):
91
 
        launcher = gsettings.get_schema('com.canonical.Unity.Launcher')
92
 
        icons = launcher.get_strv('favorites')
93
 
        desktop = 'unity://desktop-icon'
94
 
        if flag == True:
95
 
            if desktop not in icons:
96
 
                icons.append(desktop)
97
 
                launcher.set_strv('favorites', icons)
98
 
        else:
99
 
            if desktop in icons:
100
 
                icons.remove(desktop)
101
 
                launcher.set_strv('favorites', icons)
102
 
 
103
 
    # get is launcher have 'show desktop' icon
104
 
    def get_launcher_have_showdesktopicon(self):
105
 
        launcher = gsettings.get_schema('com.canonical.Unity.Launcher')
106
 
        icons = launcher.get_strv('favorites')
107
 
        desktop = 'unity://desktop-icon'
108
 
        if desktop in icons:
109
 
            return True
110
 
        else:
111
 
            return False
112
 
 
113
 
    def get_default_launcher_have_showdesktopicon(self):
114
 
        return self.get_launcher_have_showdesktopicon()
115
 
 
116
 
    def set_default_launcher_have_showdesktopicon(self):
117
 
        self.set_launcher_have_showdesktopicon(True)
118
 
 
119
 
 
120
 
 
121
 
    #add by kobe
122
 
    # 透明度
123
 
    def get_launcher_transparency(self):
124
 
        try:
125
 
            return gsettings.get('org.compiz.unityshell',
126
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
127
 
                'launcher-opacity', 'double')
128
 
        except Exception, e:
129
 
            return 0.0
130
 
 
131
 
    # 'min'    : 0.2, # TODO : Check these min max. Most prolly wrong.
132
 
    # 'max'    : 1.0, # But fine since they are ignored anyway.
133
 
    # 'ticks'  : [(0.666, Gtk.PositionType.BOTTOM, None)]
134
 
    def set_launcher_transparency(self, opacity):
135
 
        return gsettings.set('org.compiz.unityshell',
136
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
137
 
            'launcher-opacity',
138
 
            'double', opacity)
139
 
 
140
 
    # 图标背景
141
 
    def get_all_launcher_icon_colourings(self):
142
 
#        return ['0:0', '1:1', '2:2', '3:3', '4:4']
143
 
        return ['all programs', 'only run app', 'no coloring', 'edge coloring', 'each workspace alternating coloring']
144
 
 
145
 
    def get_launcher_icon_colouring(self):
146
 
        try:
147
 
            return gsettings.get('org.compiz.unityshell',
148
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
149
 
                'backlight-mode', 'int')
150
 
        except Exception, e:
151
 
            return 0
152
 
 
153
 
    # 'map'       : {0:0,1:1,2:2,3:3,4:4}  0:所有程序,1:仅打开的应用程序,2:不着色,3:边缘着色,4:每个工作区交替着色
154
 
    def set_launcher_icon_colouring(self, colouring):
155
 
        return gsettings.set('org.compiz.unityshell',
156
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
157
 
            'backlight-mode',
158
 
            'int', colouring)
159
 
 
160
 
    def get_all_launcher_position(self):
161
 
        return ['Left', 'Bottom']
162
 
 
163
 
    def get_current_launcher_position(self):
164
 
        return gsettings.get('com.canonical.Unity.Launcher',
165
 
            None,
166
 
            'launcher-position',
167
 
            'string')
168
 
 
169
 
    def set_launcher_position(self, position):
170
 
        return gsettings.set('com.canonical.Unity.Launcher',
171
 
            None,
172
 
            'launcher-position',
173
 
            'string', position)
174
 
 
175
 
    #Dash背景模糊类型
176
 
    def get_dash_blur_experimental(self):
177
 
        try:
178
 
            return gsettings.get('org.compiz.unityshell',
179
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
180
 
                'dash-blur-experimental', 'int')
181
 
        except Exception, e:
182
 
            return 0
183
 
 
184
 
    # 活动模糊smart: 2   静态模糊static:1   非模糊0
185
 
    def set_dash_blur_experimental(self, blur):
186
 
        return gsettings.set('org.compiz.unityshell',
187
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
188
 
            'dash-blur-experimental',
189
 
            'int', blur)
190
 
 
191
 
    #面板菜单透明度
192
 
    def get_panel_transparency(self):
193
 
        try:
194
 
            return gsettings.get('org.compiz.unityshell',
195
 
                '/org/compiz/profiles/unity/plugins/unityshell/',
196
 
                'panel-opacity', 'double')
197
 
        except Exception, e:
198
 
            return 0.0
199
 
 
200
 
    # 'min'    : 0.2, # TODO : Check these min max. Most prolly wrong.
201
 
    # 'max'    : 8.0, # But fine since they are ignored anyway.
202
 
    # 'ticks'  : [(0.666, Gtk.PositionType.BOTTOM, None)]
203
 
    def set_panel_transparency(self, opacity):
204
 
        return gsettings.set('org.compiz.unityshell',
205
 
            '/org/compiz/profiles/unity/plugins/unityshell/',
206
 
            'panel-opacity',
207
 
            'double', opacity)
208
 
 
209
 
    #日期时间格式
210
 
    def get_all_time_format(self):
211
 
        return ['locale-default', '12-hour' , '24-hour', 'custom']
212
 
 
213
 
    def get_time_format(self):
214
 
#        if self.desktop == "mate":
215
 
#            return gsettings.get('org.mate.panel',
216
 
#                '/org/mate/panel/objects/clock/prefs/',
217
 
#                'format',
218
 
#                'string')
219
 
#        else:
220
 
        return gsettings.get('com.canonical.indicator.datetime',
221
 
            None,
222
 
            'time-format',
223
 
            'string')
224
 
 
225
 
    def set_time_format(self, format):
226
 
#        if self.desktop == "mate":
227
 
#            return gsettings.set('org.mate.panel',
228
 
#                '/org/mate/panel/objects/clock/prefs/',
229
 
#                'format',
230
 
#                'string', format)
231
 
#        else:
232
 
        return gsettings.set('com.canonical.indicator.datetime',
233
 
            None,
234
 
            'time-format',
235
 
            'string', format)
236
 
    # 秒
237
 
    def get_show_seconds(self):
238
 
        return gsettings.get('com.canonical.indicator.datetime',
239
 
            None,
240
 
            'show-seconds',
241
 
            'boolean')
242
 
 
243
 
    def set_show_seconds(self, flag):
244
 
        return gsettings.set('com.canonical.indicator.datetime',
245
 
            None,
246
 
            'show-seconds',
247
 
            'boolean', flag)
248
 
 
249
 
    #星期
250
 
    def get_show_week(self):
251
 
        return gsettings.get('com.canonical.indicator.datetime',
252
 
            None,
253
 
            'show-day',
254
 
            'boolean')
255
 
 
256
 
    def set_show_week(self, flag):
257
 
        return gsettings.set('com.canonical.indicator.datetime',
258
 
            None,
259
 
            'show-day',
260
 
            'boolean', flag)
261
 
 
262
 
    #日期
263
 
    def get_show_date(self):
264
 
        return gsettings.get('com.canonical.indicator.datetime',
265
 
            None,
266
 
            'show-date',
267
 
            'boolean')
268
 
 
269
 
    def set_show_date(self, flag):
270
 
        return gsettings.set('com.canonical.indicator.datetime',
271
 
            None,
272
 
            'show-date',
273
 
            'boolean', flag)
274
 
 
275
 
    # 电源
276
 
    # present:电源总是可见     charge:当机器充电/放电时可见         never:总是不可见
277
 
    def get_all_power_icon_policy(self):
278
 
        return ['present', 'charge', 'never']
279
 
 
280
 
    def get_power_icon_policy(self):
281
 
        return gsettings.get('com.canonical.indicator.power',
282
 
            None,
283
 
            'icon-policy',
284
 
            'string')
285
 
 
286
 
    def set_power_icon_policy(self, flag):
287
 
        return gsettings.set('com.canonical.indicator.power',
288
 
            None,
289
 
            'icon-policy',
290
 
            'string', flag)
291
 
 
292
 
    #电源时间
293
 
    def get_show_power_time(self):
294
 
        return gsettings.get('com.canonical.indicator.power',
295
 
            None,
296
 
            'show-time',
297
 
            'boolean')
298
 
 
299
 
    def set_show_power_time(self, flag):
300
 
        return gsettings.set('com.canonical.indicator.power',
301
 
            None,
302
 
            'show-time',
303
 
            'boolean', flag)
304
 
 
305
 
    #电源百分比
306
 
    def get_show_power_percentage(self):
307
 
        return gsettings.get('com.canonical.indicator.power',
308
 
            None,
309
 
            'show-percentage',
310
 
            'boolean')
311
 
 
312
 
    def set_show_power_percentage(self, flag):
313
 
        return gsettings.set('com.canonical.indicator.power',
314
 
            None,
315
 
            'show-percentage',
316
 
            'boolean', flag)
317
 
 
318
 
    #-----------------mate----------------------------
319
 
    def set_mate_panel_icon_size(self, position, size):
320
 
        if position == "top":
321
 
            return gsettings.set('org.mate.panel.toplevel',
322
 
                '/org/mate/panel/toplevels/top/',
323
 
                'size',
324
 
                'int', size)
325
 
        elif position == "bottom":
326
 
            return gsettings.set('org.mate.panel.toplevel',
327
 
                '/org/mate/panel/toplevels/bottom/',
328
 
                'size',
329
 
                'int', size)
330
 
        else:
331
 
            return False
332
 
 
333
 
    # get launcher icon size
334
 
    def get_mate_panel_icon_size(self, position):
335
 
        if position == "top":
336
 
            return gsettings.get('org.mate.panel.toplevel',
337
 
                '/org/mate/panel/toplevels/top/',
338
 
                'size', 'int')
339
 
        elif position == "bottom":
340
 
            return gsettings.get('org.mate.panel.toplevel',
341
 
                '/org/mate/panel/toplevels/bottom/',
342
 
                'size', 'int')
343
 
        else:
344
 
            return False
345
 
 
346
 
    def set_mate_panel_autohide(self, position, flag):
347
 
        if position == "top":
348
 
            return gsettings.set('org.mate.panel.toplevel',
349
 
                '/org/mate/panel/toplevels/top/',
350
 
                'auto-hide',
351
 
                'boolean', flag)
352
 
        elif position == "bottom":
353
 
            return gsettings.set('org.mate.panel.toplevel',
354
 
                '/org/mate/panel/toplevels/bottom/',
355
 
                'auto-hide',
356
 
                'boolean', flag)
357
 
        else:
358
 
            return False
359
 
 
360
 
    def get_mate_panel_autohide(self, position):
361
 
        if position == "top":
362
 
            return gsettings.get('org.mate.panel.toplevel',
363
 
                '/org/mate/panel/toplevels/top/',
364
 
                'auto-hide', 'boolean')
365
 
        elif position == "bottom":
366
 
            return gsettings.get('org.mate.panel.toplevel',
367
 
                '/org/mate/panel/toplevels/bottom/',
368
 
                'auto-hide', 'boolean')
369
 
        else:
370
 
            return False
371
 
 
372
 
    def get_show_apps(self):
373
 
        return gsettings.get('org.mate.panel.menubar',
374
 
            None,
375
 
            'show-applications',
376
 
            'boolean')
377
 
 
378
 
    def set_show_apps(self, flag):
379
 
        return gsettings.set('org.mate.panel.menubar',
380
 
            None,
381
 
            'show-applications',
382
 
            'boolean', flag)
383
 
 
384
 
    def get_show_desktop(self):
385
 
        return gsettings.get('org.mate.panel.menubar',
386
 
            None,
387
 
            'show-desktop',
388
 
            'boolean')
389
 
 
390
 
    def set_show_desktop(self, flag):
391
 
        return gsettings.set('org.mate.panel.menubar',
392
 
            None,
393
 
            'show-desktop',
394
 
            'boolean', flag)
395
 
 
396
 
    def get_show_icon(self):
397
 
        return gsettings.get('org.mate.panel.menubar',
398
 
            None,
399
 
            'show-icon',
400
 
            'boolean')
401
 
 
402
 
    def set_show_icon(self, flag):
403
 
        return gsettings.set('org.mate.panel.menubar',
404
 
            None,
405
 
            'show-icon',
406
 
            'boolean', flag)
407
 
 
408
 
    def get_show_places(self):
409
 
        return gsettings.get('org.mate.panel.menubar',
410
 
            None,
411
 
            'show-places',
412
 
            'boolean')
413
 
 
414
 
    def set_show_places(self, flag):
415
 
        return gsettings.set('org.mate.panel.menubar',
416
 
            None,
417
 
            'show-places',
418
 
            'boolean', flag)
419
 
 
420
 
if __name__ == '__main__':
421
 
    uuu = Unity()
422
 
#    print uuu.get_launcher_icon_colouring()
423
 
#    print uuu.set_launcher_icon_colouring(1)
424
 
    print uuu.get_time_format()
425
 
#    bb = uuu.get_default_schema_value("unityshell", "icon_size")
426
 
#    aa = uuu.get_default_schema_value("unityshell", "launcher_hide_mode")
427
 
    #aa = uuu.get_default_schema_value('org.gnome.desktop.media-handling', 'automount')
428
 
    #uuu = Unity("unityshell", "icon_size")
429
 
    #aa = uuu.get_launcher_icon_size_test()
430
 
    #print "bb->"
431
 
    #print bb
432
 
    #print "aa->"
433
 
    #print aa
434
 
    #uuu.set_default_schema_value('icon-size', 'int', bb)
435
 
#    cc = uuu.get_default_launcher_have_showdesktopicon()
436
 
#    print cc
437
 
 
438
 
    #uuu.set_default_schema_value('launcher-hide-mode', 'int', aa)
439
 
 
440
 
    #bb = uuu.get_default_launcher_icon_size()
441
 
    #print "bb->"
442
 
    #print bb
443
 
    #print(type(bb))
444
 
    #uuu.reset_default_launcher_icon_size(bb)
445
 
    #uuu.set_launcher_icon_size(48)
446
 
    # print uuu.get_launcher_icon_size()
447
 
    # print uuu.get_launcher_have_showdesktopicon()
448
 
    # uuu.set_launcher_autohide(0)
449
 
    # print uuu.get_launcher_autohide()
450
 
    # uuu.set_launcher_have_showdesktopicon(True)
451
 
    # uuu.set_launcher_icon_size(48)