Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unzip_parts.py - Reduce working memory size by reading and writing sm… #455

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
AssignPartsEvent, EVT_ASSIGN_PARTS_EVENT = NewEvent()
PopulateFootprintListEvent, EVT_POPULATE_FOOTPRINT_LIST_EVENT = NewEvent()
UpdateSetting, EVT_UPDATE_SETTING = NewEvent()
LogboxAppendEvent, EVT_LOGBOX_APPEND_EVENT = NewEvent()
25 changes: 16 additions & 9 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
from .const import Column
from .events import (
EVT_ASSIGN_PARTS_EVENT,
EVT_LOGBOX_APPEND_EVENT,
EVT_MESSAGE_EVENT,
EVT_POPULATE_FOOTPRINT_LIST_EVENT,
EVT_RESET_GAUGE_EVENT,
EVT_UPDATE_GAUGE_EVENT,
EVT_UPDATE_SETTING,
LogboxAppendEvent,
)
from .fabrication import Fabrication
from .helpers import (
Expand Down Expand Up @@ -501,6 +503,7 @@ def __init__(self, parent, kicad_provider=KicadProvider()):
self.Bind(EVT_ASSIGN_PARTS_EVENT, self.assign_parts)
self.Bind(EVT_POPULATE_FOOTPRINT_LIST_EVENT, self.populate_footprint_list)
self.Bind(EVT_UPDATE_SETTING, self.update_settings)
self.Bind(EVT_LOGBOX_APPEND_EVENT, self.logbox_append)

self.enable_part_specific_toolbar_buttons(False)

Expand Down Expand Up @@ -897,6 +900,10 @@ def update_settings(self, e):
self.settings[e.section][e.setting] = e.value
self.save_settings()

def logbox_append(self, e):
"""Write text to the logbox."""
self.logbox.WriteText(e.msg)

def load_settings(self):
"""Load settings from settings.json."""
with open(os.path.join(PLUGIN_PATH, "settings.json"), encoding="utf-8") as j:
Expand Down Expand Up @@ -1092,7 +1099,7 @@ def init_logger(self):
handler1 = logging.StreamHandler(sys.stderr)
handler1.setLevel(logging.DEBUG)
# and to our GUI
handler2 = LogBoxHandler(self.logbox)
handler2 = LogBoxHandler(self.logbox, self)
handler2.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(funcName)s - %(message)s",
Expand All @@ -1112,15 +1119,15 @@ def __del__(self):
class LogBoxHandler(logging.StreamHandler):
"""Logging class for the logging textbox at th ebottom of the mainwindow."""

def __init__(self, textctrl):
def __init__(self, textctrl, event_destination):
logging.StreamHandler.__init__(self)
self.textctrl = textctrl
self.event_destination = event_destination

def emit(self, record):
"""Pokemon exception that hopefully helps getting this working with threads."""
try:
msg = self.format(record)
self.textctrl.WriteText(msg + "\n")
self.flush()
except: # pylint: disable=bare-except
pass
"""Marshal the event over to the main thread."""
msg = self.format(record)
wx.QueueEvent(self.event_destination, LogboxAppendEvent(
msg=f"{msg}\n"
)
)
7 changes: 3 additions & 4 deletions unzip_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ def unzip_parts(path):
# Open the split file
with open(split_path, "rb") as split_file:
# Read the file data
file_data = split_file.read()

# Append the file data to the original file
db.write(file_data)
while (file_data := split_file.read(1024 * 1024)):
# Append the file data to the original file
db.write(file_data)

# Delete the split file
os.unlink(split_path)
Expand Down