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
:add
add_anchor
add_centered
anchor
attention_lost
augment_mouse_event
bg_color
bg_image
border_color
border_width
call_handler
call_parent_handler
cell_rect
click_item
defer_drawing
dismiss
draw
draw_item_and_highlight
draw_over
draw_posthighlight
draw_prehighlight
fg_color
focus
focus_switch
font
get_cursor
get_focus
get_margin_rect
get_root
get_top_widget
get_visible
global_to_local
has_focus
highlight_style
inherited
invalidate
is_gl_container
item_is_selected
key_down
key_up
local_to_global
margin
menu_bar
num_cols
num_rows
parent
parent_resized
present
rect
relative_mode
remove
remove_anchor
resized
scale_bg
scroll_button_color
scroll_button_size
sel_color
sel_width
set_parent
set_size_for_text
tab_stop
visible