summaryrefslogtreecommitdiff
path: root/kberylsettings/contentframe.py
blob: 72155b34ecac9ca890913a11222db50e31bc94a9 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" kberylsettings.contentframe -> defines the right side about/setting views.

"""
from os.path import abspath

from qt import Qt, QFrame, QLabel, QHBoxLayout, QScrollView, QVBoxLayout
from kdecore import KIcon, KIconLoader
from kdeui import KStdGuiItem, KPushButton

from kberylsettings.lib import App, Signals, buildPart
from kberylsettings.settingframe import SettingFrame
from kberylsettings.widget import Frame, WidgetStack


class ContentFrame(WidgetStack):
    """ ContentFrame -> stack with About page, Settings Page.

    """
    aboutPageId = 0
    settingsPageId = 1
    
    def __init__(self, parent):
        WidgetStack.__init__(self, parent)
        self.loader = KIconLoader(self.__class__.__name__)
        self.buildAboutPage()
        self.buildSettingsPage()
        self.buildConnections()

    def buildAboutPage(self):
        """ builds the About Plugin page

        @return None
        """
        self.aboutPage = Frame(self, margin=6, spacing=10)
        self.infoHtml = buildPart(self.aboutPage, 'text/html',
                                   "Type == 'Service'", True)
        self.addWidget(self.aboutPage, self.aboutPageId)

    def buildSettingsPage(self):
        """ builds page for displaying one or more settings

        @return None
        """
        self.settingsPage = Frame(self, margin=6, spacing=10)
        self.pluginHeader = QFrame(self.settingsPage)
        self.pluginIconLabel = QLabel(self.pluginHeader)
        self.pluginNameLabel = QLabel(self.pluginHeader)
        layout = QHBoxLayout(self.pluginHeader)        
        layout.addWidget(self.pluginIconLabel)
        layout.addWidget(self.pluginNameLabel, 100)        

        self.settingsMain = QFrame(self)
        self.settingsMain.settingsWidgets = []
        layout = QVBoxLayout(self.settingsMain)
        
        self.settingsScroller = ContentScroll(self.settingsPage, self.settingsMain)
        if not App.debug:
            self.settingsScroller.setFrameShape(Frame.NoFrame)
        self.settingsFooter = QFrame(self.settingsPage)
        layout = QHBoxLayout(self.settingsFooter)
        
        def contentButton(name):
            gui = getattr(KStdGuiItem, name)()
            button = KPushButton(gui.iconSet(), gui.text(), self.settingsFooter)
            layout.addWidget(button)
            return button

        self.helpButton = contentButton('help')
        self.defaultsButton = contentButton('defaults')
        layout.addStretch(100)
        self.applyButton = contentButton('apply')
        self.resetButton = contentButton('reset')
        self.addWidget(self.settingsPage, self.settingsPageId)

    def buildConnections(self):
        """ build the connections for this instance

        @return None
        """
        self.connect(self.helpButton, Signals.clicked, self.settingHelp)
        self.connect(self.defaultsButton, Signals.clicked, self.settingDefaults)
        self.connect(self.applyButton, Signals.clicked, self.settingApply)        

    def showAbout(self, plugin):
        """ displays the About Plugin page with information from the plugin

        @param plugin berylsettings Plugin instance
        @return None
        """
        logofile = 'file://%s' % (abspath(App.basedir + '/html/beryl-manager.png'), )
        htmlsrc = open(abspath(App.basedir + '/html/plugin.html')).read()        
        if plugin is None:
            pluginname = 'Beryl Settings'
            plugindesc = 'Beryl Settings - Get Your Effects On!'
        else:
            pluginname = plugin.ShortDesc
            plugindesc = plugin.LongDesc
        self.infoHtml.begin()
        self.infoHtml.write(htmlsrc % locals())
        self.infoHtml.end()
        self.raiseWidget(self.aboutPageId)
        
    def showSettings(self, plugin, arg):
        """ displays the settings page with individual setting frames

        @param plugin berylsettings Plugin instance
        @param arg setting name or setting section name
        @return None
        """
        self.settingsMain.hide()
        for widget in self.settingsMain.settingsWidgets:
            widget.close()
        layout = self.settingsMain.layout()
        layout.deleteAllItems()
        if arg in plugin.settings:
            settings = plugin.settings[arg]
            extra = ' - %s' % (arg, )
        else:
            settings = [arg, ]
            extra = ''
        ico = plugin.icon(KIcon.SizeLarge, self.loader)
        self.pluginIconLabel.setPixmap(ico)
        self.pluginNameLabel.setText('<b>%s%s</b>' % (plugin.ShortDesc, extra))
        for setting in settings:
            frame = SettingFrame(self.settingsMain, setting)
            self.settingsMain.settingsWidgets.append(frame)
            layout.addWidget(frame, 0, Qt.AlignTop)
            frame.show()
        layout.addStretch(100)
        self.settingsMain.show()        
        self.raiseWidget(self.settingsPageId)

    def settingHelp(self):
        """ not implemented

        """

    def settingDefaults(self):
        """ not implemented

        """

    def settingApply(self):
        """ not implemented

        """


class ContentScroll(QScrollView):
    """ ContentScroll -> a scroll view fitted to a single child

    """
    def __init__(self, parent, child):
        QScrollView.__init__(self, parent)
        self.addChild(child)
        self.setResizePolicy(QScrollView.AutoOneFit)