From 1733cb59070749019c266941b23781d2f2aeceb4 Mon Sep 17 00:00:00 2001 From: Xemin0 Date: Mon, 9 Oct 2023 01:05:46 -0600 Subject: [PATCH] release as a conda package --- README.md | 23 ++- conda-recipe/meta.yaml | 26 +++ setup.py | 34 ++++ xml2table/__init__.py | 7 + {utils => xml2table/utils}/EventHandler.py | 8 +- xml2table/utils/__init__.py | 1 + xml2table/utils/xml_processing/__init__.py | 1 + .../utils}/xml_processing/xml_parser.py | 0 .../visual_components}/ColorBar.py | 0 xml2table/visual_components/__init__.py | 1 + xml2table/xml2table.py | 151 ++++++++++++++++++ xml2table_v02_2.py | 142 ---------------- 12 files changed, 244 insertions(+), 150 deletions(-) create mode 100644 conda-recipe/meta.yaml create mode 100644 setup.py create mode 100644 xml2table/__init__.py rename {utils => xml2table/utils}/EventHandler.py (97%) create mode 100644 xml2table/utils/__init__.py create mode 100644 xml2table/utils/xml_processing/__init__.py rename {utils => xml2table/utils}/xml_processing/xml_parser.py (100%) rename {visual_components => xml2table/visual_components}/ColorBar.py (100%) create mode 100644 xml2table/visual_components/__init__.py create mode 100644 xml2table/xml2table.py delete mode 100644 xml2table_v02_2.py diff --git a/README.md b/README.md index d72f5e1..6ea9587 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,29 @@ It simply converts between the copy-pasted XML contents and a visual table. XML *Could be adapted for other parameter-settings in XML.* ### Required Python Packages -- Python 3.10.12 (Other python should also work) -- `TkInter` +- Python 3.10.12 (Other python should also work; and `TkInter` used is already an integral part of `Python`) - `Numpy` + +### Install +- `conda` +```bash +conda install -c xemin0 xml2table +``` +- Directly clone the repo +```bash +git clone https://github.com/Xemin0/XML2Table +``` + + ### How to Use it -- Start the program by running +#### Installed from `conda` +simply run `xml2table` from command line + +#### Cloned from Github +Navigate to `xml2table/` folder then start the program by running ```bash -python xml2table_v{current_version_number}.py +python xml2table.py ``` Either: diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml new file mode 100644 index 0000000..d288047 --- /dev/null +++ b/conda-recipe/meta.yaml @@ -0,0 +1,26 @@ +{% set data = load_setup_py_data() %} +package: + name: xml2table + version: {{ data['version'] }} + +source: + path: .. + +build: + script: python3 setup.py install + +requirements: + build: + - python >=3.6,{{PY_VER}}* + - setuptools <60.0 + run: + - python {{PY_VER}}* + - numpy >=1.8* + +about: + home: https://github.com/Xemin0/XML2Table + license: BSD 3-Clause + license_file: LICENSE + license_family: BSD + + summary: data['description'] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..af51483 --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +from setuptools import setup, find_packages + +setup( + name = 'xml2table', + version = '0.2.2', + packages = find_packages(), + url = 'https://github.com/Xemin0/XML2Table', + + # BSD 3-Clause License: + # - http://choosealicense.com/licenses/bsd-3-clause + # - http://opensource.org/licenses/BSD-3-Clause + license = 'BSD', + author = 'Xemin0', + author_email = 'loser.qqfang@gmail.com', + description = 'A simple python GUI to facilate parameter settings (Contact Energies) in XML file generated by CompuCell3D, by converting between XML and a colored table. ', + install_requires = [ + 'numpy>=1.8.0', + ], + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers = [ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: BSD License', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + ], + entry_points={ + 'console_scripts': [ + 'xml2table=xml2table.xml2table:main', + ], + } +) diff --git a/xml2table/__init__.py b/xml2table/__init__.py new file mode 100644 index 0000000..75e6568 --- /dev/null +++ b/xml2table/__init__.py @@ -0,0 +1,7 @@ +# __init__.py + +from .xml2table import main + +# Optional +#from .utils.EventHandler import EventHandler +#from .visual_components.ColorBar import ColorBar diff --git a/utils/EventHandler.py b/xml2table/utils/EventHandler.py similarity index 97% rename from utils/EventHandler.py rename to xml2table/utils/EventHandler.py index 1c4dd25..83557d5 100644 --- a/utils/EventHandler.py +++ b/xml2table/utils/EventHandler.py @@ -94,8 +94,8 @@ def renderTable2(self): - Symmetric Entries are now dynamically synced """ if 1 == len(self.names): - tk.Label(master = self.frame4table, text = self.names[0], foreground = 'purple').grid(row = 0, column = 1) # top row - tk.Label(master = self.frame4table, text = self.names[0], foreground = 'purple').grid(row = 1, column = 0) # Leftmost column + tk.Label(master = self.frame4table, text = self.names[0]).grid(row = 0, column = 1) # top row + tk.Label(master = self.frame4table, text = self.names[0]).grid(row = 1, column = 0) # Leftmost column self.entries = [] entry = tk.Entry(master = self.frame4table, width = 5) @@ -110,8 +110,8 @@ def renderTable2(self): #N = len(self.names) # Create and place the Label widgets for the names for i, name in enumerate(self.names): - tk.Label(master = self.frame4table, text = name, foreground = 'purple').grid(row = 0, column = i+1) # top row - tk.Label(master = self.frame4table, text = name, foreground = 'purple').grid(row = i+1, column = 0) # Leftmost column + tk.Label(master = self.frame4table, text = name).grid(row = 0, column = i+1) # top row + tk.Label(master = self.frame4table, text = name).grid(row = i+1, column = 0) # Leftmost column # Create and place the Entry widgets for the matrix values (contact energies) self.entries = [] # clear the old widgets diff --git a/xml2table/utils/__init__.py b/xml2table/utils/__init__.py new file mode 100644 index 0000000..e65cafd --- /dev/null +++ b/xml2table/utils/__init__.py @@ -0,0 +1 @@ +from .EventHandler import EventHandler diff --git a/xml2table/utils/xml_processing/__init__.py b/xml2table/utils/xml_processing/__init__.py new file mode 100644 index 0000000..b29047b --- /dev/null +++ b/xml2table/utils/xml_processing/__init__.py @@ -0,0 +1 @@ +from .xml_parser import names_and_values diff --git a/utils/xml_processing/xml_parser.py b/xml2table/utils/xml_processing/xml_parser.py similarity index 100% rename from utils/xml_processing/xml_parser.py rename to xml2table/utils/xml_processing/xml_parser.py diff --git a/visual_components/ColorBar.py b/xml2table/visual_components/ColorBar.py similarity index 100% rename from visual_components/ColorBar.py rename to xml2table/visual_components/ColorBar.py diff --git a/xml2table/visual_components/__init__.py b/xml2table/visual_components/__init__.py new file mode 100644 index 0000000..2c142d7 --- /dev/null +++ b/xml2table/visual_components/__init__.py @@ -0,0 +1 @@ +from .ColorBar import ColorBar diff --git a/xml2table/xml2table.py b/xml2table/xml2table.py new file mode 100644 index 0000000..04c7ea4 --- /dev/null +++ b/xml2table/xml2table.py @@ -0,0 +1,151 @@ +""" +Front-end GUI for the python app XML2Table +to facilitate the Contact Energy Plugin settings in XML generated in CompuCell3D + +Visual Compenents and their usages (Left to Right) + - Text Field for XML(Contact Energy Plugin): + - XML section copy-pasted from CC3D.twedit to be converted to table + or + - XML section generated based on the adjusted table + - Four Buttons: + - Convert XML to Table + - Generate XML from Table + - Add a New Cell + - Clear the Table + - Color Bar Field: + - Table Field: +""" +import tkinter as tk + +if __name__ == "__main__": + # running as a script + from utils.EventHandler import EventHandler + from visual_components.ColorBar import ColorBar +else: + from .utils.EventHandler import EventHandler + from .visual_components.ColorBar import ColorBar + +def main(): + """ + # Base window + """ + + window = tk.Tk() + window.title("Simple XML2Table Editor") + + # Set minimal Size to ensure the texts in the buttons will be shown properly + window.rowconfigure(0, minsize = 200, weight = 1) + window.columnconfigure(0, minsize = 100, weight = 1) + window.columnconfigure(1, minsize = 150, weight = 1) + window.columnconfigure(2, minsize = 25, weight = 1) + window.columnconfigure(3, minsize = 100, weight = 1) + + # ====================================== # + + + + """ + # Create Frames for each region and attach them to the main window horizontally + # with default sizes + """ + + frame_txtField = tk.Frame(master = window, width = 60, height = 200) + + frame_buttons = tk.Frame(master = window, relief = tk.RAISED, bd = 2, width = 20, height = 200) + + frame_CB = tk.Frame(master = window, width = 30, height = 200) + + frame_table = tk.Frame(master = window, width = 100, height = 200) + + # ====================================== # + + + """ + # Arrange the Fields/Widgets accordingly inside the main window + """ + #frame_txtField.pack(fill = tk.BOTH, side = tk.LEFT, expand = True) + #frame_buttons.pack(fill = tk.Y, side = tk.LEFT, expand = True) + #frame_table.pack(fill = tk.BOTH, side = tk.LEFT, expand = True) + + frame_txtField.grid(row = 0, column = 0, sticky = 'nsew') + frame_buttons.grid(row = 0, column = 1, sticky = 'ns') + frame_CB.grid(row = 0, column = 2, sticky = 'ns') + frame_table.grid(row = 0, column = 3, sticky = 'nsew') + + # ====================================== # + + + + """ + # Text Field for XML + """ + + text_box = tk.Text(master = frame_txtField) # height = 10, width = 20) + + # Place text field inside the frame + text_box.pack(fill = tk.BOTH, expand = True) + + # ====================================== # + """ + # Event Handler Class Object + """ + e_handler = EventHandler(text_box, frame_table) + + # ====================================== # + + + + + """ + # Buttons + - convert to table + - convert to XML + - add new cell + - clear table + + # Event Handlers for each Button + """ + + + btn_xml2table = tk.Button(master = frame_buttons, text = 'Convert to Table', command = e_handler.toTable) + btn_table2xml = tk.Button(master = frame_buttons, text = 'Convert to XML', command = e_handler.toXML) + btn_newCell = tk.Button(master = frame_buttons, text = 'Add New Cell', command = e_handler.newCell) + btn_clear = tk.Button(master = frame_buttons, text = 'Clear Table', command = e_handler.clearTable) + + # Place the three buttons inside the frame + #btn_xml2table.pack(fill = tk.Y, padx = 5) + #btn_table2xml.pack(fill = tk.Y, padx = 5) + #btn_newCell.pack(fill = tk.Y, padx = 5) + + # Sticky = 'ew' to guarantee the buttons are all of the same width + btn_xml2table.grid(row = 0, column = 0, sticky = 'ew', padx = 5, pady = 5) + btn_table2xml.grid(row = 1, column = 0, sticky = 'ew', padx = 5, pady = 5) + btn_newCell.grid(row = 2, column = 0, sticky = 'ew', padx = 5, pady = 5) + btn_clear.grid(row = 3, column = 0, sticky = 'ew', padx = 5, pady = 5) + + + # ====================================== # + + + """ + Color Bar + 200 x 25 + """ + color_bar = ColorBar(root = frame_CB, compute_color_func = e_handler.compute_color, + W = 25, H = 200) + + + # ====================================== # + + """ + # Table Field + + ** This part is not initialized by default, but will be updated once a related button event occurs + """ + + + window.mainloop() + + +if __name__ == '__main__': + main() diff --git a/xml2table_v02_2.py b/xml2table_v02_2.py deleted file mode 100644 index 59df72d..0000000 --- a/xml2table_v02_2.py +++ /dev/null @@ -1,142 +0,0 @@ -""" -Front-end GUI for the python app XML2Table -to facilitate the Contact Energy Plugin settings in XML generated in CompuCell3D - -Visual Compenents and their usages (Left to Right) - - Text Field for XML(Contact Energy Plugin): - - XML section copy-pasted from CC3D.twedit to be converted to table - or - - XML section generated based on the adjusted table - - Four Buttons: - - Convert XML to Table - - Generate XML from Table - - Add a New Cell - - Clear the Table - - Color Bar Field: - - Table Field: -""" -import tkinter as tk - - -from utils.EventHandler import EventHandler -from visual_components.ColorBar import ColorBar - -""" -# Base window -""" - -window = tk.Tk() -window.title("Simple XML2Table Editor") - -# Set minimal Size to ensure the texts in the buttons will be shown properly -window.rowconfigure(0, minsize = 200, weight = 1) -window.columnconfigure(0, minsize = 100, weight = 1) -window.columnconfigure(1, minsize = 150, weight = 1) -window.columnconfigure(2, minsize = 25, weight = 1) -window.columnconfigure(3, minsize = 100, weight = 1) - -# ====================================== # - - - -""" -# Create Frames for each region and attach them to the main window horizontally -# with default sizes -""" - -frame_txtField = tk.Frame(master = window, width = 60, height = 200) - -frame_buttons = tk.Frame(master = window, relief = tk.RAISED, bd = 2, width = 20, height = 200) - -frame_CB = tk.Frame(master = window, width = 30, height = 200) - -frame_table = tk.Frame(master = window, width = 100, height = 200) - -# ====================================== # - - -""" -# Arrange the Fields/Widgets accordingly inside the main window -""" -#frame_txtField.pack(fill = tk.BOTH, side = tk.LEFT, expand = True) -#frame_buttons.pack(fill = tk.Y, side = tk.LEFT, expand = True) -#frame_table.pack(fill = tk.BOTH, side = tk.LEFT, expand = True) - -frame_txtField.grid(row = 0, column = 0, sticky = 'nsew') -frame_buttons.grid(row = 0, column = 1, sticky = 'ns') -frame_CB.grid(row = 0, column = 2, sticky = 'ns') -frame_table.grid(row = 0, column = 3, sticky = 'nsew') - -# ====================================== # - - - -""" -# Text Field for XML -""" - -text_box = tk.Text(master = frame_txtField) # height = 10, width = 20) - -# Place text field inside the frame -text_box.pack(fill = tk.BOTH, expand = True) - -# ====================================== # -""" -# Event Handler Class Object -""" -e_handler = EventHandler(text_box, frame_table) - -# ====================================== # - - - - -""" -# Buttons - - convert to table - - convert to XML - - add new cell - - clear table - -# Event Handlers for each Button -""" - - -btn_xml2table = tk.Button(master = frame_buttons, text = 'Convert to Table', command = e_handler.toTable) -btn_table2xml = tk.Button(master = frame_buttons, text = 'Convert to XML', command = e_handler.toXML) -btn_newCell = tk.Button(master = frame_buttons, text = 'Add New Cell', command = e_handler.newCell) -btn_clear = tk.Button(master = frame_buttons, text = 'Clear Table', command = e_handler.clearTable) - -# Place the three buttons inside the frame -#btn_xml2table.pack(fill = tk.Y, padx = 5) -#btn_table2xml.pack(fill = tk.Y, padx = 5) -#btn_newCell.pack(fill = tk.Y, padx = 5) - -# Sticky = 'ew' to guarantee the buttons are all of the same width -btn_xml2table.grid(row = 0, column = 0, sticky = 'ew', padx = 5, pady = 5) -btn_table2xml.grid(row = 1, column = 0, sticky = 'ew', padx = 5, pady = 5) -btn_newCell.grid(row = 2, column = 0, sticky = 'ew', padx = 5, pady = 5) -btn_clear.grid(row = 3, column = 0, sticky = 'ew', padx = 5, pady = 5) - - -# ====================================== # - - -""" -Color Bar -200 x 25 -""" -color_bar = ColorBar(root = frame_CB, compute_color_func = e_handler.compute_color, - W = 25, H = 200) - - -# ====================================== # - -""" -# Table Field - -** This part is not initialized by default, but will be updated once a related button event occurs -""" - - -window.mainloop()