diff --git a/.gitignore b/.gitignore index 7c951fd..1175555 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.pyc *.swp *.swo -build/ -docs/build -.venv +/build/ +/docs/build +/.venv +/dist diff --git a/pyproject.toml b/pyproject.toml index c8a31c6..80cd34e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,8 +4,9 @@ build-backend = "hatchling.build" [project] name = "pystdf" -version = "1.3.3" -long_description=""" +version = "1.3.4" +description = "Python module for working with STDF files" +readme = {content-type = "text/plain", text = """ PySTDF is a Python module that makes it easy to work with STDF (Teradyne"s Standard Test Data Format). STDF is a commonly used file format in semiconductor test -- automated test equipment (ATE) from such vendors as Teradyne, Verigy, LTX, Credence, and others support this format. PySTDF provides event-based stream parsing of STDF version 4, along with indexers that can help you rearrange the data into a more useful tabular form, as well as generate missing summary records or new types of derivative records. @@ -21,9 +22,9 @@ Potential applications of PySTDF include: - Loading data into a relational database PySTDF is released under a GPL license. Applications developed with PySTDF can only be released with a GPL-compatible license. Commercial applications can purchase an alternate license agreement for closed-source distribution. -""" +"""} authors = [{name = "Casey Marshall", email="casey.marshall@gmail.com"}] -url="http://code.google.com/p/pystdf/" +url="https://github.com/cmars/pystdf" dependencies = [ 'numpy', 'pandas', @@ -49,4 +50,4 @@ stdf_slice = "pystdf.scripts.stdf_slice:main" rec_index = "pystdf.scripts.rec_index:main" stdf2excel = "pystdf.scripts.stdf2excel:main" stdf2text = "pystdf.scripts.stdf2text:main" -stdf2xml = "pystdf.scripts.stdf2xml:main" \ No newline at end of file +stdf2xml = "pystdf.scripts.stdf2xml:main" diff --git a/pystdf/explorer/MainFrame.py b/pystdf/explorer/MainFrame.py deleted file mode 100644 index dfe0ef7..0000000 --- a/pystdf/explorer/MainFrame.py +++ /dev/null @@ -1,302 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -#Boa:Frame:MainFrame - -import wx -import wx.grid -import wx.gizmos -from wx.lib.anchors import LayoutAnchors - -from pystdf.IO import Parser -from pystdf.Mapping import * -from pystdf.Writers import * - -from record_pos_table import RecordPositionTable -from record_pos_listctrl import RecordPositionListCtrl -from record_view_listctrl import RecordViewListCtrl -from record_keeper import RecordKeeper - -from threading import * -from pystdf.logexcept import exc_string - -# Define notification event for thread completion -EVT_MAPPED_ID = wx.Window.NewControlId() - -def EVT_MAPPED(win, func): - """Define Mapped Event.""" - win.Connect(-1, -1, EVT_MAPPED_ID, func) - -class MappedEvent(wx.PyEvent): - def __init__(self, cancelled=False): - wx.PyEvent.__init__(self) - self.SetEventType(EVT_MAPPED_ID) - self.cancelled = cancelled - -class ProgressUpdater: - def __init__(self, notify_window): - self.notify_window = notify_window - self.count = 0 - self.cancelled = False - - def before_send(self, dataSource, data): - if self.cancelled: - raise MapperCancelled - self.count += 1 - if self.count % 1000 == 0: - self.notify_window.statusBar.SetStatusText('Mapped %d bytes' % ( - dataSource.inp.tell())) - self.notify_window.recordPositionList.SetItemCount(self.count) - -class MapperCancelled(Exception): pass - -class MapperThread(Thread): - def __init__(self, notify_window, parser): - Thread.__init__(self) - self._notify_window = notify_window - self.parser = parser - self.progress_updater = ProgressUpdater(notify_window) - self.parser.addSink(self.progress_updater) - self.start() - - def cancel(self): - self.progress_updater.cancelled = True - - def run(self): - try: - self.parser.parse() - wx.PostEvent(self._notify_window, MappedEvent()) - # except Exception, what: - except Exception as what: - print >>sys.stderr, exc_string() - wx.PostEvent(self._notify_window, MappedEvent(cancelled=True)) - -def create(parent): - return MainFrame(parent) - -[wxID_MAINFRAME, wxID_MAINFRAMERECORDPOSITIONLIST, - wxID_MAINFRAMERECORDVIEWLIST, wxID_MAINFRAMESTATUSBAR, -] = [wx.Window.NewControlId() for _init_ctrls in range(4)] - -[wxID_MAINFRAMEMENUFILECLOSE, wxID_MAINFRAMEMENUFILEEXIT, - wxID_MAINFRAMEMENUFILEOPEN, -] = [wx.Window.NewControlId() for _init_coll_menuFile_Items in range(3)] - -[wxID_MAINFRAMEMENUHELPABOUT] = [wx.Window.NewControlId() for _init_coll_menuHelp_Items in range(1)] - -class MainFrame(wx.Frame): - _custom_classes = {'wx.ListCtrl': ['RecordPositionListCtrl','RecordViewListCtrl']} - - def _init_coll_mainSizer_Items(self, parent): - # generated method, don't edit - - parent.Add(self.recordPositionList, 1, border=0, flag=0) - parent.Add(self.recordViewList, 2, border=0, flag=0) - - def _init_coll_mainMenuBar_Menus(self, parent): - # generated method, don't edit - - parent.Append(menu=self.menuFile, title=u'File') - parent.Append(menu=self.menuHelp, title=u'Help') - - def _init_coll_menuHelp_Items(self, parent): - # generated method, don't edit - - parent.Append(id=wxID_MAINFRAMEMENUHELPABOUT, - kind=wx.ITEM_NORMAL, item=u'About') - self.Bind(wx.EVT_MENU, self.OnMenuHelpAboutMenu, - id=wxID_MAINFRAMEMENUHELPABOUT) - - def _init_coll_menuFile_Items(self, parent): - # generated method, don't edit - - parent.Append(id=wxID_MAINFRAMEMENUFILEOPEN, - kind=wx.ITEM_NORMAL, item=u'Open') - parent.Append(id=wxID_MAINFRAMEMENUFILECLOSE, - kind=wx.ITEM_NORMAL, item=u'Close') - parent.Append(id=wxID_MAINFRAMEMENUFILEEXIT, - kind=wx.ITEM_NORMAL, item=u'Exit') - self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu, - id=wxID_MAINFRAMEMENUFILEOPEN) - self.Bind(wx.EVT_MENU, self.OnMenuFileCloseMenu, - id=wxID_MAINFRAMEMENUFILECLOSE) - self.Bind(wx.EVT_MENU, self.OnMenuFileExitMenu, - id=wxID_MAINFRAMEMENUFILEEXIT) - - def _init_coll_recordViewList_Columns(self, parent): - # generated method, don't edit - - parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT, - heading=u'Field Name', width=-1) - parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT, heading=u'Value', - width=-1) - - def _init_coll_recordPositionList_Columns(self, parent): - # generated method, don't edit - - parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT, - heading=u'File Offset', width=-1) - parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT, - heading=u'Record Type', width=-1) - parent.InsertColumn(col=2, format=wx.LIST_FORMAT_LEFT, - heading=u'Wafer', width=-1) - parent.InsertColumn(col=3, format=wx.LIST_FORMAT_LEFT, - heading=u'Insertion', width=-1) - parent.InsertColumn(col=4, format=wx.LIST_FORMAT_LEFT, - heading=u'Part', width=-1) - - def _init_coll_statusBar_Fields(self, parent): - # generated method, don't edit - parent.SetFieldsCount(1) - - parent.SetStatusText(u'Status') - - parent.SetStatusWidths([-1]) - - def _init_sizers(self): - # generated method, don't edit - self.mainSizer = wx.BoxSizer(orient=wx.HORIZONTAL) - - self._init_coll_mainSizer_Items(self.mainSizer) - - self.SetSizer(self.mainSizer) - - def _init_utils(self): - # generated method, don't edit - self.menuFile = wx.Menu(title='') - - self.menuHelp = wx.Menu(title='') - - self.mainMenuBar = wx.MenuBar() - - self._init_coll_menuFile_Items(self.menuFile) - self._init_coll_menuHelp_Items(self.menuHelp) - self._init_coll_mainMenuBar_Menus(self.mainMenuBar) - - def _init_ctrls(self, prnt): - # generated method, don't edit - wx.Frame.__init__(self, id=wxID_MAINFRAME, name=u'MainFrame', - parent=prnt, pos=wx.Point(304, 125), size=wx.Size(615, 556), - style=wx.DEFAULT_FRAME_STYLE, title=u'STDF Explorer') - self._init_utils() - self.SetClientSize(wx.Size(607, 527)) - self.SetMenuBar(self.mainMenuBar) - self.SetExtraStyle(0) - self.SetStatusBarPane(0) - - self.statusBar = wx.StatusBar(id=wxID_MAINFRAMESTATUSBAR, - name=u'statusBar', parent=self, style=0) - self._init_coll_statusBar_Fields(self.statusBar) - self.SetStatusBar(self.statusBar) - - self.recordPositionList = RecordPositionListCtrl(id=wxID_MAINFRAMERECORDPOSITIONLIST, - name=u'recordPositionList', parent=self, pos=wx.Point(0, 0), - size=wx.Size(202, 487), - style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES) - self._init_coll_recordPositionList_Columns(self.recordPositionList) - self.recordPositionList.Bind(wx.EVT_LIST_ITEM_SELECTED, - self.OnRecordPositionListListItemSelected, - id=wxID_MAINFRAMERECORDPOSITIONLIST) - - self.recordViewList = RecordViewListCtrl(id=wxID_MAINFRAMERECORDVIEWLIST, - name=u'recordViewList', parent=self, pos=wx.Point(202, 0), - size=wx.Size(404, 487), - style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES) - self.recordViewList.SetAutoLayout(False) - self.recordViewList.SetMinSize(wx.Size(404, 487)) - self._init_coll_recordViewList_Columns(self.recordViewList) - - self._init_sizers() - - def __init__(self, parent): - self._init_ctrls(parent) - self.view_stream = None - EVT_MAPPED(self, self.OnMapped) - - def OnMenuHelpAboutMenu(self, event): - event.Skip() - - def OnMenuFileOpenMenu(self, event): - dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*") - try: - if dlg.ShowModal() == wx.ID_OK: - filename = dlg.GetPath() - - # Set up the mapping parser - self.map_stream = open(filename, 'rb') - parser = Parser(inp=self.map_stream) - self.record_mapper = StreamMapper() - parser.addSink(self.record_mapper) - material_mapper = MaterialMapper() - parser.addSink(material_mapper) - self.recordPositionList.record_mapper = self.record_mapper - self.recordPositionList.material_mapper = material_mapper - - # Set up the viewing parser - self.view_stream = open(filename, 'rb') - self.view_parser = Parser(inp=self.view_stream) - self.record_keeper = RecordKeeper() - self.view_parser.addSink(self.record_keeper) - self.view_parser.parse(1) - - # Parse the file in a separate thread - self.mapper = MapperThread(self, parser) - - finally: - dlg.Destroy() - - def OnMapped(self, event): - if event.cancelled: - self.statusBar.SetStatusText('%s... Cancelled!' % ( - self.statusBar.GetStatusText())) - else: - self.recordPositionList.SetItemCount( - len(self.record_mapper.indexes)) - self.statusBar.SetStatusText('%s... Done' % ( - self.statusBar.GetStatusText())) - - if self.map_stream is not None: - self.map_stream.close() - self.map_stream = None - self.mapper = None - - def OnMenuFileCloseMenu(self, event): - self.recordPositionList.record_mapper = None - self.recordPositionList.material_mapper = None - self.view_stream.close() - self.view_stream = None - self.view_parser = None - self.record_mapper = None - - self.recordPositionList.SetItemCount(0) - self.recordPositionList.Refresh() - self.recordViewList.SetItemCount(0) - self.recordViewList.Refresh() - - if self.mapper: - self.mapper.cancel() - - def OnMenuFileExitMenu(self, event): - self.Close() - - def OnRecordPositionListListItemSelected(self, event): - if self.record_mapper: - self.view_stream.seek(self.record_mapper.indexes[event.GetIndex()]) - self.view_parser.parse(1) - self.recordViewList.record = self.record_keeper.record_type, self.record_keeper.record_data diff --git a/pystdf/explorer/README.StdfExplorer b/pystdf/explorer/README.StdfExplorer deleted file mode 100644 index 511fcb7..0000000 --- a/pystdf/explorer/README.StdfExplorer +++ /dev/null @@ -1,4 +0,0 @@ - -StdfExplorer is a simple STDF viewer GUI viewer -written in WxPython. To run it, you'll need to install -WxPython 4.0.3 or greater and be on Python 3. diff --git a/pystdf/explorer/StdfExplorer.pyw b/pystdf/explorer/StdfExplorer.pyw deleted file mode 100644 index 546c38b..0000000 --- a/pystdf/explorer/StdfExplorer.pyw +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -#Boa:App:BoaApp - -import wx - -from pystdf.explorer import MainFrame - -modules ={'pystdf.explorer.MainFrame': [1, 'Main frame of Application', u'MainFrame.py']} - -class BoaApp(wx.App): - def OnInit(self): - wx.InitAllImageHandlers() - self.main = MainFrame.create(None) - self.main.Show() - self.SetTopWindow(self.main) - return True - -def main(): - application = BoaApp(0) - application.MainLoop() - -if __name__ == '__main__': - main() diff --git a/pystdf/explorer/__init__.py b/pystdf/explorer/__init__.py deleted file mode 100644 index f2667de..0000000 --- a/pystdf/explorer/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# diff --git a/pystdf/explorer/record_keeper.py b/pystdf/explorer/record_keeper.py deleted file mode 100644 index 5ffa5a6..0000000 --- a/pystdf/explorer/record_keeper.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -class RecordKeeper: - def __init__(self): - self.record_type = None - self.record_data = None - - def after_begin(self, dataSource): - self.record_type = None - self.record_data = None - - def after_send(self, dataSource, data): - self.record_type, self.record_data = data - - \ No newline at end of file diff --git a/pystdf/explorer/record_pos_listctrl.py b/pystdf/explorer/record_pos_listctrl.py deleted file mode 100644 index 1eb5217..0000000 --- a/pystdf/explorer/record_pos_listctrl.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -import wx - -class RecordPositionListCtrl(wx.ListCtrl): - def __init__(self, *args, **kwargs): - wx.ListCtrl.__init__(self, *args, **kwargs) - self.__record_mapper = None - - def get_record_mapper(self): - return self.__record_mapper - def set_record_mapper(self, value): - self.__record_mapper = value - if value is None: - self.SetItemCount(0) - else: - self.SetItemCount(len(value.indexes)) - record_mapper = property(get_record_mapper, set_record_mapper) - - def get_material_mapper(self): - return self.__material_mapper - def set_material_mapper(self, value): - self.__material_mapper = value - material_mapper = property(get_material_mapper, set_material_mapper) - - def OnGetItemText(self, item, col): - if self.__record_mapper is not None: - if col == 0: - return '%08X' % (self.__record_mapper.indexes[item]) - elif col == 1: - return self.__record_mapper.types[item].__class__.__name__ - elif col == 2: - return str(self.__material_mapper.waferid[item]) - elif col == 3: - return str(self.__material_mapper.insertionid[item]) - elif col == 4: - return str(self.__material_mapper.partid[item]) - return '' - diff --git a/pystdf/explorer/record_pos_table.py b/pystdf/explorer/record_pos_table.py deleted file mode 100644 index ebfa020..0000000 --- a/pystdf/explorer/record_pos_table.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -import wx -import wx.grid as gridlib - -class RecordPositionTable(gridlib.PyGridTableBase): - def __init__(self, record_mapper): - gridlib.PyGridTableBase.__init__(self) - self.record_mapper = record_mapper - - def GetNumberRows(self): - print('GetNumberRows: %d' % (len(self.record_mapper.indexes))) - return len(self.record_mapper.indexes) - - def GetNumberCols(self): - return 2 - - col_names = { - 0:'File Offset (Hex)', - 1:'Record Type', - } - def GetColLabelValue(self, col): - return self.col_names[col] - - def IsEmptyCell(self, row, col): - return False - - value_getters = { - 0:lambda self, row: '%08X' % (self.record_mapper.indexes[row]), - 1:lambda self, row: self.record_mapper.types[row].__class__.__name__, - } - - def GetValue(self, row, col): - return self.value_getters[col](self, row) - - def SetValue(self, row, col, value): - pass - diff --git a/pystdf/explorer/record_view_listctrl.py b/pystdf/explorer/record_view_listctrl.py deleted file mode 100644 index d8d9b84..0000000 --- a/pystdf/explorer/record_view_listctrl.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -import wx - -class RecordViewListCtrl(wx.ListCtrl): - def __init__(self, *args, **kwargs): - wx.ListCtrl.__init__(self, *args, **kwargs) - self.__record_type, self.__record_data = None, None - - def get_record(self): - return self.__record_type, self.__record_data - def set_record(self, value): - if value is None: - self.__record_type, self.__record_data = None, None - self.SetItemCount(0) - else: - self.__record_type, self.__record_data = value - self.SetItemCount(len(self.__record_type.fieldNames)) - self.RefreshItems(0, len(self.__record_type.fieldNames)-1) - record = property(get_record, set_record) - - def OnGetItemText(self, item, col): - if col == 0 and self.__record_type is not None: - return self.__record_type.fieldNames[item] - elif col == 1 and self.__record_data is not None: - return str(self.__record_data[item]) - return '' - diff --git a/pystdf/explorer/test.py b/pystdf/explorer/test.py deleted file mode 100644 index 2e4d38a..0000000 --- a/pystdf/explorer/test.py +++ /dev/null @@ -1,106 +0,0 @@ -# -# PySTDF - The Pythonic STDF Parser -# Copyright (C) 2006 Casey Marshall -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -import wx -import wx.grid as gridlib - -from pystdf.IO import Parser -from pystdf.Mapping import * -from pystdf.Writers import * - -#--------------------------------------------------------------------------- -class HugeTable(gridlib.PyGridTableBase): - def __init__(self, record_mapper, f): - gridlib.PyGridTableBase.__init__(self) - self.record_mapper = record_mapper - self.f = f - -# self.odd=gridlib.GridCellAttr() -# self.odd.SetBackgroundColour("sky blue") -# self.even=gridlib.GridCellAttr() -# self.even.SetBackgroundColour("sea green") - -# def GetAttr(self, row, col, kind): -# attr = [self.even, self.odd][row % 2] -# attr.IncRef() -# return attr - - # This is all it takes to make a custom data table to plug into a - # wxGrid. There are many more methods that can be overridden, but - # the ones shown below are the required ones. This table simply - # provides strings containing the row and column values. - - def GetNumberRows(self): - return len(self.record_mapper.indexes) - - def GetNumberCols(self): - return 2 - - def IsEmptyCell(self, row, col): - return False - - value_getters = { - 0: lambda self, row: self.record_mapper.indexes[row], - 1: lambda self, row: self.record_mapper.types[row], - } - - def GetValue(self, row, col): - return self.value_getters[col](self, row) - - def SetValue(self, row, col, value): - pass - -#--------------------------------------------------------------------------- -class HugeTableGrid(gridlib.Grid): - def __init__(self, parent, record_mapper, f): - gridlib.Grid.__init__(self, parent, -1) - table = HugeTable(record_mapper, f) - # The second parameter means that the grid is to take ownership of the - # table and will destroy it when done. Otherwise you would need to keep - # a reference to it and call it's Destroy method later. - self.SetTable(table, True) - self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightDown) - def OnRightDown(self, event): - print("hello") - print(self.GetSelectedRows()) - -#--------------------------------------------------------------------------- -class TestFrame(wx.Frame): - def __init__(self, parent, filename): - f = open(filename, 'rb') - p=Parser(inp=f) - record_mapper = StreamMapper() - p.addSink(record_mapper) - - print('Parsing %s...' % (filename)) - p.parse() - print('Parse complete') - - wx.Frame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480)) - grid = HugeTableGrid(self, record_mapper, f) - grid.SetReadOnly(5,5, True) - -#--------------------------------------------------------------------------- -if __name__ == '__main__': - import sys - app = wx.PySimpleApp() - frame = TestFrame(None, sys.argv[1]) - frame.Show(True) - app.MainLoop() -#--------------------------------------------------------------------------- diff --git a/pystdf/scripts/rec_index.py b/pystdf/scripts/rec_index.py index 89aac86..24f8eff 100644 --- a/pystdf/scripts/rec_index.py +++ b/pystdf/scripts/rec_index.py @@ -78,3 +78,7 @@ def main(): print("Usage: %s " % (sys.argv[0])) else: process_file(sys.argv[1]) + +if __name__ == '__main__': + main() + diff --git a/pystdf/scripts/stdf2excel.py b/pystdf/scripts/stdf2excel.py index 98b7c83..6e00459 100644 --- a/pystdf/scripts/stdf2excel.py +++ b/pystdf/scripts/stdf2excel.py @@ -52,3 +52,7 @@ def main(): dfs= STDF2DataFrame(fin) print("Exporting to %s" %fout) toExcel(fout,dfs) + +if __name__ == '__main__': + main() + diff --git a/pystdf/scripts/stdf2text.py b/pystdf/scripts/stdf2text.py index 87e0fcd..6732436 100644 --- a/pystdf/scripts/stdf2text.py +++ b/pystdf/scripts/stdf2text.py @@ -74,3 +74,7 @@ def main(): print("Usage: %s " % (sys.argv[0])) else: process_file(sys.argv[1:]) + +if __name__ == '__main__': + main() + diff --git a/pystdf/scripts/stdf2xml.py b/pystdf/scripts/stdf2xml.py index 2c9265a..c6192e9 100644 --- a/pystdf/scripts/stdf2xml.py +++ b/pystdf/scripts/stdf2xml.py @@ -69,3 +69,7 @@ def main(): print("Usage: %s " % (sys.argv[0])) else: process_file(sys.argv[1]) + +if __name__ == '__main__': + main() + diff --git a/pystdf/scripts/stdf_slice.py b/pystdf/scripts/stdf_slice.py index 623fdf1..942c972 100644 --- a/pystdf/scripts/stdf_slice.py +++ b/pystdf/scripts/stdf_slice.py @@ -35,3 +35,7 @@ def main(): p.addSink(AtdfWriter()) f.seek(record_mapper.indexes[start]) p.parse(count=count) + +if __name__ == '__main__': + main() +