Skip to content

ArriZa-Wi/Python_MWC3_2026

Repository files navigation

Game Shop Inventory Manager

Important

This project is a submission for the MWC3 Python competition and won 1st place.

A config-driven data management application for tracking game shop inventory. It offers both a Tkinter GUI and a console-based CLI, with full CRUD operations, CSV import/export, searching, sorting, and data merging — all powered by pandas.


Dependencies

  • Python 3.10+
  • pandas (pip install -r requirements.txt)
  • tkinter (included with Python)

How to Run

pip install -r requirements.txt
python main.py

On launch, you are prompted to choose between the graphical interface (option 1) or the console interface (option 2).


Project Structure

File Purpose
main.py Application entry point — launches GUI or CLI
config.py Central schema and app settings
models.py Record data model class
data_manager.py Pandas-powered data engine (CRUD, CSV, search, merge)
gui.py Tkinter graphical interface
console_ui.py Menu-driven console interface
requirements.txt Python dependencies
REFERENCES.md Documentation reference for all libraries used

Features & How They Work

Centralized Configuration (config.py)

All data schema definitions live in config.py. The column schema is defined as a list of tuples — each specifying the column name, Python type, whether it's required, and its default value. Every other module reads from these constants, so changing the data schema only requires editing one file.

Key constants:

  • COLUMNS — defines the full schema (name, type, required flag, default)
  • PRIMARY_KEY — the unique identifier column (storeid)
  • COLUMN_NAMES, COLUMN_TYPES, REQUIRED_COLUMNS, COLUMN_DEFAULTS — derived helpers used across modules

Data Model (models.py)

The Record class represents a single inventory entry. Its attributes are set dynamically from the config schema.

Method Description
__init__(**kwargs) Initializes attributes dynamically from config.COLUMNS
__str__() Returns a human-readable pipe-separated string of all fields
__repr__() Returns a developer-readable string that can recreate the object
__eq__(other) Compares records by primary key for equality checks
to_dict() Converts the record to a dictionary for pandas interop
from_dict(data) Class method that creates a Record from a dictionary

Data Manager (data_manager.py)

The DataManager class is the core data engine. It wraps a pandas DataFrame and provides all data operations.

CSV Operations

Method Description
load_csv(filepath) Reads a CSV file, normalizes column names, applies the config schema, and replaces current data
import_csv(filepath) Reads a CSV and merges it into the existing DataFrame (appends new records, updates existing ones)
export_csv(filepath) Writes the current DataFrame to a CSV file

CRUD Operations

Method Description
add_record(record_dict) Adds a new record; raises ValueError on duplicate primary key
get_record(key_value) Retrieves a single record by primary key
update_record(key_value, updates) Updates specified fields of an existing record
remove_record(key_value) Deletes a record by primary key

Search & Utility

Method Description
search(column, query) Case-insensitive partial match for strings; exact match for numeric columns
get_all() Returns the entire DataFrame
merge_dataframes(incoming_df) Merges an incoming DataFrame — appends new primary keys, updates existing ones
record_count() Returns the total number of records

Graphical Interface (gui.py)

The Application class extends tk.Tk and builds the full GUI window.

Component Built by Description
Menu bar _create_menu_bar() File menu (Import CSV, Merge CSV, Export CSV, Exit) and Data menu (Add record, Edit selected)
Toolbar _create_toolbar() Buttons for Import CSV, Add, Edit, Delete, Export, and Refresh
Search bar _create_search_bar() Column dropdown selector + live search entry with clear button
Data table _create_treeview() Scrollable ttk.Treeview displaying all records with sortable column headers
Status bar _create_status_bar() Displays current record count and status messages

Key interaction methods:

Method Description
_refresh_table() Reloads the Treeview from the current DataFrame
_sort_column(col) Sorts the table by a column, toggling ascending/descending on each click
_on_search(*args) Filters the table in real-time as the user types
_import_csv() Opens a file dialog and loads a CSV, replacing current data
_merge_csv() Opens a file dialog and merges a CSV into existing data
_export_csv() Opens a save dialog and exports data to CSV
_add_record_dialog() Opens a form dialog to manually add a new record
_open_edit_dialog(item_id) Opens a pre-filled edit dialog for the selected record (primary key field is disabled)
_delete_selected() Deletes selected record(s) with a confirmation prompt
_on_double_click(event) Double-clicking a row opens the edit dialog

Console Interface (console_ui.py)

The ConsoleUI class provides a menu-driven text interface with the same data capabilities as the GUI.

Menu Option Method Description
1. Import from CSV _import_csv() Opens a file dialog; offers Replace or Merge if data already exists
2. Add a record _add_record() Prompts for each field defined in config, with required/default indicators
3. View all records _view_all() Displays all records in a formatted pandas table
4. Search records _search() Lets user pick a column and enter a search term
5. Update a record _update_record() Looks up a record by primary key, then prompts for new values
6. Delete a record _delete_record() Looks up and displays a record, then asks for confirmation before deleting
7. Export to CSV _export_csv() Opens a save dialog and exports the data
0. Exit _exit() Exits the application

Helper functions:

  • _ask_open_file() / _ask_save_file() — module-level functions that reuse a hidden Tk root window to show file dialogs from the console without reinitializing Tk each time
  • _display_records(df) — renders a DataFrame as a readable table in the terminal
  • _print_header() / _print_separator() / _pause() — formatting and flow control helpers

Entry Point (main.py)

Function Description
main() Prompts the user to select GUI (1) or Console (2)
launch_gui() Imports and starts the Tkinter Application
launch_console() Imports and starts the ConsoleUI menu loop

Data Schema

The default schema tracks game shop inventory with the following columns:

Column Type Required Default
title str Yes None
publisher str No (empty)
platform str No (empty)
msrp float No 0.0
purchaseprice float No 0.0
condition str No (empty)
storeid str Yes (Primary Key) None

The schema is fully configurable in config.py — changing the COLUMNS list automatically updates both the GUI and console interfaces.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages