summaryrefslogtreecommitdiffstats
path: root/DesktopEffects/DesktopEffectsKDE4.py
blob: 28648b0ff7f120edca58ab323effe646f87f9a5b (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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of 
# the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2007-2008 Martin Böhm <martin.bohm@kubuntu.org>
# Copyright 2007-2008 Michael Anderson <nosrednaekim@gmail.com>

import sys
import os
from optparse import OptionParser
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *

from DesktopEffectsQt4Dialog import Ui_Dialog
from DesktopEffectsCommon import DesktopEffectsCommon
import gettext

def _(str):
    ''' the traditional gettext function '''
    return unicode(gettext.gettext(str), 'UTF-8')

def __(catalog,str):
    ''' selects a different catalog for the str translation;
        useful when you want to use the standard KDE labels. '''
    return unicode(gettext.dgettext(catalog, str), 'UTF-8')

def utf8(str):
  if isinstance(str, unicode):
      return str
  return unicode(str, 'UTF-8')

class DesktopEffectsKDE4(DesktopEffectsCommon):
    def __init__(self):
        '''launches the app, draws the window '''
        # needed for all Qt actions 
        app = QApplication (sys.argv)

        # Qt4 explanations:
        # self.qd is the link to the main QDialog (what you can see)
        # self.ui is its UI (the UI defined in Qt-Designer
        self.qd = QDialog()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self.qd)

        localesApp="desktop-effects-tde"
        localesDir="/opt/trinity/share/locale"
        gettext.bindtextdomain(localesApp, localesDir)
        gettext.textdomain(localesApp)

        # the Common class triggers some UI text settings, so we need to 
        # init the UI first
        DesktopEffectsCommon.__init__(self)
	   
        self.radioGroup = QButtonGroup(self.qd)
        self.radioGroup.setExclusive(True)
        self.radioGroup.addButton(self.ui.noEffectsButton)
        self.radioGroup.addButton(self.ui.stdEffectsButton)
        self.radioGroup.addButton(self.ui.extraEffectsButton)
        self.radioGroup.addButton(self.ui.customEffectsButton)
	   
        # connect signals and slots -- we have to do it ourselves in Qt4
        QObject.connect(self.ui.installButton, SIGNAL("clicked()"), self.btnInstallClicked)
        QObject.connect(self.ui.done, SIGNAL("clicked()"), self.done)
        QObject.connect(self.ui.apply, SIGNAL("clicked()"), self.apply)	   
        # connect radio buttons - methods provided by the Common class
        QObject.connect(self.ui.noEffectsButton,     SIGNAL("clicked()"), self.noEffects)
        QObject.connect(self.ui.stdEffectsButton,    SIGNAL("clicked()"), self.standardEffects)
        QObject.connect(self.ui.extraEffectsButton,  SIGNAL("clicked()"), self.extraEffects)
        QObject.connect(self.ui.customEffectsButton, SIGNAL("clicked()"), self.customEffects)

        self.ui.installButton.setText(_("Install"))
        self.ui.warningText.setText(_("Desktop Effects are a great way to enjoy a modern desktop experience without transitioning to KDE4"))
        self.ui.groupBox.setTitle(_("Effects Level"))
        self.ui.noEffectsButton.setText(_("No Effects"))
        self.ui.label_6.setText(_("All effects are disabled and KDE Window manager is used. This is the default behaviour."))
        self.ui.stdEffectsButton.setText(_("Standard Effects"))
        self.ui.label_12.setText(_("Some simple effects."))
        self.ui.extraEffectsButton.setText(_("Extra Effects"))
        self.ui.label_14.setText(_("You\'ll need sunglasses"))
        self.ui.customEffectsButton.setText(_("Custom Effects"))
        self.ui.label_16.setText(_("Use custom settings from another settings manager. Switching from this option to another will back up any custom settings"))
        self.ui.apply.setText(_("Apply"))
        self.ui.done.setText(_("Done"))
        self.qd.show()
        sys.exit(self.qd.exec_())
	   
    def check(self):
        ''' overrides the DesktopEffectsCommon.check() method, does some painting '''
        DesktopEffectsCommon.check(self)
        self.ui.packageText.setText(self.pText)
        self.ui.installButton.setText(self.ibText)
        if os.path.exists(os.path.expanduser("~/.trinity/share/config/compizasWM")):
		   compizasWM = open(os.path.expanduser("~/.trinity/share/config/compizasWM"))
		   state = compizasWM.readline()
		   if state == "standardeffects":
			   self.action = 2
			   self.ui.stdEffectsButton.toggle()
		   elif state == "extraeffects":
			   self.action = 3
			   self.ui.extraEffectsButton.toggle()
		   elif state == "custom":
			   self.action = 4
			   self.ui.customEffectsButton.toggle()	   	   
        else:                                             
		   self.action = 1
		   self.ui.noEffectsButton.toggle()
    def apply(self):
         DesktopEffectsCommon.apply(self)
         if self.action == 1:
		   print "hi"
		   os.popen("twin --replace &")

    def showWarning(self):
        ''' shows the warning box if the package is installed '''
        self.ui.warningText.show()
        self.ui.warningIcon.show()

    def hideWarning(self):
        ''' hides the warning because the package is not yet there '''
        self.ui.warningText.hide()
        self.ui.warningIcon.hide()

    def enable(self):
        ''' enables the radio boxes, compiz is installed '''
        self.ui.groupBox.setDisabled(False)

    def disable(self):
        ''' disables the group box, you have to install compiz first '''
        self.ui.groupBox.setDisabled(True)

    def close(self):
        ''' triggers the QDialog to close '''
        self.qd.close()