~ubuntu-branches/ubuntu/oneiric/compizconfig-settings-manager/oneiric

« back to all changes in this revision

Viewing changes to ccm/Widgets.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-04-05 13:36:23 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080405133623-isu5feeln0uxo8bc
Tags: 0.7.4-0ubuntu1
* new upstream release:
  + Improved look of edge and button selector widgets
  + Fixed automatically resolving conflicts
  + Fixed a few bugs in the Profiles page
  + Unified list settings with regular settings
  + Fixed resolution of svg icons => sharp plugin icons
  + Lots of smaller code cleanups
  + Advanced Search rewrite
* 03_update_finish_translation.patch:
  - dropped, does not apply anymore
* added Vcs-Bzr header

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from math import pi, sqrt
29
29
import time
30
30
import re
 
31
import mimetypes
 
32
mimetypes.init()
31
33
 
32
34
from ccm.Utils import *
33
35
from ccm.Constants import *
128
130
        cr.set_source_rgba(r, g, b, a)
129
131
        cr.paint()
130
132
 
 
133
class PluginView(gtk.TreeView):
 
134
    def __init__(self, plugins):
 
135
        liststore = gtk.ListStore(str, gtk.gdk.Pixbuf, bool, object)
 
136
        self.model = liststore.filter_new()
 
137
        gtk.TreeView.__init__(self, self.model)
 
138
 
 
139
        self.SelectionHandler = None
 
140
 
 
141
        self.Plugins = set(plugins)
 
142
 
 
143
        for plugin in sorted(plugins.values(), key=PluginKeyFunc):
 
144
            liststore.append([plugin.ShortDesc, Image(plugin.Name, type=ImagePlugin).props.pixbuf, 
 
145
                plugin.Enabled, plugin])
 
146
        
 
147
        column = self.insert_column_with_attributes(0, _('Plugin'), gtk.CellRendererPixbuf(), pixbuf=1, sensitive=2)
 
148
        cell = gtk.CellRendererText()
 
149
        cell.props.wrap_width = 200
 
150
        column.pack_start(cell)
 
151
        column.set_attributes(cell, text=0)
 
152
        self.model.set_visible_func(self.VisibleFunc)
 
153
        self.get_selection().connect('changed', self.SelectionChanged)
 
154
 
 
155
    def VisibleFunc(self, model, iter):
 
156
        return model[iter][3].Name in self.Plugins
 
157
 
 
158
    def Filter(self, plugins):
 
159
        self.Plugins = set(plugins)
 
160
        self.model.refilter()
 
161
 
 
162
    def SelectionChanged(self, selection):
 
163
        model, iter = selection.get_selected()
 
164
        if iter is None:
 
165
            return self.SelectionHandler(None)
 
166
        
 
167
        return self.SelectionHandler(model[iter][3])
 
168
 
 
169
class GroupView(gtk.TreeView):
 
170
    def __init__(self, name):
 
171
        self.model = gtk.ListStore(str, str)
 
172
        gtk.TreeView.__init__(self, self.model)
 
173
 
 
174
        self.SelectionHandler = None
 
175
 
 
176
        self.Visible = set()
 
177
        
 
178
        cell = gtk.CellRendererText()
 
179
        cell.props.ypad = 5
 
180
        cell.props.wrap_width = 200
 
181
        column = gtk.TreeViewColumn(name, cell, text=0)
 
182
        self.append_column(column)
 
183
 
 
184
        self.get_selection().connect('changed', self.SelectionChanged)
 
185
        self.hide_all()
 
186
        self.props.no_show_all = True
 
187
 
 
188
    def Update(self, items):
 
189
        self.model.clear()
 
190
 
 
191
        self.model.append([_('All'), 'All'])
 
192
 
 
193
        length = 0
 
194
        for item in items:
 
195
            self.model.append([item or _("General"), item])
 
196
            if item: # exclude "General" from count
 
197
                length += 1
 
198
 
 
199
        if length:
 
200
            self.show_all()
 
201
            self.props.no_show_all = False
 
202
        else:
 
203
            self.hide_all()
 
204
            self.props.no_show_all = True
 
205
 
 
206
    def SelectionChanged(self, selection):
 
207
        model, iter = selection.get_selected()
 
208
        if iter is None:
 
209
            return None
 
210
        
 
211
        return self.SelectionHandler(model[iter][1])
 
212
 
131
213
# Selector Buttons
132
214
#
133
215
class SelectorButtons(gtk.HBox):
149
231
        arrow = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_NONE)
150
232
        button = gtk.Button(label)
151
233
        button.set_relief(gtk.RELIEF_NONE)
152
 
        button.connect('clicked', callback, label)
153
 
        if len(self.get_children()) > 0:
 
234
        button.connect('clicked', self.on_button_clicked, callback)
 
235
        if self.get_children():
154
236
            self.pack_start(arrow, False, False)
155
237
            self.arrows.append(arrow)
156
238
        self.pack_start(button, False, False)
166
248
            self.arrows[pos-1].destroy()
167
249
            self.arrows.remove(self.arrows[pos-1])
168
250
 
 
251
    def on_button_clicked(self, widget, callback):
 
252
        callback(selector=True)
 
253
 
169
254
# Selector Box
170
255
#
171
256
class SelectorBox(gtk.ScrolledWindow):
230
315
        self.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
231
316
 
232
317
        self.store = gtk.ListStore(gobject.TYPE_STRING)
233
 
 
234
 
        self.custom_style = Style()
235
 
 
236
 
        viewport = gtk.Viewport()
237
 
        viewport.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.custom_style.BackgroundColor))
238
318
    
239
319
        self.view = gtk.TreeView(self.store)
240
320
        self.view.set_headers_visible(True)
242
322
        
243
323
        self.set_size_request(300, 300)
244
324
        
245
 
        viewport.add(self.view)
246
 
        self.add(viewport)
 
325
        self.add(self.view)
247
326
        
248
327
        self.select = self.view.get_selection()
249
328
        self.select.set_mode(gtk.SELECTION_SINGLE)
444
523
        self.add_events (gtk.gdk.BUTTON_PRESS_MASK)
445
524
        self.connect ("expose_event", self.expose)
446
525
        self.connect ("button_press_event", self.button_press)
447
 
        self.set_size_request (200, 200)
 
526
        self.set_size_request (196, 196)
448
527
 
449
528
        # Useful vars
450
 
        x0 = 25
451
 
        y0 = 33
452
 
        x1 = 175
453
 
        y1 = 125
454
 
        x2 = x0 + 40
455
 
        y2 = y0 + 27
456
 
        x3 = x1 - 40
457
 
        y3 = y1 - 27
 
529
        x0 = 16
 
530
        y0 = 24
 
531
        x1 = 181
 
532
        y1 = 133
 
533
        x2 = x0 + 39
 
534
        y2 = y0 + 26
 
535
        x3 = x1 - 39
 
536
        y3 = y1 - 26
458
537
        self._coords = (x0, y0, x1, y1, x2, y2, x3, y3)
459
538
 
460
539
    def draw (self, cr, width, height):
464
543
        cradius = self._cradius
465
544
        radius  = self._radius
466
545
 
 
546
        cr.set_line_width(1.0)
 
547
 
467
548
        # Top left edge
468
549
        cr.new_path ()
469
 
        cr.move_to (x0, y0 - cradius)
 
550
        cr.move_to (x0, y0 + cradius)
470
551
        cr.line_to (x0, y0)
471
552
        cr.line_to (x0 + cradius, y0)
472
553
        cr.arc (x0, y0, cradius, 0, pi / 2)
473
 
        self.set_color (cr, "TopLeft")
474
 
        cr.fill ()
 
554
        cr.close_path ()
 
555
        self.set_fill_color (cr, "TopLeft")
 
556
        cr.fill_preserve ()
 
557
        self.set_stroke_color (cr, "TopLeft")
 
558
        cr.stroke ()
475
559
        # Top right edge
476
560
        cr.new_path ()
477
561
        cr.move_to (x1, y0 + cradius)
478
562
        cr.line_to (x1, y0)
479
563
        cr.line_to (x1 - cradius, y0)
480
 
        cr.arc (x1, y0, cradius, pi / 2, pi)
481
 
        self.set_color (cr, "TopRight")
482
 
        cr.fill ()
 
564
        cr.arc_negative (x1, y0, cradius, pi, pi/2)
 
565
        cr.close_path ()
 
566
        self.set_fill_color (cr, "TopRight")
 
567
        cr.fill_preserve ()
 
568
        self.set_stroke_color (cr, "TopRight")
 
569
        cr.stroke ()
483
570
        # Bottom left edge
484
571
        cr.new_path ()
485
572
        cr.move_to (x0, y1 - cradius)
486
573
        cr.line_to (x0, y1)
487
574
        cr.line_to (x0 + cradius, y1)
488
 
        cr.arc (x0, y1, cradius, 3 * pi / 2, 2 * pi)
489
 
        self.set_color (cr, "BottomLeft")
490
 
        cr.fill ()
 
575
        cr.arc_negative (x0, y1, cradius, 2 * pi, 3 * pi / 2)
 
576
        cr.close_path ()
 
577
        self.set_fill_color (cr, "BottomLeft")
 
578
        cr.fill_preserve ()
 
579
        self.set_stroke_color (cr, "BottomLeft")
 
580
        cr.stroke ()
491
581
        # Bottom right edge
492
582
        cr.new_path ()
493
583
        cr.move_to (x1, y1 - cradius)
494
584
        cr.line_to (x1, y1)
495
585
        cr.line_to (x1 - cradius, y1)
496
586
        cr.arc (x1, y1, cradius, pi, 3 * pi / 2)
497
 
        self.set_color (cr, "BottomRight")
498
 
        cr.fill ()
 
587
        cr.close_path ()
 
588
        self.set_fill_color (cr, "BottomRight")
 
589
        cr.fill_preserve ()
 
590
        self.set_stroke_color (cr, "BottomRight")
 
591
        cr.stroke ()
499
592
        # Top edge
500
593
        cr.new_path ()
501
594
        cr.move_to (x2 + radius, y0)
503
596
        cr.arc (x3 - radius, y0, radius, 0, pi / 2)
504
597
        cr.line_to (x2 + radius, y0 + radius)
505
598
        cr.arc (x2 + radius, y0, radius, pi / 2, pi)
506
 
        self.set_color (cr, "Top")
507
 
        cr.fill ()
 
599
        cr.close_path ()
 
600
        self.set_fill_color (cr, "Top")
 
601
        cr.fill_preserve ()
 
602
        self.set_stroke_color (cr, "Top")
 
603
        cr.stroke ()
508
604
        # Bottom edge
509
605
        cr.new_path ()
510
606
        cr.move_to (x2 + radius, y1)
512
608
        cr.arc_negative (x3 - radius, y1, radius, 0, - pi / 2)
513
609
        cr.line_to (x2 + radius, y1 - radius)
514
610
        cr.arc_negative (x2 + radius, y1, radius, - pi / 2, pi)
515
 
        self.set_color (cr, "Bottom")
516
 
        cr.fill ()
 
611
        cr.close_path ()
 
612
        self.set_fill_color (cr, "Bottom")
 
613
        cr.fill_preserve ()
 
614
        self.set_stroke_color (cr, "Bottom")
 
615
        cr.stroke ()
517
616
        # Left edge
518
617
        cr.new_path ()
519
618
        cr.move_to (x0, y2 + radius)
521
620
        cr.arc_negative (x0, y3 - radius, radius, pi / 2, 0)
522
621
        cr.line_to (x0 + radius, y2 + radius)
523
622
        cr.arc_negative (x0, y2 + radius, radius, 0, 3 * pi / 2)
524
 
        self.set_color (cr, "Left")
525
 
        cr.fill ()
 
623
        cr.close_path ()
 
624
        self.set_fill_color (cr, "Left")
 
625
        cr.fill_preserve ()
 
626
        self.set_stroke_color (cr, "Left")
 
627
        cr.stroke ()
526
628
        # Right edge
527
629
        cr.new_path ()
528
630
        cr.move_to (x1, y2 + radius)
530
632
        cr.arc (x1, y3 - radius, radius, pi / 2, pi)
531
633
        cr.line_to (x1 - radius, y2 + radius)
532
634
        cr.arc (x1, y2 + radius, radius, pi, 3 * pi / 2)
533
 
        self.set_color (cr, "Right")
534
 
        cr.fill ()
 
635
        cr.close_path ()
 
636
        self.set_fill_color (cr, "Right")
 
637
        cr.fill_preserve ()
 
638
        self.set_stroke_color (cr, "Right")
 
639
        cr.stroke ()
535
640
 
536
 
    def set_color (self, cr, edge):
 
641
    def set_fill_color (self, cr, edge):
537
642
        '''Set painting color for edge'''
538
643
        cr.set_source_rgb (0.9, 0.9, 0.9)
539
644
 
 
645
    def set_stroke_color (self, cr, edge):
 
646
        '''Set stroke color for edge'''
 
647
        cr.set_source_rgb (0.45, 0.45, 0.45)
 
648
 
540
649
    def redraw (self, queue = False):
541
650
        '''Redraw internal surface'''
542
651
        alloc = self.get_allocation ()
655
764
        return "|".join (filter (lambda s: len (s) > 0, self._current))
656
765
    current = property (get_current, set_current)
657
766
 
658
 
    def set_color (self, cr, edge):
 
767
    def set_fill_color (self, cr, edge):
659
768
        '''Set painting color for edge'''
660
769
        if edge in self._current:
661
 
            cr.set_source_rgb (0, 1, 0)
662
 
        else:
663
 
            cr.set_source_rgb (0.90, 0, 0)
 
770
            cr.set_source_rgb (0.64, 1.0, 0.09)
 
771
        else:
 
772
            cr.set_source_rgb (0.80, 0.00, 0.00)
 
773
 
 
774
    def set_stroke_color (self, cr, edge):
 
775
        '''Set stroke color for edge'''
 
776
        if edge in self._current:
 
777
            cr.set_source_rgb (0.31, 0.60, 0.02)
 
778
        else:
 
779
            cr.set_source_rgb (0.64, 0.00, 0.00)
664
780
 
665
781
    def edge_clicked (self, widget, edge, event):
666
782
        if not len (edge):
678
794
 
679
795
    _settings = []
680
796
    _edges = {}
 
797
    _text  = {}
681
798
    _context = None
682
799
 
683
800
    def __init__ (self, context, settings=[]):
691
808
        if len (settings) <= 0:
692
809
            self.generate_setting_list ()
693
810
 
694
 
    def set_color (self, cr, edge):
 
811
    def set_fill_color (self, cr, edge):
695
812
        '''Set painting color for edge'''
696
 
        if self._edges.has_key(edge):
697
 
            cr.set_source_rgb (0, 1, 0)
698
 
        else:
699
 
            cr.set_source_rgb (0.90, 0, 0)
 
813
        if edge in self._edges:
 
814
            cr.set_source_rgb (0.64, 1.0, 0.09)
 
815
        else:
 
816
            cr.set_source_rgb (0.80, 0.00, 0.00)
 
817
 
 
818
    def set_stroke_color (self, cr, edge):
 
819
        '''Set stroke color for edge'''
 
820
        if edge in self._edges:
 
821
            cr.set_source_rgb (0.31, 0.60, 0.02)
 
822
        else:
 
823
            cr.set_source_rgb (0.64, 0.00, 0.00)
700
824
 
701
825
    def set_settings (self, value):
702
826
        self._settings = value
723
847
            for edge in edges:
724
848
                self._edges[edge] = setting
725
849
 
726
 
    def set_edge_settings (self, widget, setting, edge):
 
850
    def set_edge_setting (self, setting, edge):
727
851
        if not setting:
728
 
            if self._edges.has_key(edge):
 
852
            if edge in self._edges:
729
853
                self._edges.pop(edge)
730
854
            for setting in self._settings:
731
855
              value = setting.Value.split ("|")
748
872
        self.redraw (queue = True)
749
873
 
750
874
    def show_popup (self, widget, edge, event):
751
 
        menu = gtk.Menu ()
 
875
        self._text = {}
 
876
        comboBox = gtk.combo_box_new_text ()
752
877
 
753
 
        item = gtk.MenuItem (_("None"))
754
 
        item.connect ('activate', self.set_edge_settings, None, edge)
755
 
        menu.append (item)
 
878
        comboBox.append_text (_("None"))
 
879
        comboBox.set_active (0)
 
880
        i = 1
756
881
        for setting in self._settings:
757
 
            item = gtk.MenuItem ("%s: %s" % (setting.Plugin.ShortDesc, setting.ShortDesc))
758
 
            item.connect ('activate', self.set_edge_settings, setting, edge)
759
 
            menu.append (item)
760
 
 
761
 
        menu.show_all ()
762
 
        menu.popup (None, None, None, event.button, event.time)
 
882
            text = "%s: %s" % (setting.Plugin.ShortDesc, setting.ShortDesc)
 
883
            comboBox.append_text (text)
 
884
            self._text[text] = setting
 
885
 
 
886
            if edge in setting.Value.split ("|"):
 
887
                comboBox.set_active (i)
 
888
            i += 1
 
889
 
 
890
        comboBox.set_size_request (200, -1)
 
891
        comboBox.connect ('changed', self.combo_changed, edge)
 
892
 
 
893
        popup = Popup (self, child=comboBox, decorated=False, mouse=True, modal=False)
 
894
        popup.show_all()
 
895
        popup.connect ('focus-out-event', self.focus_out)
 
896
 
 
897
    def focus_out (self, widget, event):
 
898
        combo = widget.get_child ()
 
899
        if combo.props.popup_shown:
 
900
            return
 
901
        gtk_process_events ()
 
902
        widget.destroy ()
 
903
 
 
904
    def combo_changed (self, widget, edge):
 
905
        text = widget.get_active_text ()
 
906
        setting = None
 
907
        if text != _("None"):
 
908
            setting = self._text[text]
 
909
        self.set_edge_setting (setting, edge)
 
910
        popup = widget.get_parent ()
 
911
        popup.destroy ()
763
912
 
764
913
# Popup
765
914
#
766
915
class Popup (gtk.Window):
767
916
 
768
 
    def __init__ (self, parent, text):
 
917
    def __init__ (self, parent, text=None, child=None, decorated=True, mouse=False, modal=True):
769
918
        gtk.Window.__init__ (self, gtk.WINDOW_TOPLEVEL)
770
919
        self.set_type_hint (gtk.gdk.WINDOW_TYPE_HINT_UTILITY)
771
 
        self.set_position (gtk.WIN_POS_CENTER_ALWAYS)
 
920
        self.set_position (mouse and gtk.WIN_POS_MOUSE or gtk.WIN_POS_CENTER_ALWAYS)
772
921
        self.set_transient_for (parent.get_toplevel ())
773
 
        self.set_icon (parent.get_toplevel ().get_icon ())
774
 
        self.set_modal (True)
775
 
        label = gtk.Label (text)
776
 
        align = gtk.Alignment ()
777
 
        align.set_padding (20, 20, 20, 20)
778
 
        align.add (label)
779
 
        self.add (align)
780
 
        self.show_all ()
 
922
        self.set_modal (modal)
 
923
        self.set_decorated (decorated)
 
924
        if text:
 
925
            label = gtk.Label (text)
 
926
            align = gtk.Alignment ()
 
927
            align.set_padding (20, 20, 20, 20)
 
928
            align.add (label)
 
929
            self.add (align)
 
930
        elif child:
 
931
            self.add (child)
781
932
        gtk_process_events ()
782
933
 
783
934
    def destroy (self):
817
968
    def begin_key_grab (self, widget):
818
969
        self.add_events (gtk.gdk.KEY_PRESS_MASK)
819
970
        self.popup = Popup (self, _("Please press the new key combination"))
 
971
        self.popup.show_all()
820
972
        self.handler = self.popup.connect ("key-press-event",
821
973
                                           self.on_key_press_event)
822
974
        while gtk.gdk.keyboard_grab (self.popup.window) != gtk.gdk.GRAB_SUCCESS:
891
1043
 
892
1044
    match   = None
893
1045
 
894
 
    def __init__ (self, match = None):
 
1046
    def __init__ (self, entry = None):
895
1047
        '''Prepare widget'''
896
1048
        super (MatchButton, self).__init__ ()
897
1049
 
898
 
        self.match = match
 
1050
        self.entry = entry
 
1051
        self.match = entry.get_text()
899
1052
 
900
1053
        self.add (Image (name = gtk.STOCK_ADD, type = ImageStock,
901
1054
                         size = gtk.ICON_SIZE_BUTTON))
903
1056
 
904
1057
    def set_match (self, value):
905
1058
        self.match = value
906
 
        self.emit ("changed", self.match)
 
1059
        self.entry.set_text(value)
 
1060
        self.entry.activate()
907
1061
 
908
1062
    def get_xprop (self, regexp, proc = "xprop"):
909
1063
        proc = os.popen (proc)
971
1125
    def run_edit_dialog (self, widget):
972
1126
        '''Run dialog to generate a match'''
973
1127
 
 
1128
        self.match = self.entry.get_text ()
 
1129
 
974
1130
        dlg = gtk.Dialog (_("Edit match"))
975
1131
        dlg.set_position (gtk.WIN_POS_CENTER_ON_PARENT)
976
1132
        dlg.set_transient_for (self.get_parent ().get_toplevel ())
1033
1189
            invert   = check.get_active ()
1034
1190
            self.generate_match (type, value, relation, invert)
1035
1191
 
 
1192
class FileButton (gtk.Button):
 
1193
    __gsignals__    = {"changed" : (gobject.SIGNAL_RUN_FIRST,
 
1194
                                    gobject.TYPE_NONE,
 
1195
                                    [gobject.TYPE_STRING])}
 
1196
    _directory = False
 
1197
    _context   = None
 
1198
    _image     = False
 
1199
    _path      = ""
 
1200
 
 
1201
    def __init__ (self, context, entry, directory=False, image=False, path=""):
 
1202
        gtk.Button.__init__ (self)
 
1203
 
 
1204
        self._entry = entry
 
1205
        self._directory = directory
 
1206
        self._context = context
 
1207
        self._image = image
 
1208
        self._path = path
 
1209
 
 
1210
        Tooltips.set_tip(self, _("Browse..."))
 
1211
        self.set_image(gtk.image_new_from_stock(
 
1212
            gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON))
 
1213
        self.connect('clicked', self.open_dialog)
 
1214
 
 
1215
    def set_path (self, value):
 
1216
        self._path = value
 
1217
        self._entry.set_text (value)
 
1218
        self._entry.activate ()
 
1219
 
 
1220
    def create_filter(self):
 
1221
        filter = gtk.FileFilter ()
 
1222
        if self._image:
 
1223
            filter.set_name (_("Images"))
 
1224
            filter.add_pattern ("*.png")
 
1225
            filter.add_pattern ("*.jpg")
 
1226
            filter.add_pattern ("*.jpeg")
 
1227
            filter.add_pattern ("*.svg")
 
1228
        else:
 
1229
            filter.add_pattern ("*")
 
1230
            filter.set_name (_("File"))
 
1231
 
 
1232
        return filter
 
1233
 
 
1234
    def check_type (self, filename):
 
1235
        if filename.find (".") == -1:
 
1236
            return True
 
1237
        ext = filename.split (".") [-1]
 
1238
 
 
1239
        try:
 
1240
            mime = mimetypes.types_map [".%s" %ext]
 
1241
        except KeyError:
 
1242
            return True
 
1243
 
 
1244
        if self._image:
 
1245
            require = FeatureRequirement (self._context, 'imagemime:' + mime)
 
1246
            return require.Resolve ()
 
1247
 
 
1248
        return True
 
1249
 
 
1250
    def update_preview (self, widget):
 
1251
        path = widget.get_preview_filename ()
 
1252
        if path is None or os.path.isdir (path):
 
1253
            widget.get_preview_widget ().set_from_file (None)
 
1254
            return
 
1255
        try:
 
1256
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (path, 128, 128)
 
1257
        except gobject.GError:
 
1258
            return
 
1259
        widget.get_preview_widget ().set_from_pixbuf (pixbuf)
 
1260
 
 
1261
    def open_dialog (self, widget):
 
1262
        b = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)
 
1263
        if self._directory:
 
1264
            title = _("Open directory...")
 
1265
        else:
 
1266
            title = _("Open file...")
 
1267
 
 
1268
        chooser = gtk.FileChooserDialog (title = title, buttons = b)
 
1269
        if self._directory:
 
1270
            chooser.set_action (gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
 
1271
        else:
 
1272
            chooser.set_filter (self.create_filter ())
 
1273
 
 
1274
        if self._path and os.path.exists (self._path):
 
1275
            chooser.set_filename (self._path)
 
1276
        else:
 
1277
            chooser.set_current_folder (os.environ.get("HOME"))
 
1278
 
 
1279
        if self._image:
 
1280
            chooser.set_use_preview_label (False)
 
1281
            chooser.set_preview_widget (gtk.Image ())
 
1282
            chooser.connect ("selection-changed", self.update_preview)
 
1283
 
 
1284
        ret = chooser.run ()
 
1285
 
 
1286
        filename = chooser.get_filename ()
 
1287
        chooser.destroy ()
 
1288
        if ret == gtk.RESPONSE_OK:
 
1289
            if self._directory or self.check_type (filename):
 
1290
                self.set_path (filename)
 
1291
 
1036
1292
# About Dialog
1037
1293
#
1038
1294
class AboutDialog (gtk.AboutDialog):
1039
1295
    def __init__ (self, parent):
1040
1296
        gtk.AboutDialog.__init__ (self)
1041
 
        self.set_parent (parent)
 
1297
        self.set_transient_for (parent)
1042
1298
 
1043
1299
        self.set_name (_("CompizConfig Settings Manager"))
1044
1300
        self.set_version (Version)
1051
1307
        self.set_artists (["Andrew Wedderburn <andrew.wedderburn@gmail.com>",
1052
1308
                           "Patrick Niklaus <marex@opencompositing.org>",
1053
1309
                           "Gnome Icon Theme Team"])
1054
 
        self.set_icon (parent.get_icon())
1055
1310
        self.set_logo (IconTheme.load_icon("ccsm", 64, gtk.ICON_LOOKUP_FORCE_SVG))
1056
1311
        self.set_website ("http://www.compiz-fusion.org")
1057
1312
 
1068
1323
        self.set_position (gtk.WIN_POS_CENTER)
1069
1324
        self.set_markup (message)
1070
1325
        self.set_title (_("An error has occured"))
1071
 
        self.set_icon (parent.get_icon ())
1072
1326
        self.set_transient_for (parent)
1073
1327
        self.set_modal (True)
1074
1328
        self.show_all ()
1087
1341
        self.set_position (gtk.WIN_POS_CENTER)
1088
1342
        self.set_markup (message)
1089
1343
        self.set_title (_("Warning"))
1090
 
        self.set_icon (parent.get_icon ())
1091
1344
        self.set_transient_for (parent)
1092
1345
        self.connect_after ("response", lambda *args: self.destroy ())
1093
1346