class HistoryPanel(wx.Panel): def __init__(self, parent, data): wx.Panel.__init__(self, parent=parent) self.parent = parent self.data = data self._create_widgets() self._create_boxes() self._create_binds() def _create_widgets(self): asset_column = ColumnDefn("Asset", "left", 60, "asset.product_name", isSpaceFilling=True) date_column = ColumnDefn("Completed", "right", 100, "completed") process_column = ColumnDefn("Process", "right", 100, "process") status_column = ColumnDefn("Status", "right", 80, "status") columns = [asset_column, date_column, process_column, status_column] self.olv = ObjectListView(parent=self, style=wx.LC_REPORT | wx.SUNKEN_BORDER, useAlternateBackColors=True, sortable=False) self.olv.SetEmptyListMsg('No items in history') assets = self.data.db.queue.not_pending logging.debug(f'history panel assets: {assets}') self.olv.SetColumns(columns) self.olv.SetObjects(assets) self.olv.oddRowsBackColor = wx.Colour(255, 255, 255) self.olv.evenRowsBackColor = wx.Colour(240, 240, 240) self.olv._FormatAllRows() def _create_boxes(self): main_box = wx.BoxSizer(wx.VERTICAL) main_box.Add(self.olv, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(main_box) def _create_binds(self): pass def refresh(self): self.olv.DeleteAllItems() self.olv.SetObjects(self.data.db.queue.pending)
class OLVPanel(wx.Panel): """ Panel that contains the list view of a library Attributes: self.olv: ObjectListView: wx.ListCtrl """ def __init__(self, parent, data: DataHandler): wx.Panel.__init__(self, parent) self.data = data self.id_s = [0] self._create_widgets() self._create_boxes() self._create_binds() def _create_widgets(self): self.source_choice = wx.Choice(self, choices=self._get_choices()) self.source_choice.SetSelection(0) id_column = ColumnDefn("ID", "right", 60, "id") sku_column = ColumnDefn("SKU", "right", 80, "sku") product_name_column = ColumnDefn("Product Name", "left", 160, "product_name", isSpaceFilling=True) zip_size_column = ColumnDefn("Zip Size", "right", 90, "size") installed_column = ColumnDefn("Installed", "right", 90, "installed") columns = [ sku_column, product_name_column, installed_column, zip_size_column ] self.olv = ObjectListView(parent=self, style=wx.LC_REPORT | wx.SUNKEN_BORDER, useAlternateBackColors=True) self.olv.SetColumns(columns) self.olv.SetObjects(self.data.db.assets.all) self.olv.oddRowsBackColor = wx.Colour(255, 255, 255) self.olv.evenRowsBackColor = wx.Colour(240, 240, 240) self.olv._FormatAllRows() def _create_boxes(self): main_box = wx.BoxSizer(wx.VERTICAL) main_box.Add(self.source_choice, 0, wx.EXPAND | wx.ALL, 5) main_box.Add(self.olv, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(main_box) def _create_binds(self): self.source_choice.Bind(wx.EVT_CHOICE, self.on_source_change) def _get_choices(self): choices = ['All Assets'] for source in self.data.db.sources: choices.append(source.path_raw) self.id_s.append(source.id) return choices def on_source_change(self, event: wx.Event = None): selection: int = self.source_choice.GetSelection() id: int = self.id_s[selection] source = self.data.db.sources[id] if selection == 0: assets = self.data.db.assets.all else: assets = self.data.db.assets.filter_by(source_id=source.id).all() self.olv.DeleteAllItems() self.olv.SetObjects(assets)
class MetaDialog(wx.Dialog): def __init__(self, parent, data): wx.Dialog.__init__(self, parent, title='Metadata Import', pos=wx.DefaultPosition, size=(400, 300), style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.YES_NO) self.parent: wx.Frame = parent self.data: DataHandler = data self._create_widgets() self._create_boxes() self._create_binds() def _create_widgets(self): unimported_assets = self.data.db.assets.filter_by( imported_raw=False, installed_raw=True).all() if len(unimported_assets) > 1: label = f'Would you like to open Daz and import {len(unimported_assets)} assets?' elif len(unimported_assets) > 0: label = f'Would you like to open Daz and import 1 asset?' else: label = f'No assets to be imported into Daz.' self.message = wx.StaticText(self, label=label) self.message.SetFont(wx.Font(wx.FontInfo(12))) product_name_column = ColumnDefn("Product Name", "left", 160, "product_name", isSpaceFilling=True) columns = [product_name_column] self.olv = ObjectListView(parent=self, style=wx.LC_REPORT | wx.SUNKEN_BORDER, useAlternateBackColors=True, sortable=False) self.olv.SetEmptyListMsg('No Assets to be Imported') self.olv.SetColumns(columns) self.olv.SetObjects(unimported_assets) self.olv.oddRowsBackColor = wx.Colour(255, 255, 255) self.olv.evenRowsBackColor = wx.Colour(240, 240, 240) self.olv._FormatAllRows() self.yes_button = wx.Button(self, label='Yes') self.no_button = wx.Button(self, label='No') if not len(unimported_assets) > 0: self.yes_button.Disable() def _create_boxes(self): button_box = wx.BoxSizer(wx.HORIZONTAL) button_box.Add(0, 0, 1) button_box.Add(self.yes_button, 0, border=5) button_box.Add(5, 0, 0) button_box.Add(self.no_button, 0, border=5) button_box.Add(0, 0, 1) main_box = wx.BoxSizer(wx.VERTICAL) main_box.Add(self.message, 0, wx.EXPAND | wx.ALL, 5) main_box.Add(self.olv, 1, wx.EXPAND | wx.ALL, 5) main_box.Add(button_box, 0, wx.EXPAND | wx.ALL, 5) self.SetSizer(main_box) def _create_binds(self): self.yes_button.Bind(wx.EVT_BUTTON, self._on_yes_button) self.no_button.Bind(wx.EVT_BUTTON, self._on_no_button) def _on_close(self, event=None): self.EndModal(wx.ID_CLOSE) def _on_yes_button(self, event=None): self.EndModal(wx.ID_YES) def _on_no_button(self, event=None): self.EndModal(wx.ID_NO)
class TestObjectListViewFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos=wx.DefaultPosition, size=(600, 800), style=wx.DEFAULT_FRAME_STYLE) self.data = DataHandler() self._create_body() self.Show() logging.info('---------------- TestListView Shown') self.Bind(wx.EVT_CLOSE, self.on_close) def _disable_frame(self, event=None): # self.library_panel.Disable() pass def _enable_frame(self, event=None): pass def _create_body(self): idn_column = ColumnDefn("ID", "right", 60, "idn") sku_column = ColumnDefn("SKU", "right", 80, "sku") product_name_column = ColumnDefn("Product Name", "left", 160, "product_name", isSpaceFilling=True) filename_column = ColumnDefn("File Name", "left", 180, "filename", isSpaceFilling=True) zip_size_column = ColumnDefn("Zip Size", "right", 90, "get_size") installed_column = ColumnDefn("Installed", "right", 90, "get_installed") columns = [ idn_column, sku_column, product_name_column, zip_size_column, installed_column ] assets = self.data.db.select_all_assets() panel = wx.Panel(self) box = wx.BoxSizer() self.olv = ObjectListView(parent=panel, style=wx.LC_REPORT | wx.SUNKEN_BORDER, useAlternateBackColors=True) self.olv.SetColumns(columns) self.olv.SetObjects(assets) self.olv.oddRowsBackColor = wx.Colour(255, 255, 255) self.olv.evenRowsBackColor = wx.Colour(240, 240, 240) self.olv._FormatAllRows() box.Add(self.olv, 1, wx.EXPAND | wx.ALL, 5) panel.SetSizer(box) def on_close(self, event): self.data.close() event.Skip()