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

« back to all changes in this revision

Viewing changes to backends/kylin-assistant-daemon/src/policykit/dialogs.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/python3
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
### BEGIN LICENSE
 
5
# Copyright (C) 2007-2011 Tualatrix Chou <tualatrix@gmail.com>
 
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 _thread
 
20
 
 
21
from gi.repository import GObject, Gtk, Gdk
 
22
 
 
23
class BaseDialog(Gtk.MessageDialog):
 
24
    def __init__(self, **kwargs):
 
25
        title = kwargs.pop('title', '')
 
26
        message = kwargs.pop('message', '')
 
27
 
 
28
        GObject.GObject.__init__(self, **kwargs)
 
29
 
 
30
        if title:
 
31
            self.set_title(title)
 
32
 
 
33
        if message:
 
34
            self.set_content(message)
 
35
 
 
36
    def set_title(self, title):
 
37
        self.set_markup('<big><b>%s</b></big>' % title)
 
38
 
 
39
    def set_content(self, message):
 
40
        if self.get_property('text'):
 
41
            self.format_secondary_markup(message)
 
42
        else:
 
43
            self.set_markup(message)
 
44
    
 
45
    def launch(self):
 
46
        self.run()
 
47
        self.destroy()
 
48
 
 
49
    def add_option_button(self, button):
 
50
        '''Add an option button to the left. It will not grab the default response.'''
 
51
        vbox = self.get_content_area()
 
52
        hbuttonbox = vbox.get_children()[-1]
 
53
 
 
54
        hbox = Gtk.HBox(spacing=12)
 
55
        vbox.pack_start(hbox, False, False, 0)
 
56
        vbox.remove(hbuttonbox)
 
57
 
 
58
        new_hbuttonbox = Gtk.HButtonBox()
 
59
        new_hbuttonbox.set_layout(Gtk.ButtonBoxStyle.START)
 
60
        new_hbuttonbox.pack_start(button, True, True, 0)
 
61
 
 
62
        hbox.pack_start(new_hbuttonbox, True, True, 0)
 
63
        hbox.pack_start(hbuttonbox, True, True, 0)
 
64
 
 
65
        hbuttonbox.get_children()[-1].grab_focus()
 
66
 
 
67
        vbox.show_all()
 
68
 
 
69
 
 
70
class ErrorDialog(BaseDialog):
 
71
    def __init__(self, title='', message='', parent=None,
 
72
                 type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK):
 
73
        BaseDialog.__init__(self, title=title, message=message,
 
74
                            parent=parent, message_type=type, buttons=buttons)