128
130
cr.set_source_rgba(r, g, b, a)
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)
139
self.SelectionHandler = None
141
self.Plugins = set(plugins)
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])
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)
155
def VisibleFunc(self, model, iter):
156
return model[iter][3].Name in self.Plugins
158
def Filter(self, plugins):
159
self.Plugins = set(plugins)
160
self.model.refilter()
162
def SelectionChanged(self, selection):
163
model, iter = selection.get_selected()
165
return self.SelectionHandler(None)
167
return self.SelectionHandler(model[iter][3])
169
class GroupView(gtk.TreeView):
170
def __init__(self, name):
171
self.model = gtk.ListStore(str, str)
172
gtk.TreeView.__init__(self, self.model)
174
self.SelectionHandler = None
178
cell = gtk.CellRendererText()
180
cell.props.wrap_width = 200
181
column = gtk.TreeViewColumn(name, cell, text=0)
182
self.append_column(column)
184
self.get_selection().connect('changed', self.SelectionChanged)
186
self.props.no_show_all = True
188
def Update(self, items):
191
self.model.append([_('All'), 'All'])
195
self.model.append([item or _("General"), item])
196
if item: # exclude "General" from count
201
self.props.no_show_all = False
204
self.props.no_show_all = True
206
def SelectionChanged(self, selection):
207
model, iter = selection.get_selected()
211
return self.SelectionHandler(model[iter][1])
131
213
# Selector Buttons
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)
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)
458
537
self._coords = (x0, y0, x1, y1, x2, y2, x3, y3)
460
539
def draw (self, cr, width, height):
464
543
cradius = self._cradius
465
544
radius = self._radius
546
cr.set_line_width(1.0)
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")
555
self.set_fill_color (cr, "TopLeft")
557
self.set_stroke_color (cr, "TopLeft")
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")
564
cr.arc_negative (x1, y0, cradius, pi, pi/2)
566
self.set_fill_color (cr, "TopRight")
568
self.set_stroke_color (cr, "TopRight")
483
570
# Bottom left edge
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")
575
cr.arc_negative (x0, y1, cradius, 2 * pi, 3 * pi / 2)
577
self.set_fill_color (cr, "BottomLeft")
579
self.set_stroke_color (cr, "BottomLeft")
491
581
# Bottom right edge
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")
588
self.set_fill_color (cr, "BottomRight")
590
self.set_stroke_color (cr, "BottomRight")
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")
600
self.set_fill_color (cr, "Top")
602
self.set_stroke_color (cr, "Top")
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")
612
self.set_fill_color (cr, "Bottom")
614
self.set_stroke_color (cr, "Bottom")
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")
624
self.set_fill_color (cr, "Left")
626
self.set_stroke_color (cr, "Left")
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")
636
self.set_fill_color (cr, "Right")
638
self.set_stroke_color (cr, "Right")
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)
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)
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)
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)
663
cr.set_source_rgb (0.90, 0, 0)
770
cr.set_source_rgb (0.64, 1.0, 0.09)
772
cr.set_source_rgb (0.80, 0.00, 0.00)
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)
779
cr.set_source_rgb (0.64, 0.00, 0.00)
665
781
def edge_clicked (self, widget, edge, event):
666
782
if not len (edge):
691
808
if len (settings) <= 0:
692
809
self.generate_setting_list ()
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)
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)
816
cr.set_source_rgb (0.80, 0.00, 0.00)
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)
823
cr.set_source_rgb (0.64, 0.00, 0.00)
701
825
def set_settings (self, value):
702
826
self._settings = value
748
872
self.redraw (queue = True)
750
874
def show_popup (self, widget, edge, event):
876
comboBox = gtk.combo_box_new_text ()
753
item = gtk.MenuItem (_("None"))
754
item.connect ('activate', self.set_edge_settings, None, edge)
878
comboBox.append_text (_("None"))
879
comboBox.set_active (0)
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)
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
886
if edge in setting.Value.split ("|"):
887
comboBox.set_active (i)
890
comboBox.set_size_request (200, -1)
891
comboBox.connect ('changed', self.combo_changed, edge)
893
popup = Popup (self, child=comboBox, decorated=False, mouse=True, modal=False)
895
popup.connect ('focus-out-event', self.focus_out)
897
def focus_out (self, widget, event):
898
combo = widget.get_child ()
899
if combo.props.popup_shown:
901
gtk_process_events ()
904
def combo_changed (self, widget, edge):
905
text = widget.get_active_text ()
907
if text != _("None"):
908
setting = self._text[text]
909
self.set_edge_setting (setting, edge)
910
popup = widget.get_parent ()
766
915
class Popup (gtk.Window):
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)
922
self.set_modal (modal)
923
self.set_decorated (decorated)
925
label = gtk.Label (text)
926
align = gtk.Alignment ()
927
align.set_padding (20, 20, 20, 20)
781
932
gtk_process_events ()
783
934
def destroy (self):
1033
1189
invert = check.get_active ()
1034
1190
self.generate_match (type, value, relation, invert)
1192
class FileButton (gtk.Button):
1193
__gsignals__ = {"changed" : (gobject.SIGNAL_RUN_FIRST,
1195
[gobject.TYPE_STRING])}
1201
def __init__ (self, context, entry, directory=False, image=False, path=""):
1202
gtk.Button.__init__ (self)
1205
self._directory = directory
1206
self._context = context
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)
1215
def set_path (self, value):
1217
self._entry.set_text (value)
1218
self._entry.activate ()
1220
def create_filter(self):
1221
filter = gtk.FileFilter ()
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")
1229
filter.add_pattern ("*")
1230
filter.set_name (_("File"))
1234
def check_type (self, filename):
1235
if filename.find (".") == -1:
1237
ext = filename.split (".") [-1]
1240
mime = mimetypes.types_map [".%s" %ext]
1245
require = FeatureRequirement (self._context, 'imagemime:' + mime)
1246
return require.Resolve ()
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)
1256
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (path, 128, 128)
1257
except gobject.GError:
1259
widget.get_preview_widget ().set_from_pixbuf (pixbuf)
1261
def open_dialog (self, widget):
1262
b = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)
1264
title = _("Open directory...")
1266
title = _("Open file...")
1268
chooser = gtk.FileChooserDialog (title = title, buttons = b)
1270
chooser.set_action (gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
1272
chooser.set_filter (self.create_filter ())
1274
if self._path and os.path.exists (self._path):
1275
chooser.set_filename (self._path)
1277
chooser.set_current_folder (os.environ.get("HOME"))
1280
chooser.set_use_preview_label (False)
1281
chooser.set_preview_widget (gtk.Image ())
1282
chooser.connect ("selection-changed", self.update_preview)
1284
ret = chooser.run ()
1286
filename = chooser.get_filename ()
1288
if ret == gtk.RESPONSE_OK:
1289
if self._directory or self.check_type (filename):
1290
self.set_path (filename)
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)
1043
1299
self.set_name (_("CompizConfig Settings Manager"))
1044
1300
self.set_version (Version)