Commits

Ali Afshar committed 06ba032

proto project tree. still sketching

Comments (0)

Files changed (10)

 if __name__ == '__main__':
     import gtk
     from gtkarchitect.view.main import ArchitectMainView
+    from gtkarchitect.model.project import Project
 
     v = ArchitectMainView()
+    v.set_project(Project())
     v.show()
     gtk.main()
 

gtkarchitect/gtkentities/__init__.py

 import gtk
 
 from ..model.definitions import EntityDefinition, entity_catalog
-from ..view.gadget import Gadget
+from ..view.gadget import Gadget, ContainerGadget
 from ..view.placeholder import Placeholder
 
 
         self.widget = gtk.Button()
         t.add(self.widget)
 
-class WindowGadget(Gadget):
+
+class WindowGadget(ContainerGadget):
 
     def create_ui(self):
         t = self.get_toplevel()
         self.widget = gtk.Frame()
         t.add(self.widget)
 
-    def fill_empty(self):
-        self.widget.add(Placeholder())
+
+class FrameGadget(ContainerGadget):
+
+    def create_ui(self):
+        t = self.get_toplevel()
+        self.widget = gtk.Frame('hello')
+        t.add(self.widget)
 
 
 entity_catalog.register_entity_def(
 )
 
 entity_catalog.register_entity_def(
-    'GTK2 Widgets', EntityDefinition('GtkButton', gadget_type=ButtonGadget)
+    'GTK Widgets', EntityDefinition('GtkFrame', gadget_type=FrameGadget)
 )
 

gtkarchitect/model/definitions.py

 Defines how widgets are displayed in gazpacho
 """
 
+from lxml.etree import Element
+
 from collections import defaultdict
 
 from .entity import get_entity_type
         self.editor_type = editor_type
         self.is_toplevel = is_toplevel
 
-    def create_new_element(self, project):
-        pass
+    def create_entity(self):
+        return Element('object', **{'class':self.entity_name})
 
 
 class EntityCatalog(object):
         self.entity_map[definition.entity_name] = definition
 
     def get_entity_def(self, name):
+        print 'ged', name, self.entity_map.get(name)
         return self.entity_map.get(name)
 
 entity_catalog = EntityCatalog()
 
 
 def get_entity_def(entity):
-    entity_catalog.get_entity_def(get_entity_type(entity))
+    return entity_catalog.get_entity_def(get_entity_type(entity))
 
 

gtkarchitect/model/project.py

 
 from lxml.etree import Element
 
-class Project(object):
+import gobject
+
+from kiwi.utils import gsignal
+
+
+class Project(gobject.GObject):
+
+    gsignal('entity-added', gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)
 
     def __init__(self, tree=None):
+        gobject.GObject.__init__(self)
         if tree is None:
             tree = Element('interface')
         self.tree = tree
 
+    def add_entity(self, entity, parent=None):
+        if parent is None:
+            parent = self.tree
+        parent.append(entity)
+        self.emit('entity-added', entity, parent)
+
+    def create_entity(self, definition, parent=None):
+        entity = definition.create_entity()
+        self.add_entity(entity, parent)
+
Add a comment to this file

gtkarchitect/utils/debug.py

Empty file added.

gtkarchitect/view/gadget.py

 
-import gtk
+import gtk, gobject
+
+from kiwi.utils import gsignal
 
 from base import Slave
 
 from ..controller.command import EntityPropertyChangeCommand
-
+from .placeholder import Placeholder
 
 class GadgetHolder(gtk.EventBox):
 
 
 class Gadget(Slave):
 
+    gsignal('placeholder-clicked', gobject.TYPE_PYOBJECT)
+
     def __init__(self, entity):
         self.entity = entity
+        self.placeholders = []
         Slave.__init__(self)
 
     def create_toplevel_widget(self):
     def fill_empty(self):
         pass
 
+    def register_placeholder(self, placeholder):
+        placeholder.connect('clicked', self._on_placeholder_clicked)
+        self.placeholders.append(placeholder)
+
     def set_prop(self, property, value):
         c = EntityPropertyChangeCommand(None)
         c.do(self.entity, property, value)
         return c
 
+    def _on_placeholder_clicked(self, placeholder):
+        print 'ph clicked'
+        self.emit('placeholder-clicked', placeholder)
+
+    def add_gadget(self, gadget):
+        p = self.placeholders.pop(0)
+        self.widget.remove(p)
+        p.unparent()
+        print gadget.get_toplevel()
+        self.widget.add(gadget.get_toplevel())
+        self.widget.show_all()
+
+
+class ContainerGadget(Gadget):
+
+    def fill_empty(self):
+        print 'fill empty'
+        p = Placeholder()
+        self.register_placeholder(p)
+        self.widget.add(p)
+        p.show()
+
 
 if __name__ == '__main__':
     from lxml.etree import Element, tostring

gtkarchitect/view/main.py

 
-import gtk
+import gtk, gobject
 
 from .base import MainView
 from .palette import Palette
 from .workspace import Workspace
+from .projecttree import ProjectTree
 
-from ..model.definitions import entity_catalog
+from ..model.definitions import entity_catalog, get_entity_def
 
 from .. import gtkentities
 
 class ArchitectMainView(MainView):
 
     def create_ui(self):
+        self.gadgets = {}
+
         palette = Palette(entity_catalog)
         workspace = Workspace()
+        projecttree = ProjectTree()
 
         p = gtk.HPaned()
         self.get_toplevel().add(p)
         p.pack1(palette.get_toplevel())
-        p.pack2(workspace.get_toplevel())
+        p2 = gtk.HPaned()
+        p.pack2(p2)
+        p2.pack1(workspace.get_toplevel())
+        p2.pack2(projecttree.get_toplevel())
 
         self.palette = palette
         self.workspace = workspace
+        self.projecttree = projecttree
         p.show_all()
 
-    def on_palette__entity_selected(self, palette, entity):
-        if entity.is_toplevel:
-            g = entity.gadget_type(entity)
-            g.fill_empty()
-            self.workspace.add_toplevel(g.get_toplevel())
-            self.workspace.show_all()
-            print 'top'
+    def on_palette__entity_selected(self, palette, entity_def):
+        if entity_def is not None:
+            if entity_def.is_toplevel:
+                self.project.create_entity(entity_def)
+                gobject.idle_add(self.palette.set_current_entity_def, None)
+
+    def set_project(self, project):
+        self.project = project
+        self.projecttree.set_project(project)
+        self.project.connect('entity-added', self._on_project_entity_added)
+
+
+    def _on_project_entity_added(self, project, entity, parent):
+        entity_def = get_entity_def(entity)
+        if entity_def.is_toplevel:
+            self.add_toplevel_entity(entity, entity_def)
         else:
-            pass
+            self.add_entity(entity, entity_def, parent)
 
+    def add_entity(self, entity, entity_def, parent):
+        parent_gadget = self.gadgets.get(parent)
+        gadget = entity_def.gadget_type(entity)
+        gadget.fill_empty()
+        self.register_gadget(gadget)
+        parent_gadget.add_gadget(gadget)
+        self.projecttree.add_entity(entity, parent)
+
+    def add_toplevel_entity(self, entity, entity_def):
+        g = entity_def.gadget_type(entity)
+        self.register_gadget(g)
+        g.fill_empty()
+        self.workspace.add_toplevel(g.get_toplevel())
+        self.workspace.show_all()
+        self.projecttree.add_entity(entity, None)
+        print 'top'
+
+    def register_gadget(self, gadget):
+        self.gadgets[gadget.entity] = gadget
+        gadget.connect('placeholder-clicked',
+                            self._on_gadget_placeholder_clicked)
+        
+    def _on_gadget_placeholder_clicked(self, gadget, placeholder):
+        entity_def = self.palette.current_entity_def
+        if entity_def is None:
+            print 'should select'
+        else:
+            print 'adding ed;'
+            self.project.create_entity(entity_def, gadget.entity)
+

gtkarchitect/view/palette.py

     gsignal('entity-selected', gobject.TYPE_PYOBJECT)
 
     def create_ui(self, catalog):
+        self.current_entity_def = None
+
         self.palettes = {}
 
         t = self.get_toplevel()
         self.buttons = gtk.VBox()
-        
+
         self.current_label = gtk.Label()
         t.pack_start(self.current_label, expand=False)
 
         self.sections.set_current_page(self.sections.page_num(entity_list))
 
     def on_entity_selected(self, section, entity_def):
-        print entity_def
-        self.current_label.set_text(entity_def.entity_name)
+        self.set_current_entity_def(entity_def)
+
+    def set_current_entity_def(self, entity_def):
+        print entity_def, 'eeee'
+        self.current_entity_def = entity_def
         self.emit('entity-selected', entity_def)
+        if entity_def is not None:
+            current_text = entity_def.entity_name
+        else:
+            current_text = ''
+        print current_text
+        self.current_label.set_text(current_text)
 
 

gtkarchitect/view/placeholder.py

 from gazpacho.popup import PlaceholderPopup
 from gazpacho.util import get_parent
 
+from kiwi.utils import gsignal
+
 placeholder_xpm = [
     # columns rows colors chars-per-pixel
     "8 8 2 1",
 MIN_WIDTH = MIN_HEIGHT = 20
 
 class Placeholder(gtk.Widget):
+
+    gsignal('clicked')
+    gsignal('shiftclicked')
+
     def __init__(self):
         gtk.Widget.__init__(self)
 
 
         self.window.set_back_pixmap(self._pixmap, False)
 
-    def get_project(self):
-        """Get the project to which this placeholder belong."""
-        project = None
-        parent = get_parent(self)
-        if parent:
-            project = parent.project
-        return project
-
     def do_size_allocate(self, allocation):
         self.allocation = allocation
         if self.flags() & gtk.REALIZED:
         return False
 
     def do_motion_notify_event(self, event):
-        Cursor.set_for_widget_adaptor(event.window,
-                                      get_utility(IGazpachoApp).add_class)
+        #Cursor.set_for_widget_adaptor(event.window,
+        #                              get_utility(IGazpachoApp).add_class)
 
         return False
 
             self.grab_focus()
 
         if event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
-            app = get_utility(IGazpachoApp)
+            
+            self.emit('clicked')
+            return
+            #app = get_utility(IGazpachoApp)
             # A widget type is selected in the palette.
             # Add a new widget of that type
-            if app.add_class:
-                gapi.create_gadget(app.get_current_project(), app.add_class,
-                                   self)
+            #if app.add_class:
+            #    gapi.create_gadget(app.get_current_project(), app.add_class,
+            #                       self)
 
             # Shift clicking circles through the widget tree by
             # choosing the parent of the currently selected widget.
-            elif event.state & gtk.gdk.SHIFT_MASK:
+            if event.state & gtk.gdk.SHIFT_MASK:
                 parent = get_parent(self)
                 parent.project.selection.circle(self)
 

gtkarchitect/view/projecttree.py

+
+from kiwi.ui.objectlist import ObjectTree, Column
+
+from ..model.entity import get_entity_type
+from .base import Slave
+
+
+class EntityColumn(Column):
+
+    def get_attribute(self, entity, *args):
+        return '%s %s' % (entity.tag, get_entity_type(entity))
+
+class ProjectTree(Slave):
+
+    def create_ui(self):
+        self.tree = ObjectTree(EntityColumn('name'))
+        t = self.get_toplevel()
+        t.add(self.tree)
+
+    def set_project(self, project):
+        self.project = project
+        self.add_entity(self.project.tree)
+
+    def add_entity(self, entity, parent=None):
+        self.tree.append(parent, entity)
+        for child in entity:
+            self.add_entity(child, entity)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.