Module albow.dialog.FileListView
Source code
import os
from pygame import Surface
from pygame import Rect
from albow.containers.PaletteView import PaletteView
from albow.dialog.DialogUtilities import alert
class FileListView(PaletteView):
def __init__(self, width, client, **kwds):
"""
:param width:
:param client:
:param kwds:
"""
font = self.predict_font(kwds)
h = font.get_linesize()
d = 2 * self.predict(kwds, 'margin')
super().__init__((width - d, h), 10, 1, scrolling=True, **kwds)
self.client = client
self.selection = None
self.names = []
def update(self):
client = self.client
directory = client.directory
def aFilter(name):
path = os.path.join(directory, name)
return os.path.isdir(path) or self.client.filter(path)
try:
names = [name for name in os.listdir(directory)
if not name.startswith(".") and aFilter(name)]
except EnvironmentError as e:
alert("%s: %s" % (directory, e))
names = []
self.names = names
self.selection = None
def num_items(self):
return len(self.names)
def draw_item(self, surface: Surface, item_no: int, rect: Rect):
color = self.fg_color
buf = self.font.render(self.names[item_no], True, color)
surface.blit(buf, rect)
def click_item(self, item_no, e):
self.selection = item_no
self.client.dir_box_click(e.num_clicks == 2)
def item_is_selected(self, item_no):
return item_no == self.selection
def get_selected_name(self):
sel = self.selection
if sel is not None:
return self.names[sel]
else:
return ""
Classes
class FileListView (width, client, **kwds)-
The PaletteView class is an abstract base class for implementing tool palettes and similar things. A PaletteView displays an array of items which can be selected by clicking, with the selected item being highlighted. There is provision for scrolling, so that the palette can contain more items than are displayed at one time.
The PaletteView does not maintain the items themselves or keep track of which one is selected; these things are responsibilities of the subclass.
:param width: :param client: :param kwds:
Source code
class FileListView(PaletteView): def __init__(self, width, client, **kwds): """ :param width: :param client: :param kwds: """ font = self.predict_font(kwds) h = font.get_linesize() d = 2 * self.predict(kwds, 'margin') super().__init__((width - d, h), 10, 1, scrolling=True, **kwds) self.client = client self.selection = None self.names = [] def update(self): client = self.client directory = client.directory def aFilter(name): path = os.path.join(directory, name) return os.path.isdir(path) or self.client.filter(path) try: names = [name for name in os.listdir(directory) if not name.startswith(".") and aFilter(name)] except EnvironmentError as e: alert("%s: %s" % (directory, e)) names = [] self.names = names self.selection = None def num_items(self): return len(self.names) def draw_item(self, surface: Surface, item_no: int, rect: Rect): color = self.fg_color buf = self.font.render(self.names[item_no], True, color) surface.blit(buf, rect) def click_item(self, item_no, e): self.selection = item_no self.client.dir_box_click(e.num_clicks == 2) def item_is_selected(self, item_no): return item_no == self.selection def get_selected_name(self): sel = self.selection if sel is not None: return self.names[sel] else: return ""Ancestors
Methods
def draw_item(self, surface, item_no, rect)-
Source code
def draw_item(self, surface: Surface, item_no: int, rect: Rect): color = self.fg_color buf = self.font.render(self.names[item_no], True, color) surface.blit(buf, rect) def get_selected_name(self)-
Source code
def get_selected_name(self): sel = self.selection if sel is not None: return self.names[sel] else: return "" def num_items(self)-
Source code
def num_items(self): return len(self.names) def update(self)-
Source code
def update(self): client = self.client directory = client.directory def aFilter(name): path = os.path.join(directory, name) return os.path.isdir(path) or self.client.filter(path) try: names = [name for name in os.listdir(directory) if not name.startswith(".") and aFilter(name)] except EnvironmentError as e: alert("%s: %s" % (directory, e)) names = [] self.names = names self.selection = None
Inherited members
PaletteView:addadd_anchoradd_centeredanchorattention_lostaugment_mouse_eventbg_colorbg_imageborder_colorborder_widthcall_handlercall_parent_handlercell_rectclick_itemdefer_drawingdismissdrawdraw_item_and_highlightdraw_overdraw_posthighlightdraw_prehighlightfg_colorfocusfocus_switchfontget_cursorget_focusget_margin_rectget_rootget_top_widgetget_visibleglobal_to_localhas_focushighlight_styleinheritedinvalidateis_gl_containeritem_is_selectedkey_downkey_uplocal_to_globalmarginmenu_barnum_colsnum_rowsparentparent_resizedpresentrectrelative_moderemoveremove_anchorresizedscale_bgscroll_button_colorscroll_button_sizesel_colorsel_widthset_parentset_size_for_texttab_stopvisible