summaryrefslogtreecommitdiff
path: root/Compiz-Fusion-Preferences/compiz-fusion-settings
blob: 231e67bdfc5b592fe8b1c399ebb67eb37070c1d8 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
#!/usr/bin/env python

# This program is used to change the settings of Compiz Fusion
# and also does some hardware detectection. It is not a full-
# blown settings manager.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Authors: Sam Spilsbury (SmSpillaz@gmail.com)
# Copyright (C) 2007 Sam Spilsbury

import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
import gtk.gdk as gdk
import gobject
import compizconfig
from CompizFusionSettings.execute import run
from subprocess import Popen
import ccm.Conflicts
import ccm.Utils
import os

class Base:

    def SystemInfoCheck(self):

	    self.glxinfo = run('glxinfo', 'output')
	    self.xvinfo = run('xvinfo', 'output')
	    self.xdpyinfo = run('xdpyinfo', 'output')

	    self.StartupCommand = ""

	    if "GNOME_DESKTOP_SESSION_ID" in os.environ:
		    self.desktop = "GNOME"
	    elif "KDE_FULL_SESSION" in os.environ:
		    self.desktop = "KDE"
	    else:
		    self.desktop = 'Unknown'

	    # We need to check if TFP is direct or Indirect

	    self.tfp = False
	    if self.glxinfo.count('GLX_EXT_texture_from_pixmap') == 0:
		    self.tfp = 'none'
	    elif self.glxinfo.count('GLX_EXT_texture_from_pixmap') < 3:
		    self.tfp = 'indirect'
	    else:
		    self.tfp = 'direct'


	    # Because Xgl is an entirely new server, we need to check for it first

	    if 'Xgl' in self.xvinfo:
		    self.XglIsActive = True
		    self.possible = True
		    self.StartupCommand = "compiz --replace ccp"
	    else:
		    self.XglIsActive = False

	    if self.XglIsActive == True:
		    self.RenderingPathString = '<b>Xgl</b>. Desktop effects are provided by an OpenGL overlay. You may notice slowness with 3D applications and Video'
	    else:
		    if self.tfp == 'direct':
			    self.RenderingPathString = '<b>Direct Rendering.</b> Desktop effects are provided by your graphics card. You may experience driver glitches.'
			    self.possible = True
		    elif self.tfp == 'indirect':
			    self.RenderingPathString = 'X.org <b>AIGLX</b>. Some 3D applications and video may not display correctly when desktop effects are enabled'
			    self.possible = True
		    elif self.tfp == 'none':
			    self.RenderingPathString = 'Desktop effects cannot be enabled. You will need to configure your X server'
			    self.possible = False

	    line = [l for l in self.glxinfo.splitlines() if 'OpenGL renderer string:' in l]
	    if line:
		    self.GlxRenderer = ' '.join(line[0].split()[3:])

	    if 'Intel' in self.GlxRenderer:
		    self.StartupCommand = "INTEL_BATCH=1 LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp"

	    elif 'Radeon' in self.GlxRenderer:
		    self.StartupCommand = "LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp"

	    elif 'NVIDIA' in self.GlxRenderer:
		    if self.tfp == "direct":
			    self.StartupCommand = "__GL_YEILD='NOTHING' compiz --replace --loose-binding ccp"
		    elif self.tfp == "indirect":
			    self.StartupCommand = "LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp"

	    print "For reference, your startup command is: %s" %self.StartupCommand

    def delete(self, widget, event=None):
	    gtk.main_quit()
	    return False

    def openccsm(self, widget, event=None):
	    run("ccsm")
	    gtk.main_quit()
	    return False

    def openthemer(self, widget, event=None):
	    if self.InterTheme.get_active() == True:

		    if self.desktop == "GNOME":
			    run(["gnome-theme-manager"])
		    if self.desktop == "KDE":
			    run(["kcmshell", "kwindecoration"])
	    else:
		    run("emerald-theme-manager")

    def EnableDisableCompiz(self, widget, event=None):

	    # First, we need to check if we are enabling or disabling

	    EnabledOrDisabled = self.EnableEffects.get_active()

	    # If it is disabled, we kill compiz, wait - then (FIXME) execute metacity

	    if EnabledOrDisabled == False:
		    run(['killall', 'compiz'])
		    run(['metacity', '--replace'])
	    elif EnabledOrDisabled == True:
		    run(['killall', 'metacity'])
		    run("compiz-manager")

    def IntegrateTheme(self, widget, event=None):

	    # Are we integrating or not?

	    Integrate = self.InterTheme.get_active()

	    if Integrate == True:
		    if self.desktop == "GNOME":
			    run(["killall", "kde-window-decorator", "emerald", "gtk-window-decorator"])
			    run(["gtk-window-decorator", "--replace"])
		    elif self.desktop == "KDE":
			    run(["killall", "kde-window-decorator", "emerald", "gtk-window-decorator"])
			    run(["kde-window-decorator", "--replace"])
		    else:
			    print "Check box should be disabled, this should not happen!"

	    else:
		    run(["killall", "kde-window-decorator", "emerald", "gtk-window-decorator"])
		    run(["emerald", "--replace"])

    def RunFusionIcon(self, widget):
	    Running = self.TrayIcon.get_active()
	    if Running == True:
		    run(["fusion-icon", "--no-start"])
	    else:
		    run(["killall", "fusion-icon"])

    def __init__(self):
        self.SystemInfoCheck()

        self.gladefile = gtk.glade.XML('/usr/local/share/compiz-fusion-settings/compiz-fusion-settings.glade')

        self.context = compizconfig.Context()

        names = ["core", "text", "switcher", "ring", "shift", "scale", "scalefilter", "scaleaddon", "thumbnail", "group", "extrawm", "widget", "expo", "move", "cube", "rotate", "wall", "plane", "cubereflex", "3d", "gears", "atlantis", "vpswitch", "wobbly", "animation", "resize", "snow", "water", "firepaint", "reflex", "blur", "trailfocus", "bs", "ezoom", "colorfilter", "annotate", "showdesktop", "fadedesktop"]

        self.plugins = []

        for plugin in names:
            if plugin in self.context.Plugins:
	            self.plugin = self.context.Plugins[plugin]
	            self.plugins.append(self.plugin)

        self.pluginnames = []

        for plugin in self.plugins:
            name = plugin.Name
            self.pluginnames.append(name)

        # Sanity Check

        for pluginname in self.pluginnames:
            index = self.pluginnames.index(pluginname)
            if self.pluginnames[index] == self.plugins[index].Name:
	            continue
            else:
	            print "This should not happen"
	            print pluginname
	            print names[index] + " Names index"
	            print self.plugins[index].Name + " Plugins index"
	            raise KeyError

        # When the window is closed, the app is closed. 
        self.Window = self.gladefile.get_widget('CompizFusionConfigWindow')
        self.Window.connect("delete_event", self.delete)
        self.Window.set_icon_from_file('/usr/local/share/icons/hicolor/scalable/apps/fusion-icon-settings.svg')

        # When we click the button, the app is closed
        self.QuitButton = self.gladefile.get_widget('QuitButton')
        self.QuitButton.connect("clicked", self.delete)

        # When we click 'Open CCSM,' this window closes
        self.OpenCCSMButton = self.gladefile.get_widget('OpenCCSMButton')
        self.OpenCCSMButton.connect("clicked", self.openccsm)

        ## Other Stuff

        # We need to import the notebook, and grab the tab to set some text and stuff

        ## The "General" Tab

        # Enable Desktop Effects

        self.EnableEffects = self.gladefile.get_widget('EnableFXCheckButton')
        if run(['pgrep', 'compiz'], 'call', quiet=True) == 0:
            EffectsAreEnabled = True
        else:
            EffectsAreEnabled = False

        self.EnableEffects.set_active(EffectsAreEnabled)
        self.EnableEffects.connect("clicked", self.EnableDisableCompiz)

        # The Desktop Identifier

        self.DEIdentifier = self.gladefile.get_widget("DELabel")
        self.DEIdentifier.set_text(self.desktop)

        self.DEImage = self.gladefile.get_widget("DEImage")
        DEImages = [["KDE", "/usr/local/share/pixmaps/KDE.png"], ["GNOME", "/usr/local/share/pixmaps/GNOME.png"], ["Unknown", "/usr/local/share/pixmaps/general.png"]]
        for info in DEImages:
            if self.desktop == info[0]:
	            self.DEImage.set_from_file(info[1])

        # The Rendering Path Identifier

        self.RenderingPathIdentifier = self.gladefile.get_widget('RenderingMethod')
        self.RenderingPathIdentifier.set_text(self.RenderingPathString)
        self.RenderingPathIdentifier.set_use_markup(True)

        # The "Configure" Button

        self.gladefile.get_widget('CompizFusionConfigWindow').show_all()

        if self.possible == False:
            self.EnableEffects.set_sensitive(False)

        # Gfx card identifier

        self.GraphicsAdaptorIdentifier = self.gladefile.get_widget('GraphicsCard')
        self.GraphicsAdaptorIdentifier.set_use_markup(True)
        # Xgl screws up some stuff in glxinfo, putting "Generic Graphics Card" there.
        # We need to notify the user that the graphics card cannot be displayed at the
        # moment
        if self.XglIsActive == True:
            self.GraphicsAdaptorIdentifier.set_text("Xgl is currently enabled. Therefore, your graphics card cannot be determined at this time. If you want to know your graphics card's model, disable Xgl")
        else:
            self.GraphicsAdaptorIdentifier.set_text(self.GlxRenderer)

	            # Gfx Card Image

        self.DisplayImage = self.gladefile.get_widget('MonitorImage')
        self.DisplayImage.set_from_file('/usr/local/share/pixmaps/display.png')

        # Rendering Path Image

        self.RenderImage = self.gladefile.get_widget('RenderingMethodImage')
        self.RenderImage.set_from_file('/usr/local/share/pixmaps/Rendering.svg')

        # Intergration Check Box

        self.Integration = self.gladefile.get_widget('InterSettings')
        if self.desktop == "GNOME":
            if self.context.CurrentBackend.Name == "gconf":
	            self.Integration.set_active(True)
            else:
	            self.Integration.set_active(False)
        elif self.desktop == "KDE":
            if self.context.CurrentBackend.Name == "kconfig":
	            self.Integration.set_active(True)
            else:
	            self.Integration.set_active(False)
        else:
            self.Integration.set_sensitive(False)
        self.Integration.connect('clicked', self.IntegrationToggled)

        # Theme integration

        self.InterTheme = self.gladefile.get_widget("InterTheme")
        if self.desktop == "GNOME":
            # For some reason, pgrep won't pick up on gtk-w-d if you put in gtk-window-decorator. 'gtk-window-deco' is close enough :)
            if run(['pgrep', 'gtk-window-deco'], 'call', quiet=True) == 0:
	            self.InterTheme.set_active(True)
            else:
	            self.InterTheme.set_active(False)
        elif self.desktop == "KDE":
            if run(['pgrep', 'kde-window-deco'], 'call', quiet=True) == 0:
	            self.InterTheme.set_active(True)
            else:
	            self.InterTheme.set_active(False)
        else:
            self.InterTheme.set_active(False)
            self.InterTheme.set_sensitive(False)
        self.InterTheme.connect('clicked', self.IntegrateTheme)

        # The "Theme" Button

        self.ThemeButton = self.gladefile.get_widget('ThemeButton')
        self.ThemeButton.connect("clicked", self.openthemer)

        # Tray Icon

        self.TrayIcon = self.gladefile.get_widget("TrayIconCheck")
        if run(["pgrep", "fusion-icon"], mode='call') == 0:
            self.TrayIcon.set_active(True)
        else:
            self.TrayIcon.set_active(False)
        self.TrayIcon.connect('clicked', self.RunFusionIcon)

        self.BoolSettings = [['EnableLighting', ['core', 'lighting']], ['VSyncEnable', ['core', 'sync_to_vblank']], ['AllowTabbingCheckBox', ['group', 'autotab_create']], ["EdgeFlipDrag", ["rotate", "edge_flip_window"]], ["EdgeFlipPointer", ["rotate", "edge_flip_pointer"]], ["ReflectionCheck", ["expo", "reflection"]], ["FocusTrack", ["ezoom", "follow_focus"]], ["ZoomToWindow", ["ezoom", "focus_fit_window"]], ['Skydome', ['cube', 'skydome']], ['ShowDesktopScale', ['scale', 'show_desktop']]]

        self.PluginEnableDisables = [["AllowGroupingCheckBox", "group"], ["TextScale", "scaleaddon"], ["SearchScale", "scalefilter"], ["Thumbnails", "thumbnail"], ["CubeReflectionCheck", "cubereflex"], ["3DCheck", "3d"], ["VPSwitchCheck", "vpswitch"], ["WaterCheck", "water"], ["FireCheck", "firepaint"], ["SnowCheck", "snow"], ["BlurCheck", "blur"], ["ReflexCheck", "reflex"], ["TrailfocusCheck", "trailfocus"]]

        self.ValueSettings = [['DesktopSizeX', ['core', 'hsize']], ['DesktopSizeY', ['core', 'vsize']], ['OpacityMovingWindows', ['move', 'opacity']], ['CubeZoom', ['rotate', 'zoom']], ['CubeTransparency', ['cube', 'active_opacity']]]

        self.TextSettings = [['FullscreenEntry', ['extrawm', 'toggle_fullscreen_key']], ['StickEntry', ['extrawm', 'toggle_sticky_key']], ['CursorWaterKey', ['water', 'initiate_key']], ['CursorFireKey', ['firepaint', 'initiate_button']], ['SnowKey', ['snow', 'toggle_key']], ['SelectZoomAreaButton', ['zoom', 'initiate_button']], ['FilterKey', ['colorfilter', 'toggle_window_key']], ['SwitchFilterKey', ['colorfilter', 'switch_filter_key']], ['DrawWithEntry', ['annotate', 'initiate_button']], ['ClearWithEntry', ['annotate', 'clear_key']], ['ActivateWindowPicker', ['scale', 'initiate_key']], ['ToggleExpo', ['expo', 'expo_key']]]

        for x in range(0, len(self.PluginEnableDisables)):
            pluginname = self.PluginEnableDisables[x][1]
            if pluginname not in self.pluginnames:
                sensitive = False
                self.CreatePluginSetting(self.PluginEnableDisables[x][0], 0, sensitive)
            else:
                sensitive = True
                name = self.PluginEnableDisables[x][1]
                name2 = None
                self.CreatePluginSetting(self.PluginEnableDisables[x][0], name, sensitive, name2)

        for x in range(0, len(self.BoolSettings)):
            if self.BoolSettings[x][1][0] not in self.pluginnames:
                sensitive = False
                self.CreateBoolSetting(self.BoolSettings[x][0], 0, 0, sensitive)
            else:
                sensitive = True
                self.CreateBoolSetting(self.BoolSettings[x][0], self.BoolSettings[x][1][0], self.BoolSettings[x][1][1], sensitive)

        for x in range(0, len(self.ValueSettings)):
            if self.ValueSettings[x][1][0] not in self.pluginnames:
                sensitive = False
                self.CreateValueSetting(self.ValueSettings[x][0], 0, 0, sensitive)
            else:
                sensitive = True
                self.CreateValueSetting(self.ValueSettings[x][0], self.ValueSettings[x][1][0], self.ValueSettings[x][1][1], sensitive)

        for x in range(0, len(self.TextSettings)):
            if self.TextSettings[x][1][0] not in self.pluginnames:
                sensitive = False
                self.CreateTextSetting(self.TextSettings[x][0], 0, 0, sensitive)
            else:
                sensitive = True
                self.CreateTextSetting(self.TextSettings[x][0], self.TextSettings[x][1][0], self.TextSettings[x][1][1], sensitive)

        # Now for the hard part - The Texture Filter
        self.TextureFilterCombo = self.gladefile.get_widget('TextureFilteringCombo')
        self.OldTextureFilteringComboValue = self.plugins[self.pluginnames.index('core')].Display["texture_filter"].Value
        self.TextureFilterCombo.set_active(self.OldTextureFilteringComboValue)
        self.TextureFilterCombo.connect("changed", self.TextureFilterModified)

        ## The 'Windows' Tab

        # Which Switcher to use

        # Here, we determine which of the switchers is the 'Active'
        # one, and hence we set the key. The only problem is that
        # flat switcher must be active by default if all switchers are enabled
        # already.

        self.switchers = [[0, None], [1, 'switcher'], [2, 'ring'],  [3, ['shift', 0]], [4, ['shift', 1]]]
        self.SwitcherChooser = self.gladefile.get_widget('SwitcherTypeCombo')
        switcherplugins = []
        self.ShiftFunctionIsReady = False
        for i in self.switchers:
            if i[1] == None:
                pass
            else:
                if 'list' in str(type(i[1])):
                    self.switchPlugin = self.context.Plugins[i[1][0]]
                    index = i[0]
                    shift_type = i[1][1]
                    switcherplugins.append(plugin)
                else:
                    self.switchPlugin = self.context.Plugins[i[1]]
                    index = i[0]
                    shift_type = None
                    switcherplugins.append(plugin)

                if self.switchPlugin.Enabled == True:
                    if shift_type != None:
                        if shift_type == 0:
                            index = 3
                        elif shift_type == 1:
                            index = 4
                    self.CreateSwitcherKey(self.switchPlugin.Name)
                    self.SwitcherChooser.set_active(index)
            self.SwitcherChooser.connect('changed', self.SwitcherChanged)
        if self.SwitcherChooser.get_active() == -1:
            self.SwitcherChooser.set_active(0)

        # CHEAP HACK! Sue me...
        # We have to correct shift detection as it keeps on crapping up
        # read : Calling the 'changed' function for no apparant reason
        self.ShiftFunctionIsReady = True

        # Show Desktop Mode
        ShowDesktopMode = self.gladefile.get_widget('showDesktopMode')
        # Check active mode
        if self.plugins[self.pluginnames.index('showdesktop')].Enabled == True:
            ShowDesktopMode.set_active(1)
        elif self.plugins[self.pluginnames.index('fadedesktop')].Enabled == True:
            ShowDesktopMode.set_active(2)
        else:
            ShowDesktopMode.set_active(0)

        ShowDesktopMode.connect('changed', self.ShowDesktopModeChanged)



        # Here we are going to do the screencorners. What we need to do here is
        # check every possible option to see if a screencorner is set for that widget

        # Now we need to create a list that relates the option names back to the numbers

        self.NewScreenCornerPlugins = [[None, None], ["scale", "initiate_edge"], ["scale", "initiate_all_edge"], ["scale", "initiate_group_edge"], ["expo", "expo_edge"], ["core", "show_desktop_edge"], ["widget", "toggle_edge"]]

        self.Edges = ["TopLeft", "TopRight", "BottomLeft", "BottomRight", "Left", "Right", "Top", "Bottom"]
        self.CurrentEdges = []		

        for Edge in self.Edges:
            # When this reaches 6, there musn't be any setting on the edge
            MissingEdgeCount = 0
            for i in self.NewScreenCornerPlugins:
                if i[0] != None:
                    if self.context.Plugins[i[0]].Display[i[1]].Value == Edge:
                        if i[1] != None:
                            self.CurrentEdges.append([self.NewScreenCornerPlugins.index(i), Edge])
                            break
                    else:
                        MissingEdgeCount = MissingEdgeCount + 1
                        if MissingEdgeCount == 6:
                            self.CurrentEdges.append([None, "Disabled"])


        EdgeWidgets = ['TopLeftEdgeSelect', 'TopRightEdgeSelect', 'BottomLeftEdgeSelect', 'BottomRightEdgeSelect', 'LeftEdgeSelect', 'RightEdgeSelect', 'TopEdgeSelect', 'BottomEdgeSelect']

        for Edge in EdgeWidgets:
            self.Widget = self.gladefile.get_widget(Edge)
            for x in range(0, len(self.CurrentEdges)):
                if Edge in EdgeWidgets[x]:
                    if self.CurrentEdges[x][0] != None:
                        self.Widget.set_active(self.CurrentEdges[x][0])
                    else:
                        self.Widget.set_active(0)
            self.Widget.connect("changed", self.EdgeChanged, self.Edges[EdgeWidgets.index(Edge)])

        # Treeview for keybindings,

        self.KeyBindingsStore = gtk.TreeStore(
            str, # Name of object
            bool, # Does it have a keybinding?
            str, # Keybinding setting
            object, # The object that holds the keybinding,
            bool, # Does it have a mousebinding?
            str, # Mousebinding setting
            object, # The object that holds the mousebinding,
                    )

        settingActions = { 'General' : 
                    [["Show the desktop", "core", "show_desktop", True, False],
                     ["Shade a window", "core", "toggle_window_shaded", True, False],
                     ["Slow Motion Animations", "core", "slow_animations", True, False],
                     ["Maximise Horizontally",'core', 'toggle_window_maximized_horizontally', True, False],
                     ["Maximise Vertically", 'core', 'toggle_window_maximized_vertically', True, False],
                     ["Increase Opactiy", 'core', 'opacity_increase', False, True],
                     ["Decrease Opactiy", 'core', 'opacity_decrease', False, True]
                    ],
                   'Application Switcher' : 
                   	[["Flip to the next window", "switcher", "next", True, True],
                   	 ["Flip to the previous window", "switcher", "prev", True, True],
                         ["Flip to the next window in all desktops", "switcher", "next_all", True, True],
                   	 ["Flip to the previous window in all desktops", 'switcher', "prev_all", True, True],
                    	],
                   'Ring Switcher' : 
                   	[["Flip to the next window", "ring", "next", True, True],
                   	 ["Flip to the previous window", "ring", "prev", True, True],
                         ["Flip to the next window in all desktops", "ring", "next_all", True, True],
                   	 ["Flip to the previous window in all desktops", 'ring', "prev_all", True, True],
                    	],
                   'Shift Switcher' : 
                   	[["Flip to the next window", "shift", "next", True, True],
                   	 ["Flip to the previous window", "shift", "prev", True, True],
                         ["Flip to the next window in all desktops", "shift", "next_all", True, True],
                   	 ["Flip to the previous window in all desktops", 'shift', "prev_all", True, True],
                    	],
                   'Window Picker' : 
                   	[['Pick from current viewport', 'scale', 'initiate', True, False],
                   	 ['Pick from all viewports', 'scale', 'initiate_all', True, False],
                   	 ['Pick from current application', 'scale', 'initiate_group', False, False]
                   	],
                	   'Window Grouper' : 
                	   	[['Select a window', 'group', 'select_single', True, False],
                	   	 ['Group Selected Windows', 'group', 'group', True, False],
                	   	 ['Ungroup window group', 'group', 'ungroup', True, False],
                	   	 ['(Un)Tab selected or grouped windows', 'group', 'tabmode', True, False]
                     	],
                   'Desktop Cube' : [
                   	 ['Free Rotation', 'rotate', 'initiate', False, True],
                    	 ['Rotate Left', 'rotate', 'rotate_left', True, True],
                    	 ['Rotate Right', 'rotate', 'rotate_right', True, True],
                    	 ['Rotate Left with Window', 'rotate', 'rotate_left_window', True, True],
                    	 ['Rotate Right', 'rotate', 'rotate_right_window', True, True]
                    	],				     
                   'Desktop Wall' : [
                   	 ['Move Left', 'wall', 'left', True, True],
                    	 ['Move Right', 'wall', 'right', True, True],
                    	 ['Move Up', 'wall', 'up', True, True],
                    	 ['Move Down', 'wall', 'down', True, True],
                    	 ['Move Left with Window', 'wall', 'left_window', True, False],
                    	 ['Move Right with Window', 'wall', 'right_window', True, False],
                    	 ['Move Up with Window', 'wall', 'up_window', True, False],
                    	 ['Move Down with Window', 'wall', 'down_window', True, False]
                        ]
                     }
        for category, actionS in settingActions.items():
            categoryiter = self.KeyBindingsStore.append(None, [category, False, '', None, False, '', None])
            for action in actionS:
                actionString = action[0]
                actionPluginName = action[1]
                if actionPluginName not in self.pluginnames:
                    print "Plugin doesn't exist!"
                    break
                else:
                        actionPlugin = self.plugins[self.pluginnames.index(actionPluginName)]
                actionSetting = action[2]
                actionHasKB = action[3]
                if actionHasKB == True:
                    actionKBSetting = self.GetSetting(actionPlugin, "Display", actionSetting+"_key")
                    actionKBValue = actionKBSetting.Value
                else:
                    actionKBValue = "None"
                    actionKBSetting = None
                actionHasMouse = action[4]
                if actionHasMouse == True:
                    actionMouseSetting = self.GetSetting(actionPlugin, "Display", actionSetting+"_button")
                    actionMouseValue = actionMouseSetting.Value
                else:
                    actionMouseSetting = None
                    actionMouseValue = "None"
                self.KeyBindingsStore.append(categoryiter, [actionString,
		                                actionHasKB,
		                                actionKBValue,
		                                actionKBSetting,
		                                actionHasMouse,
		                                actionMouseValue,
		                                actionMouseSetting
		                               ]
                                )

        self.KeyBindingsView = self.gladefile.get_widget('KeybindingTreeview')
        self.KeyBindingsView.set_model(self.KeyBindingsStore)

        NameColumn = gtk.TreeViewColumn('Action Name')
        self.KeyBindingsView.append_column(NameColumn)
        NameCell = gtk.CellRendererText()
        NameColumn.pack_start(NameCell, True)
        NameColumn.add_attribute(NameCell, 'text', 0)

        KeyColumn = gtk.TreeViewColumn('Key Shortcut')
        self.KeyBindingsView.append_column(KeyColumn)
        KeyCell = gtk.CellRendererText()
        KeyCell.connect('edited', self.ActionKeyEdited)
        KeyColumn.pack_start(KeyCell, True)
        KeyColumn.add_attribute(KeyCell, 'text', 2)
        KeyColumn.add_attribute(KeyCell, 'sensitive', 1)
        KeyColumn.add_attribute(KeyCell, 'editable', 1)

        MouseColumn = gtk.TreeViewColumn('Mouse Button')
        self.KeyBindingsView.append_column(MouseColumn)
        MouseCell = gtk.CellRendererText()
        MouseCell.connect('edited', self.ActionButtonEdited)
        MouseColumn.pack_start(MouseCell, True)
        MouseColumn.add_attribute(MouseCell, 'text', 5)
        MouseColumn.add_attribute(MouseCell, 'sensitive', 4)
        MouseColumn.add_attribute(MouseCell, 'editable', 4)

        # The 'App switch with' entry

        # Desktop Appearance
        self.DesktopPlugins = []
        for plugin in self.context.Plugins.values():
            if "largedesktop" in plugin.Features:
                self.DesktopPlugins.append([plugin, plugin.ShortDesc])
        self.FillDesktopAppearance()

        # Effects Settings

        # Move Effect Combo
        self.MoveEffect = self.gladefile.get_widget('MoveCombo')
        if 'Normal' or 'Dialog' or 'ModalDialog' in self.context.Plugins['wobbly'].Screens[0]['move_window_match'].Value:
            self.MoveEffect.set_active(1)
        else:
            self.MoveEffect.set_active(0)
        self.MoveEffect.connect("changed", self.MoveEffectChanged)

        # Maximise Effect Combo
        self.MaximiseEffect = self.gladefile.get_widget('MaximiseCombo')
        if self.plugins[self.pluginnames.index('wobbly')].Screens[0]["maximize_effect"].Value == True:
            self.MaximiseEffect.set_active(1)
        else:
            self.MaximiseEffect.set_active(0)
        self.MaximiseEffect.connect('changed', self.MaximiseEffectChanged)

        # Resize Effect Combo

        self.ResizeEffect = self.gladefile.get_widget('ResizeCombo')
        self.OldResizeEffectValue = self.plugins[self.pluginnames.index('resize')].Display["mode"].Value
        self.ResizeEffect.set_active(self.OldResizeEffectValue)
        self.ResizeEffect.connect("changed", self.ResizeEffectChanged)

        # Animation Boxes. Thanks to marex for the functions

        self.FillAnimationBoxes()

        self.CreateCombo = self.gladefile.get_widget('CreateCombo')
        self.CreateCombo.connect('changed', self.AnimationBoxChanged, "open_effects")

        self.CloseCombo = self.gladefile.get_widget('CloseCombo')
        self.CloseCombo.connect('changed', self.AnimationBoxChanged, "close_effects")

        self.MinimizeCombo = self.gladefile.get_widget('MinimizeCombo')
        self.MinimizeCombo.connect('changed', self.AnimationBoxChanged, "minimize_effects")

        self.ShadeCombo = self.gladefile.get_widget('ShadeCombo')
        self.ShadeCombo.connect('changed', self.AnimationBoxChanged, "shade_effects")

        self.FocusCombo = self.gladefile.get_widget('FocusCombo')
        self.FocusCombo.connect('changed', self.AnimationBoxChanged, "focus_effects")


        # Accessibility
        # Opacity Brightness and Saturation

        self.OBSModifiers = [["OpacityModifiers", ["core", "opacity_increase_button"]], ["BrightnessModifiers", ["bs", "brightness_increase_button"]], ["SaturationModifiers", ["bs", "saturation_increase_button"]]]

        self.PossibleButtons = ["Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7"]

        for i in self.OBSModifiers:
            self.OBSWidget = self.gladefile.get_widget(i[0])
            if i[1][0] not in self.context.Plugins:
                self.OBSWidget.set_sensitive(False)
            else:			
                NameOfWidget = i[0]
                OBSTempString = self.context.Plugins[i[1][0]].Display[i[1][1]].Value
                for Button in self.PossibleButtons:
                    if Button in OBSTempString:
                        self.OBSWidgetText = OBSTempString.replace(Button, "")
                self.OBSWidget.set_text(self.OBSWidgetText)
                self.OBSWidget.connect("activate", self.OBSModifierChanged, self.OBSWidget, i[1][1], i[1][0],  NameOfWidget)

        # Zoom keys
        zoomPluginExists = False
        ZoomButton = None
        zoomPlugin = None

        ZoomButton = None # Initialize the variable *cough*

        self.ZoomButtonEntry = self.gladefile.get_widget("ZoomIn")
        if self.context.Plugins['zoom'].Enabled == True:
            ZoomButton = self.context.Plugins['zoom'].Display["zoom_in_button"]
            zoomPlugin = "zoom"
            zoomPluginExists = True
        elif self.context.Plugins['ezoom'].Enabled == True:
            ZoomButton = self.context.Plugins['ezoom'].Display["zoom_in"]
            zoomPlugin = "ezoom"
            zoomPluginExists = True

        print zoomPluginExists
        print ZoomButton
        print zoomPlugin
        if zoomPluginExists == True:
            self.CreateZoomKey(zoomPluginExists, zoomPlugin, ZoomButton)

        # Zoom Mode

        self.ZoomMode = self.gladefile.get_widget("ZoomModeCombo")
        # Here begins a series of checks to determine what zoom mode is in use.
        if self.context.Plugins['zoom'].Enabled == True:
            self.ZoomMode.set_active(2)
        else:
            if self.context.Plugins['ezoom'].Screens[0]["sync_mouse"].Value == True:
                self.ZoomMode.set_active(1)
            else:
                self.ZoomMode.set_active(0)

        self.ZoomMode.connect("changed", self.ZoomModeChanged)



        # Speed Controller. I am putting this here after plugins have been initialized

        self.SpeedControl = self.gladefile.get_widget('EffectsSpeed')
        self.RateSpeed()
        SpeedControlSpeed = self.Speed / 11
        self.SpeedControl.set_value(SpeedControlSpeed)
        self.SpeedControl.connect('value-changed', self.SpeedControlChanged)

        # Here begins the area where widgets are and options are checked if
        # they are unequal and if so, the option is changed to match the widget.
        # Some areas may require conversion of intergers to strings, so that both
        # the widget and the settings value can make sense

        # Core Options

    def TextureFilterModified(self, widget):

	    TextureFilterModifiedCurrentValue = self.TextureFilterCombo.get_active()
	    TextureFilterModifiedCompizValue = self.plugins[self.pluginnames.index('core')].Display["texture_filter"].Value

	    if (TextureFilterModifiedCurrentValue != TextureFilterModifiedCompizValue):
		    self.plugins[self.pluginnames.index('core')].Display["texture_filter"].Value = TextureFilterModifiedCurrentValue
		    self.context.Write()

    def FillDesktopAppearance(self):
	    ComboBox = self.gladefile.get_widget("DesktopAppearanceCombo")
	    for i in self.DesktopPlugins:
		    ComboBox.append_text(i[1])
		    if i[0].Enabled == True:
			    ComboBox.set_active(self.DesktopPlugins.index(i))
	    ComboBox.connect("changed", self.DesktopAppearanceChanged)

    def CreateSwitcherKey(self, plugin):
	    self.SwitcherKey = self.gladefile.get_widget('AppSwitcherKey')
	    self.SwitcherKey.set_text(self.context.Plugins[plugin].Display["next_key"].Value)
	    self.SwitcherKey.connect('activate', self.SwitcherKeyChanged, plugin, self.SwitcherKey)
	
    def SwitcherChanged(self, widget):
	    # Continued from CHEAP HACK
	    if self.ShiftFunctionIsReady != True:
		    pass
	    else:
		    active = self.SwitcherChooser.get_active()
		    if active == 0:
			    for i in range(1, len(self.switchers)):
				    if self.switchers[i][1] == None:
					    pass
				    else:
					    if 'list' in str(type(self.switchers[i][1])):
						    self.context.Plugins[self.switchers[i][1][0]].Enabled = False
					    else:
						    self.context.Plugins[self.switchers[i][1]].Enabled = False
		    else:
			    if self.switchers[active][1] == None:
				    pass
			    else:
				    if 'list' in str(type(self.switchers[active][1])):
					    # This means we are working with a shift switcher
					    self.context.Plugins[self.switchers[active][1][0]].Enabled = True
					    if active == 3:
						    self.context.Plugins[self.switchers[active][1][0]].Screens[0]["mode"].Value = 1
					    else:
						    self.context.Plugins[self.switchers[active][1][0]].Screens[0]["mode"].Value = 0
				    else:
					    self.context.Plugins[self.switchers[active][1]].Enabled = True
					
				    self.context.Write()
			
			    #Disable the rest
			
			    for i in range(1, len(self.switchers)):	
				    if 'list' in str(type(self.switchers[i][1])):
					    if self.switchers[i][0] != active:
						    if active == 3 or 4:
							    # Flip sees cover /(vice-versa) and disables itself -_-
							    pass
						    else:
							    self.context.Plugins[self.switchers[i][1][0]].Enabled = False
				    elif self.switchers[i][0] != active:
					    self.context.Plugins[self.switchers[i][1]].Enabled = False
			
			    self.context.Write()
		
			    # Set the keybinding
			    if 'list' in str(type(self.switchers[active][1])):
				    self.CreateSwitcherKey(self.switchers[active][1][0])
			    else:
				    self.CreateSwitcherKey(self.switchers[active][1])
			

	
    def SwitcherKeyChanged(self, widget, plugin):
	    self.context.Plugins[plugin].Display["next_key"].Value = widget.get_text()
	    self.context.Write()	
	
    def ShowDesktopModeChanged(self, widget):
        active = widget.get_active()
        if active is 0:
            self.plugins[self.pluginnames.index('showdesktop')].Enabled = False
            self.plugins[self.pluginnames.index('fadedesktop')].Enabled = False
        elif active is 1:
            self.plugins[self.pluginnames.index('showdesktop')].Enabled = True
            self.plugins[self.pluginnames.index('fadedesktop')].Enabled = False
        elif active is 2:
            self.plugins[self.pluginnames.index('showdesktop')].Enabled = False
            self.plugins[self.pluginnames.index('fadedesktop')].Enabled = True
        self.context.Write()
            

    def EdgeChanged(self, Widget, Edge):
	
	    self.GlobalUpdater = ccm.Utils.Updater()
	    ActionConflict = ccm.Conflicts.ActionConflict
	
	    CurrentValue = Widget.get_active()
	    OldOptionDisabled = False
	    for Option in self.NewScreenCornerPlugins:
		    if Option[0] != None:
			    # First Disable the Old Option
			    if self.context.Plugins[Option[0]].Display[Option[1]].Value == Edge:
				    self.context.Plugins[Option[0]].Display[Option[1]].Value[2] = "Disabled"
				    self.context.Write()
				    OldOptionDisabled = True
		    else:
			    OldOptionDisabled = True
	    if OldOptionDisabled == True:
		    for Option in self.NewScreenCornerPlugins:
			    if self.NewScreenCornerPlugins.index(Option) == CurrentValue:
				    if CurrentValue != 0:
					    Setting = self.context.Plugins[Option[0]].Display[Option[1]]
					    # Enable the plugin
					    Conflict = ccm.EdgeConflict(Setting, Edge, autoResolve = True)
					    if Conflict.Resolve(self.GlobalUpdater):
						    self.context.Plugins[Option[0]].Display[Option[1]].Value[2] = Edge
						    self.context.Plugins[Option[0]].Enabled = True
						    self.context.Write()
					    break
				    else:
					    break
				
    def DesktopAppearanceChanged(self, widget):
	
	    CurrentValue = widget.get_active()
	
	    # First, disable other plugins	
	    for i in self.DesktopPlugins:
		    if self.DesktopPlugins.index(i) != CurrentValue:
			    # resolve conflicts
			    conflicts = i[0].DisableConflicts
			    conflict = ccm.PluginConflict(i[0], conflicts, autoResolve=True)
			    if conflict.Resolve():
				    i[0].Enabled = False
			    else:
				    print "Oops..."
				
	    self.context.Write()
	
	    # Now enable our plugin
	    for i in self.DesktopPlugins:
		    if self.DesktopPlugins.index(i) == CurrentValue:
			    i[0].Enabled = True
			    self.context.Write()
			    if i[0].Name == "cube":
				    self.context.Plugins["rotate"].Enabled = True
				    self.context.Write()	

    # Effects Options

    def MoveEffectChanged(self, widget):

	    option = self.context.Plugins['wobbly'].Screens[0]['move_window_match']

	    if self.MoveEffect.get_active() == 0:
		    option.Value = ''
		    self.context.Write()
	    elif self.MoveEffect.get_active() == 1:
		    option.Value = 'Toolbar | Menu | Utility | Dialog | Normal | Unknown'
		    self.context.Write()

    def MaximiseEffectChanged(self, widget):

	    if self.MaximiseEffect.get_active() == 0:
		    self.context.Plugins['wobbly'].Screens[0]["maximize_effect"].Value = False
		    self.context.Write() 
	    elif self.MaximiseEffect.get_active() == 1:
		    self.context.Plugins['wobbly'].Screens[0]["maximize_effect"].Value = True
		    self.context.Write()

    def ResizeEffectChanged(self, widget):

	    self.plugins[self.pluginnames.index('resize')].Display["mode"].Value = self.ResizeEffect.get_active()
	    self.context.Write()

    # Animation Boxes. Thanks to marex's 'simple-ccsm' for these

    def SetupBoxModel(self, box):
	    store = gtk.ListStore(gobject.TYPE_STRING)
	    box.set_model(store)
	    cell = gtk.CellRendererText()
	    box.pack_start(cell, True)
	    box.add_attribute(cell, 'text', 0)

    def FillAnimationBoxes(self):
	    plugin = self.context.Plugins['animation']
	
	    boxes = {}
	    boxes['CloseCombo'] =  "close_effects"
	    boxes['CreateCombo'] = "open_effects"
	    boxes['MinimizeCombo'] = "minimize_effects"
	    boxes['ShadeCombo'] = "shade_effects"
	    boxes['FocusCombo'] = "focus_effects"

	    for boxName, settingName in boxes.items():
		    box = self.gladefile.get_widget(boxName)
		    setting = plugin.Screens[0][settingName]
		    items = sorted(setting.Info[1][2].items(), key=ccm.EnumSettingKeyFunc)
		    self.SetupBoxModel(box)
		    for key, value in items:
			    box.append_text(key)
		    if len(setting.Value):
			    box.set_active(setting.Value[0])
		    else:
			    box.set_active(0)

    def AnimationBoxChanged(self, widget, settingName):
	    newval = widget.get_active_text()
	    plugin = self.context.Plugins['animation']
	    if self.context.Plugins["minimize"].Enabled == True:
		    self.context.Plugins["minimize"].Enabled = False
		    self.context.Write()
	    if self.plugin.Enabled == False:
		    self.plugin.Enabled = True
		    self.context.Write()
	    setting = plugin.Screens[0][settingName]
	    value = setting.Value
	    if len(value) >= 1:
		    value[0] = setting.Info[1][2][newval]
		    setting.Value = value
		    self.context.Write()
	    else:
		    for setting in plugin.Groups[setting.Group][setting.SubGroup].Screens[0].values():
			    setting.Reset()
			    self.context.Write()
			    self.AnimationBoxChanged(widget, settingName)
			
    # Accessibility

    def OBSModifierChanged(self, widget, WidgetName, OptionName, pluginName, NameOfWidget):
	    CurValue = WidgetName.get_text()
	    NewIncrValue = CurValue + "Button4"
	    NewDecrValue = CurValue + "Button5"
	    for i in self.OBSModifiers:
		    if i[0] == NameOfWidget:
			    self.plugins[self.pluginnames.index(pluginName)].Display[OptionName] = NewIncrValue
			    self.plugins[self.pluginnames.index(pluginName)].Display[OptionName.replace("_increase", "_decrease")].Value[1] = NewDecrValue
			    self.context.Write()


    def ZoomModifierChanged(self, widget):
	    if self.context.Plugins['ezoom'].Enabled == True:
		    self.context.Plugins['ezoom'].Display["zoom_in"].Value = self.ZoomButtonEntry.get_text() + "Button4"
		    self.context.Plugins['ezoom'].Display["zoom_out"].Value = self.ZoomButtonEntry.get_text() + "Button5"
		    self.context.Write()
	    elif self.context.Plugins['zoom'].Enabled == True:
		    self.context.Plugins['zoom'].Display["zoom_in_button"].Value = self.ZoomButtonEntry.get_text() + "Button4"
		    self.context.Plugins['zoom'].Display["zoom_out_button"].Value = self.ZoomButtonEntry.get_text() + "Button5"
            self.context.Write()

    def CreateZoomKey(self, zoomPluginExists, zoomPlugin, ZoomButton):
	    if zoomPluginExists == True:
		    for Button in self.PossibleButtons:
			    if Button in ZoomButton.Value:
				    TempValue = ZoomButton.Value
				    UseZoomButton = TempValue.replace(Button, "")
	    else:
		    UseZoomButton = "Enable Zoom Plugin"
		    zoomPlugin = None
		    self.gladefile.get_widget('SelectZoomAreaButton').set_sensitive(False)
	    self.ZoomModifiers = UseZoomButton
	    self.ZoomButtonEntry.set_text(self.ZoomModifiers)
	    self.ZoomButtonEntry.connect("activate", self.ZoomModifierChanged)



    def ZoomModeChanged(self, widget):
	    CurrentValue = self.ZoomMode.get_active()
	    zoom = self.context.Plugins['zoom']
	    ezoom = self.context.Plugins['ezoom']
	    if CurrentValue == 0:
		    zoom.Enabled = False
		    ezoom.Enabled = True
		    self.gladefile.get_widget('SelectZoomAreaButton').set_sensitive(False)
		    self.gladefile.get_widget('FocusTrack').set_sensitive(True)
		    self.gladefile.get_widget('ZoomToWindow').set_sensitive(True)
		    ezoom.Screens[0]["sync_mouse"].Value = False
		    ezoom.Screens[0]["scale_mouse"].Value = True
		    ezoom.Screens[0]["mouse_pan"].Value = True
		    ezoom.Screens[0]["hide_original_mouse"].Value = True
		    zoomPlugin = "ezoom"
		    ZoomButton = self.context.Plugins['ezoom'].Display["zoom_in"]
		    self.context.Write()
	    elif CurrentValue == 1:
		    zoom.Enabled = False
		    ezoom.Enabled = True
		    self.gladefile.get_widget('SelectZoomAreaButton').set_sensitive(False)
		    self.gladefile.get_widget('FocusTrack').set_sensitive(True)
		    self.gladefile.get_widget('ZoomToWindow').set_sensitive(True)
		    ezoom.Screens[0]["sync_mouse"].Value = True
		    ezoom.Screens[0]["scale_mouse"].Value = False
		    ezoom.Screens[0]["mouse_pan"].Value = False
		    ezoom.Screens[0]["hide_original_mouse"].Value = False
		    zoomPlugin = "ezoom"
		    ZoomButton = self.context.Plugins['ezoom'].Display["zoom_in"]
		    self.context.Write()
	    elif CurrentValue == 2:
		    self.gladefile.get_widget('SelectZoomAreaButton').set_sensitive(True)
		    self.gladefile.get_widget('FocusTrack').set_sensitive(False)
		    self.gladefile.get_widget('ZoomToWindow').set_sensitive(False)
		    zoom.Enabled = True
		    ezoom.Enabled = False
		    zoomPlugin = "zoom"
		    ZoomButton = self.context.Plugins['zoom'].Display["zoom_in_button"]
		    self.context.Write()
	    self.CreateZoomKey(True, zoomPlugin, ZoomButton)

    # Integration

    def IntegrationToggled(self, widget):
	    integrationsettings = {"GNOME" : "gconf", "KDE" : "kconfig"}
	    for Desktop, Backend in integrationsettings.items():
		    if self.Integration.get_active() == True:
			    if self.desktop == Desktop:
				    self.context.CurrentBackend = self.context.Backends[Backend]
				    self.context.Integration = True
			    else:
				    self.context.CurrentBackend = self.context.Backends["ini"]
		    else:
			    self.context.CurrentBackend = self.context.Backends["ini"]
			
    def RateSpeed(self):
	    speedplugins = [['rotate', "speed"], ['scale', "speed"], ['wobbly', "spring_k"], ['switcher', "speed"], ['ring',  "speed"], ['shift', "shift_speed"]]
	    self.speedplugins = []
	    for i in speedplugins:
		    if i[0] in self.pluginnames:
			    self.speedplugins.append(self.plugins[self.pluginnames.index(i[0])].Screens[0][i[1]])

	    durationplugins = [['wall', "slide_duration"], ['animation', "open_durations"], ['animation', "close_durations"], ['animation', "focus_durations"], ['animation', "minimize_durations"], ['animation', "shade_durations"]]
	    self.durationplugins =[]
	
	    for i in durationplugins:
		    if i[0] in self.pluginnames:
			    if i[0] == 'wall':
				    self.durationplugins.append(self.context.Plugins[i[0]].Display[i[1]])
			    else:
				    self.durationplugins.append(self.context.Plugins[i[0]].Screens[0][i[1]])

	    BaseSpeed = 0
	
	    for i in self.speedplugins:
		    # If i is more than 5, it will break this
		    if i.Value > 5:
			    i.Value = 5
		    # Wobbly is a special case
		    if i == self.speedplugins[2]:
			    NewSpeed = BaseSpeed + ((i.Value - 3) / 2)
			    BaseSpeed = NewSpeed
		    else:
			    NewSpeed = BaseSpeed + i.Value
			    BaseSpeed = NewSpeed

	    for i in self.durationplugins:
		    # Wall is special
		    if i == self.durationplugins[0]:
			    NewSpeed = BaseSpeed + (5 - i.Value)
			    BaseSpeed = NewSpeed
		    else:
			    Val = float(i.Value[0]) + 2000
			    if Val > 4000:
				    Val = 4000
			    NewSpeed = BaseSpeed + (5 - (Val / 800))
			    BaseSpeed = NewSpeed


		    self.Speed = BaseSpeed

    def SpeedControlChanged(self, widget):
	    CurrentSpeed = self.SpeedControl.get_value()
	    # Now we need to break that up and give each part equally to each speed control interface

	    for i in self.speedplugins:
		    if i == self.speedplugins[2]:
			    # Wobbly is special
			    i.Value = CurrentSpeed * 2 + 3
			    if i.Value > 10:
				    i.Value = 10
		    else:
			    i.Value = CurrentSpeed

	    for i in self.durationplugins:
		    # Wall is special
		    if i == self.durationplugins[0]:
			    i.Value = 5 - CurrentSpeed
			    self.context.Write()

		    else:
			    Value = i.Value
			    Val = (4000 - (CurrentSpeed * 800))
			    Value[0] = int(Val)
			    # We dont want it to be too slow
			    Value[0] = Value[0] - 2000
			    # Leave it if it hits 100
			    if Value[0] < 100:
				    Value[0] = 100
			    i.Value = Value
			    self.context.Write()
			
    def PluginEnableDisable(self, widget, name, name2=None):
	    self.plugins[self.pluginnames.index(name)].Enabled = widget.get_active()
	    if name2 is not None:
		    self.plugins[self.pluginnames.index(name2)].Enabled = widget.get_active()
	    self.context.Write()
	    if name == 'group':
		    self.gladefile.get_widget('AllowTabbingCheckBox').set_sensitive(widget.get_active())
	
    def SettingBoolToggled(self, widget, plugin, settingName, settingType):
	    if settingType == "Screen":
		    plugin.Screens[0][settingName].Value = widget.get_active()
	    else:
		    plugin.Display[settingName].Value = widget.get_active()
		
	    self.context.Write()
		

    def SettingValueChanged(self, widget, plugin, settingName, settingType):
	    if settingType == "Screen":
		    plugin.Screens[0][settingName].Value = widget.get_value()
	    else:
		    plugin.Display[settingName].Value = widget.get_value()
		
	    self.context.Write()
	
	
    def SettingTextChanged(self, widget, plugin, settingName, settingType):
	    if settingType == "Screen":
		    plugin.Screens[0][settingName].Value = widget.get_text()
	    else:
		    plugin.Display[settingName].Value = widget.get_text()
		
	    self.context.Write()
	
    def SettingButtonChanged(self, signal, name, settingName, settingType, widget):
	    if settingType == "Screen":
		    self.plugins[self.pluginnames.index(name)].Screens[0][settingName].Value[1] = widget.get_text()
	    else:
		    plugin.Display[settingName].Value = widget.get_text()
	
	    self.context.Write()
	
    def CreatePluginSetting(self, widgetName, name, sensitive, name2=None):
	    self.Widget = self.gladefile.get_widget(widgetName)
	    self.Widget.set_sensitive(sensitive)
	    if sensitive == False:
		    pass
	    else:
		    self.Widget.set_active(self.plugins[self.pluginnames.index(name)].Enabled)
		    self.Widget.connect('clicked', self.PluginEnableDisable, name, name2)
		
    def CreateBoolSetting(self, widgetName, name, settingName, sensitive=True):
	    self.Widget = self.gladefile.get_widget(widgetName)
	    self.Widget.set_sensitive(sensitive)
	    if sensitive == False:
		    pass
	    else:
		    if settingName in self.plugins[self.pluginnames.index(name)].Screens[0]:
			    settingType = "Screen"
		    else:
			    settingType = "Display"
		    # We first need to check to see whether the setting is screen or display
		    name = self.plugins[self.pluginnames.index(name)]
		    self.Widget.set_active(self.GetSetting(name, settingType, settingName).Value)
		
		    self.Widget.connect('clicked', self.SettingBoolToggled, name, settingName, settingType)
		    if widgetName == 'AllowTabbingCheckBox':
			    self.Widget.set_sensitive(self.gladefile.get_widget('AllowGroupingCheckBox').get_active())
	

    def CreateValueSetting(self, widgetName, name, settingName, sensitive):
	    self.Widget = self.gladefile.get_widget(widgetName)
	    self.Widget.set_sensitive(sensitive)
	    if sensitive == False:
		    pass
	    else:
		    print name
		    print settingName
		    if settingName in self.plugins[self.pluginnames.index(name)].Screens[0]:
			    settingType = "Screen"
		    else:
			    settingType = "Display"
		    # We first need to check to see whether the setting is screen or display
		    name = self.plugins[self.pluginnames.index(name)]
		    self.Widget.set_value(self.GetSetting(name, settingType, settingName).Value)
		    self.Widget.connect('value-changed', self.SettingValueChanged, name, settingName, settingType)
		
    def CreateTextSetting(self, widgetName, name, settingName, sensitive):
	    self.Widget = self.gladefile.get_widget(widgetName)
	    self.Widget.set_sensitive(sensitive)
	    if sensitive == False:
		    pass
	    else:
		    if settingName in self.plugins[self.pluginnames.index(name)].Screens[0]:
			    settingType = "Screen"
		    else:
			    settingType = "Display"
		    # We first need to check to see whether the setting is screen or display
		    name = self.plugins[self.pluginnames.index(name)]
		    self.Widget.set_text(self.GetSetting(name, settingType, settingName).Value)
		    self.Widget.connect('activate', self.SettingTextChanged, name, settingName, settingType)
		
    def ActionKeyEdited(self, cell, path, text):
	    keyIter = self.KeyBindingsStore.get_iter(path)
	    settingObject = self.KeyBindingsStore.get_value(keyIter, 3)
	    settingObject.Value[0] = text
	    self.context.Write()
	    self.KeyBindingsStore.set_value(keyIter, 2, settingObject.Value)

    def ActionButtonEdited(self, cell, path, text):
	    mouseIter = self.KeyBindingsStore.get_iter(path)
	    settingObject = self.KeyBindingsStore.get_value(mouseIter, 6)
	    settingObject.Value[1] = text
	    self.context.Write()
	    self.KeyBindingsStore.set_value(mouseIter, 5, settingObject.Value)
	
    def GetSetting(self, plugin, settingType, settingName):
	    #print "GetSetting"
	    if settingType == "Display":
		    #print "Returning plugin.Display[settingName]"
		    return plugin.Display[settingName]
	    elif settingType == "Screen":
		    return plugin.Screens[0][settingName]

if __name__=='__main__':
	Base()
	gtk.main()

#TODO:
#	Make the rest of the GUI
#	Connect signals - (fairly easy)
#	Try and figure out a way to detect graphics hardware and rendering method... hmmm.....
#	This is the master version of CFCapplet. Use it only with 0.6 compiz