def _list_contents (self): """F.list_contents (...) -> None Populates the directory contents to the scrolled list. """ items = ListItemCollection () items.append (FileListItem (os.pardir, stat.S_IFDIR)) stats = None files = [] dirs = [] dappend = dirs.append fappend = files.append entries = os.listdir (self._directory) isdir = os.path.isdir pjoin = os.path.join for filename in entries: if isdir (pjoin (self._directory, filename)): dappend (filename) else: fappend (filename) dirs.sort () files.sort () map (items.append, [FileListItem (d, stat.S_IFDIR) for d in dirs]) for filename in files: stats = os.stat (pjoin (self._directory, filename)) items.append (FileListItem (filename, stats.st_mode)) self.set_items (items)
def __init__(self, width, height, collection=None): # Temporary placeholder for kwargs of the update() method. self.__lastargs = None ScrolledWindow.__init__(self, width, height) self._spacing = 0 # The item cursor position within the list. self._cursor = None # Used for selections. self._last_direction = None self._signals[SIG_LISTCHANGED] = [] self._signals[SIG_SELECTCHANGED] = [] # Items and selection. self._itemcollection = None self._selectionmode = SELECTION_MULTIPLE if collection: self.set_items(collection) else: self._itemcollection = ListItemCollection() self._itemcollection.list_changed = self._list_has_changed self._itemcollection.item_changed = self._item_has_changed self.child = ListViewPort(self)
def _list_contents(self): """F.list_contents (...) -> None Populates the directory contents to the scrolled list. """ items = ListItemCollection() items.append(FileListItem(os.pardir, stat.S_IFDIR)) stats = None files = [] dirs = [] dappend = dirs.append fappend = files.append entries = os.listdir(self._directory) isdir = os.path.isdir pjoin = os.path.join for filename in entries: if isdir(pjoin(self._directory, filename)): dappend(filename) else: fappend(filename) dirs.sort() files.sort() map(items.append, [FileListItem(d, stat.S_IFDIR) for d in dirs]) for filename in files: stats = os.stat(pjoin(self._directory, filename)) items.append(FileListItem(filename, stats.st_mode)) self.set_items(items)
def set_items(self, items): """S.set_items (...) -> None Sets a collection of items to display. """ old = self._itemcollection self.vscrollbar.value = 0 self.hscrollbar.value = 0 if isinstance(items, ListItemCollection): self._itemcollection = items else: self._itemcollection = ListItemCollection(items) self._itemcollection.list_changed = self._list_has_changed self._itemcollection.item_changed = self._item_has_changed old.list_changed = None old.item_changed = None del old if len(self._itemcollection) > 0: self._cursor = self._itemcollection[0] else: self._cursor = None self._list_has_changed(self._itemcollection)
# ListItemCollection example. from ocempgui.widgets.components import ListItemCollection, TextListItem # Item change handler. def item_has_changed (item): print "Item '%s' has changed" % item.text # List change handler. def list_has_changed (l): print "List now contains %d item(s)" % l.length collection = ListItemCollection () # Set up a notification handler for item changes. collection.item_changed = item_has_changed # Set up a notification handler for list changes collection.list_changed = list_has_changed for i in xrange (5): collection.append (TextListItem ("Item no. %d" % i)) collection[2].text = "New text in item 3" # Use a tuple as constructor argument. items = (TextListItem ("String 1"), TextListItem ("String 2"), TextListItem ("String 3")) collection = ListItemCollection (items) print "New collection:" print collection