Skip to content

Commit

Permalink
limited support for subsections
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjanss committed Feb 27, 2013
1 parent 22beb92 commit 6a6c346
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 1 addition & 3 deletions camelot/admin/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# project-camelot@conceptive.be
#
# ============================================================================
from camelot.view.model_thread import model_function

class Section(object):
"""A Section as displayed in the left pane of the application. Each Section
Expand Down Expand Up @@ -52,7 +51,6 @@ def get_icon(self):
from camelot.view.art import Icon
return self.icon or Icon('tango/32x32/apps/system-users.png')

@model_function
def get_items(self):
return self.items

Expand Down Expand Up @@ -86,7 +84,7 @@ def get_modes(self):
def structure_to_section_items(structure, application_admin):

def rule(element):
if isinstance(element, (SectionItem,)):
if isinstance(element, (SectionItem, Section)):
return element
return SectionItem(element, application_admin)

Expand Down
29 changes: 20 additions & 9 deletions camelot/view/controls/navpane2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from PyQt4.QtGui import QDockWidget
from PyQt4.QtGui import QVBoxLayout

from camelot.admin.action.application_action import ApplicationActionGuiContext
from camelot.admin.action.application_action import ApplicationActionGuiContext
from camelot.admin.section import Section, SectionItem
from camelot.core.utils import variant_to_pyobject
from camelot.view.model_thread import post
from camelot.view.controls.modeltree import ModelItem
Expand Down Expand Up @@ -66,25 +67,33 @@ def __init__(self, parent, section, workspace):
post( section.get_items, self.set_items )

@QtCore.pyqtSlot(object)
def set_items(self, items):
def set_items(self, items, parent = None):
logger.debug('setting items for current navpane section')
section_tree = self.findChild(QtGui.QWidget, 'SectionTree')
self._items = items
if section_tree:
section_tree.clear()
section_tree.clear_model_items()
if section_tree:
if parent == None:
# take a copy, so the copy can be extended
self._items = list(i for i in items)
section_tree.clear()
section_tree.clear_model_items()
parent = section_tree

if not items: return

for item in items:
label = item.get_verbose_name()
icon = item.get_icon()
model_item = ModelItem( section_tree,
model_item = ModelItem( parent,
[unicode(label)],
item )
if icon:
model_item.set_icon(icon.getQIcon())
section_tree.modelitems.append( model_item )
section_tree.modelitems.append( model_item )
if isinstance( item, Section ):
child_items = item.get_items()
self.set_items( child_items, parent = model_item )
self._items.extend( child_items )

section_tree.resizeColumnToContents( 0 )

def create_context_menu(self, point):
Expand Down Expand Up @@ -116,7 +125,9 @@ def _run_current_action( self, mode_name=None ):
if section_tree:
item = section_tree.currentItem()
index = section_tree.indexFromItem(item)
section_item = self._items[index.row()]
section_item = self._items[index.row()]
if not isinstance( section_item, SectionItem ):
return
gui_context = ApplicationActionGuiContext()
gui_context.mode_name = mode_name
gui_context.workspace = self._workspace
Expand Down

0 comments on commit 6a6c346

Please sign in to comment.