diff -Naur sketch.orig/Sketch/Pixmaps/MiniEyeClosed.xpm sketch.layers/Sketch/Pixmaps/MiniEyeClosed.xpm --- sketch.orig/Sketch/Pixmaps/MiniEyeClosed.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniEyeClosed.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniEyeClosed_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" ", +" +++ ", +" ++.+.++ ", +" ++.+++++.+ ", +"+.++++++++++", +"+++++++++++.", +"..++++++++..", +"....++++....", +"++........++", +" ++....++ ", +" ++++ ", +" "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniEyeOpen.xpm sketch.layers/Sketch/Pixmaps/MiniEyeOpen.xpm --- sketch.orig/Sketch/Pixmaps/MiniEyeOpen.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniEyeOpen.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniEyeOpen_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" ", +" ++++ ", +" ++....++ ", +" +..+..+..+ ", +"+.++....++.+", +".+++....+++.", +"..+++..+++..", +"++..++++..++", +" ++....++ ", +" ++++ ", +" ", +" "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniLockClosed.xpm sketch.layers/Sketch/Pixmaps/MiniLockClosed.xpm --- sketch.orig/Sketch/Pixmaps/MiniLockClosed.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniLockClosed.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniLockClosed_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" +....+ ", +"+......+ ", +"+..++..+ ", +"+..++..+ ", +"........+ ", +"........+ ", +"...++...+ ", +"...++...+ ", +"........+ ", +"...++...+ ", +"........+ ", +"+++++++++ "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniLockOpen.xpm sketch.layers/Sketch/Pixmaps/MiniLockOpen.xpm --- sketch.orig/Sketch/Pixmaps/MiniLockOpen.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniLockOpen.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniLockOpen_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" +....+ ", +" +......+", +" +..++..+", +"+++++..++..+", +"........++++", +"........+ ", +"...++...+ ", +"...++...+ ", +"........+ ", +"...++...+ ", +"........+ ", +"+++++++++ "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniOutlineOff.xpm sketch.layers/Sketch/Pixmaps/MiniOutlineOff.xpm --- sketch.orig/Sketch/Pixmaps/MiniOutlineOff.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniOutlineOff.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniOutlineOff_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" +....+ ", +"+......+ ", +"........+++ ", +"..........+ ", +".....++++.+ ", +".....++++.+ ", +"+....++++.+ ", +" +...++++.+ ", +" ++.++++.+ ", +" +.++++.+ ", +" +......+ ", +" ++++++++ "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniOutlineOn.xpm sketch.layers/Sketch/Pixmaps/MiniOutlineOn.xpm --- sketch.orig/Sketch/Pixmaps/MiniOutlineOn.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniOutlineOn.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniOutlineOn_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" +....+ ", +"+.++++.+ ", +".+ ++++.+++ ", +".+ +......+ ", +".+ +.++.+.+ ", +".+ +.++.+.+ ", +"+.++.+.++.+ ", +" +....+ +.+ ", +" ++.+ +.+ ", +" +.++++.+ ", +" +......+ ", +" ++++++++ "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniPrintOff.xpm sketch.layers/Sketch/Pixmaps/MiniPrintOff.xpm --- sketch.orig/Sketch/Pixmaps/MiniPrintOff.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniPrintOff.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniPrintOff_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +"++++++++ ", +"+......++++ ", +"+..+++....+ ", +"+...++....+ ", +"++...+...++ ", +"++.......+ ", +"++.+...+.+ ", +"++.......+ ", +"++...+...++ ", +"+...+++...+ ", +"+.........+ ", +"+++++++++++ "}; diff -Naur sketch.orig/Sketch/Pixmaps/MiniPrintOn.xpm sketch.layers/Sketch/Pixmaps/MiniPrintOn.xpm --- sketch.orig/Sketch/Pixmaps/MiniPrintOn.xpm Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/Pixmaps/MiniPrintOn.xpm Fri Jan 10 18:04:36 2003 @@ -0,0 +1,18 @@ +/* XPM */ +static char * MiniPrintOn_xpm[] = { +"12 12 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" +++++++ ", +" +.....+ ", +" +.+++..++ ", +" +.+++...+ ", +" +.+++++.+ ", +" +.+++++.+ ", +" +.+++++.+ ", +" +.+++++.+ ", +" +.+++++.+ ", +" +.+++++.+ ", +" +.......+ ", +" +++++++++ "}; diff -Naur sketch.orig/Sketch/UI/layerpanel.py sketch.layers/Sketch/UI/layerpanel.py --- sketch.orig/Sketch/UI/layerpanel.py Thu Jan 1 01:00:00 1970 +++ sketch.layers/Sketch/UI/layerpanel.py Fri Jan 10 17:55:43 2003 @@ -0,0 +1,389 @@ +# Sketch - A Python-based interactive drawing program +# Copyright (C) 1997, 1998, 2000 by Bernhard Herzog +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +# A dialog to rearrange the layers of the document and change some of +# their properties. + + + +from types import StringType + +import gtk + +import Sketch +from Sketch import _, Rect, Trafo +from Sketch.Graphics import StandardColors, EmptyLineStyle, PropertyStack,\ + EmptyPattern +import Sketch, Sketch.Graphics + +from gtkmisc import SketchDrawingArea +from skpanel import SketchPanel +from gtkdevice import PatternDevice +import skpixmaps +pixmaps = skpixmaps.pixmaps + +property_defs = [ + ('visible', 'MiniEyeOpen', "convert_visible"), + ('printable', 'MiniPrintOn', "convert_printable"), + ('locked', 'MiniLockOpen', "convert_locked"), + ('outlined', 'MiniOutlineOn', "convert_outlined"), + ('outline_color', 'MiniEyeOpen', "convert_color"), +] + +# returns a pixmap with the corresponding color. +class PreviewColorFactory(PatternDevice): + + def __init__(self): + PatternDevice.__init__(self, gradient_steps = + Sketch.Base.preferences.gradient_steps_editor) + + def CreateColorPreview(self, color, width = 16, height = 16): + pixmap = gtk.create_pixmap(self.window, width, height) + self.drawable = pixmap + doc_to_win = Trafo(1, 0, 0, -1, 0, height) + win_to_doc = doc_to_win.inverse() + self.SetViewportTransform(1.0, doc_to_win, win_to_doc) + # fill_rect = Rect(0, 0, width, height) + self.SetFillColor(color) + self.FillRectangle(0, 0, width, height) + self.drawable = self.window + return pixmap + +maskbitmap = None + +class LayerList(gtk.GtkCList): + + def __init__(self, layerPanel, previewFactory): + self.layerPanel = layerPanel + self.previewFactory = previewFactory + self.layersList = None + + titles = ['Name'] + for name, pixmap, converter in property_defs: + titles.append(getattr(pixmaps, pixmap)) + + gtk.GtkCList.__init__(self, len(titles)) + for index in range(len(titles)): + title = titles[index] + if isinstance(title, StringType): + self.set_column_title(index, title) + else: + pixmap, mask = title + pixmap = gtk.GtkPixmap(pixmap, mask) + self.set_column_widget(index, pixmap) + self.column_titles_show() + ## self.set_selection_mode(SELECTION_MULTIPLE) + ## self.set_selection_mode(SELECTION_BROWSE) + self.set_reorderable( 1 ) + self.connect( "select_row", self.SelectionMade ) + + # fill the style list with the styles + def SetLayerList(self, layersList): + self.layersList = layersList ## I need it later + self.freeze() + try: + self.clear() + row = 0 + for layer in layersList: + self.append([''] * (len(property_defs) + 1)) + if layer.Name(): + text = layer.Name() + else: + text = '<unnamed>' + self.set_text(row, 0, text) + for col in range(len(property_defs)): + name, pixmap, converter = property_defs[col] + if hasattr(layer, name): + value = getattr(self, converter)(getattr(layer, name)) + else: + value = '' + if not isinstance(value, StringType): + pixmap, mask = value + self.set_pixmap(row, col+1, pixmap, mask) + else: + self.set_text(row, col + 1, value) + row += 1 + + self.set_column_width(0, self.optimal_column_width(0)) + finally: + self.thaw() + + def convert_dummy(self, value): + return '*' + + def convert_visible(self, value): + return getattr(pixmaps, ('MiniEyeClosed', 'MiniEyeOpen')[value]) + + def convert_printable(self, value): + return getattr(pixmaps, ('MiniPrintOff', 'MiniPrintOn')[value]) + + def convert_locked(self, value): + return getattr(pixmaps, ('MiniLockOpen', 'MiniLockClosed')[value]) + + def convert_outlined(self, value): + return getattr(pixmaps, ('MiniOutlineOff', 'MiniOutlineOn')[value]) + + def convert_color(self, value): + return self.previewFactory.CreateColorPreview(value), maskbitmap + + def SelectionMade( self, data, row, column, event ): + ## print "Selection: ", row, column, event, data + ## print "time, ", event.time + + idx = row + + layer = self.layerPanel.GetDocument().layers[idx] + + name = layer.name + visible = layer.visible + printable = layer.printable + locked = layer.locked + outlined = layer.outlined + outline_color = layer.outline_color + + if column>=1 and column<=4: + if column == 1: + visible = not visible + elif column == 2: + printable = not printable + elif column == 3: + locked = not locked + elif column == 4: + outlined = not outlined + + self.layerPanel.GetDocument().SetLayerState( idx, + visible, printable, + locked, outlined ) + elif column == 5: + self.layerPanel.GetDocument().SetLayerColor( idx, outline_color ); + + +class LayerPanel(SketchPanel): + + def __init__(self, context): + SketchPanel.__init__(self, context, _("Layers")) + self.context.Subscribe(Sketch.Base.const.SELECTION, + self.layersChanged) + self.context.Subscribe(Sketch.Base.const.LAYER, + self.layersChanged) + self.context.Subscribe(Sketch.Base.const.TRANSACTION_END, + self.layersChanged) + self.layersChanged() + + def destroyed(self, *args): + self.context.Unsubscribe(Sketch.Base.const.SELECTION, + self.layersChanged) + self.context.Unsubscribe(Sketch.Base.const.LAYER, + self.layersChanged) + self.context.Unsubscribe(Sketch.Base.const.TRANSACTION_END, + self.layersChanged) + apply(SketchPanel.destroyed, (self,) + args) + + def build_window(self): + vbox = self.vbox + self.previewFactory = PreviewColorFactory() + + swin = gtk.GtkScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + self.currentLayers = LayerList( self, self.previewFactory) + swin.add(self.currentLayers) + + # vbox.add(swin); + vbox.pack_start(swin) + + hbox = gtk.GtkHBox(); + + button = gtk.GtkButton(_("New")) + button.connect("clicked", self.NewLayer) + hbox.pack_start( button ) + + button = gtk.GtkButton(_("Up")) + button.connect("clicked", self.UpLayer) + hbox.pack_start( button ) + + button = gtk.GtkButton(_("Down")) + button.connect("clicked", self.DownLayer) + hbox.pack_start( button ) + + button = gtk.GtkButton(_("Delete")) + button.connect("clicked", self.DeleteLayer) + hbox.pack_start( button ) + + vbox.pack_start( hbox, expand=0 ) + vbox.show_all() + + vbox.realize() + + # after realize give window context to preview factory + self.previewFactory.init_gc(vbox.get_window()) + global maskbitmap + maskbitmap = gtk.create_bitmap_from_data(vbox.get_window(), '\377'*32, + 16, 16) + + def HasDocument(self): + if self.context.HasEditor(): + return 1 + else: + return 0 + + def GetDocument(self): + return self.context.document + + + def layersChanged(self, *args): + if self.HasDocument(): + self.currentLayers.SetLayerList(self.GetDocument().layers) + else: + self.currentLayers.SetLayerList([]) + + + ## returns a list of indices for the currently selected layers. + ## When object/s are selected, the selected layers are all layers, + ## the objects are on. + ## When no object is selected, the selected layer is the active layer. + def GetSelectedLayers( self ): + return (self.getDocument().ActiveLayerIdx) + + + ## returns the first selected layer + def GetSelectedLayer( self ): + return getSelectedLayers()[0] + + ## set the selected layer + ## if object/s are selected, they are moved to the layer. + ## if no objecs are selected, the active layer is set to layer. + ## @see getSelectedLayer + def SetSelectedLayer( self, layer ): + self.getDocument().active_layer = layer + + + def rename_layer(self, event = None): + pass +## if event is not None: +## self.set_event_context(event) +## name = GetName(self.top, self.context_layer.Name()) +## if name != None: +## self.document.SetLayerName(self.context_idx, name) + + def DeleteLayer( self, event = None ): + self.GetDocument().DeleteLayer( self.GetSelectedLayer() ) + + def NewLayer(self, event = None ): + self.GetDocument.NewLayer() + + def UpLayer(self, event = None ): + self.GetDocument().MoveLayerUp( self.GetSelectedLayer() ) + + def DownLayer(self, event = None ): + self.GetDocument().MoveLayerDown( self.GetSelectedLayer() ) + + + + def move_selection_here(self): + self.getDocument().MoveSelectionToLayer(self.context_idx) + + def can_move_selection(self): + return not self.context_layer.Locked() and self.document.HasSelection() + + def is_not_locked(self): + return not self.context_layer.Locked() + + def select_layer(self, mode): + self.getDocument().SelectLayer(self.context_idx, mode) + + + +class LayerPropertyDialog: + + def __init__(self, context, layer ): + SketchPanel.__init__(self, context, layer.name ) + self.context.Subscribe(Sketch.Base.const.LAYER, + self.layerChanged) + self.layerChanged() + + def destroyed(self, *args): + self.context.Unsubscribe(Sketch.Base.const.LAYER, + self.layersChanged) + self.context.Unsubscribe(Sketch.Base.const.TRANSACTION_END, + self.layersChanged) + apply(SketchPanel.destroyed, (self,) + args) + + def build_window(self): + vbox = self.vbox + + hbox = gtk.GtkHBox(); + + button = gtk.GtkButton(_("OK")) + button.connect("clicked", self.OK) + hbox.pack_start( button ) + + button = gtk.GtkButton(_("Cancel")) + button.connect("clicked", self.Cancel) + hbox.pack_start( button ) + + button = gtk.GtkButton(_("Apply")) + button.connect("clicked", self.Apply) + hbox.pack_start( button ) + + vbox.pack_start( hbox, expand=0 ) + vbox.show_all() + + vbox.realize() + + + def OK(self, event = None ): + self.Apply( event ) + self.close() + + def Cancel(self, event = None ): + self.close() + + def layerChanged(self, *args): + pass + +##class GetNameDlg(SKModal): + +## title = _("Name") + +## def __init__(self, master, name, **kw): +## self.name = name +## apply(SKModal.__init__, (self, master), kw) + +## def build_dlg(self): +## top = self.top + +## frame = Frame(top) +## frame.pack(side = BOTTOM, fill = BOTH, expand = 1) +## button = Button(frame, text = _("OK"), command = self.ok) +## button.pack(side = LEFT, expand = 1) +## button = Button(frame, text = _("Cancel"), command = self.cancel) +## button.pack(side = RIGHT, expand = 1) + +## self.label = Label(top, text = _("Name")) +## self.label.pack(side = LEFT) + +## self.entry = MyEntry(top, command = self.ok) +## self.entry.pack(side = RIGHT, expand = 1, fill = X) +## self.entry.SetText(self.name) + +## def ok(self, *args): +## self.close_dlg(self.entry.get()) + +##def GetName(master, name): +## dlg = GetNameDlg(master, name) +## return dlg.RunDialog() diff -Naur sketch.orig/Sketch/UI/skapp.py sketch.layers/Sketch/UI/skapp.py --- sketch.orig/Sketch/UI/skapp.py Thu Aug 1 15:43:44 2002 +++ sketch.layers/Sketch/UI/skapp.py Fri Jan 10 17:59:14 2003 @@ -494,6 +494,14 @@ Sketch.Editor.Add(Sketch.Editor.Command('object_panel', _("Object Panel"), object_panel)) +def layer_panel(context): + import layerpanel + context.application.InstantiatePanel(layerpanel.LayerPanel) + +Sketch.Editor.Add(Sketch.Editor.Command('layer_panel', + _("Layer Panel"), layer_panel)) + + # import some development commands import devcmds diff -Naur sketch.orig/Sketch/UI/skpixmaps.py sketch.layers/Sketch/UI/skpixmaps.py --- sketch.orig/Sketch/UI/skpixmaps.py Fri Jul 13 22:23:47 2001 +++ sketch.layers/Sketch/UI/skpixmaps.py Fri Jan 10 17:58:25 2003 @@ -69,7 +69,12 @@ 'MiniFill', 'MiniTransform', 'MiniLine', 'MiniWidth', 'MiniCap', 'MiniJoin', 'MiniDashes', 'MiniArrowRight', 'MiniArrowLeft', - 'MiniFont', 'MiniFontSize'] + 'MiniFont', 'MiniFontSize', + + 'MiniEyeOpen', 'MiniEyeClosed', + 'MiniLockOpen', 'MiniLockClosed', + 'MiniOutlineOn', 'MiniOutlineOff', + 'MiniPrintOn', 'MiniPrintOff',] class SketchPixmaps: diff -Naur sketch.orig/Sketch/UI/toolbox.py sketch.layers/Sketch/UI/toolbox.py --- sketch.orig/Sketch/UI/toolbox.py Thu Aug 1 15:43:44 2002 +++ sketch.layers/Sketch/UI/toolbox.py Fri Jan 10 18:00:36 2003 @@ -157,7 +157,7 @@ # writers, so it should at least require a config-flag. descr = ['message_panel', 'reload_panel', None, 'property_panel', 'fill_panel', 'meta_panel', - 'palette_panel', 'object_panel'] + 'palette_panel', 'object_panel', 'layer_panel'] tree = Sketch.Editor.BuildMenuTree('<toolbox>', descr) return menu.make_menu(tree, None, self.context)