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

[UI] improve GGPK reading performance #22

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
UI: use a new callback argument when reading GGPK, add a timer to onl…
…y emit progress bar changes once every 200ms
  • Loading branch information
Vlad Zhukov committed Feb 19, 2017
commit 2c83ff02b1d939f44e6406fb684138df721f2c5e
36 changes: 14 additions & 22 deletions PyPoE/ui/shared/file/ggpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

# Python
import os
from functools import wraps
import time

# 3rd-party
from PySide.QtCore import *
Expand Down Expand Up @@ -113,33 +113,25 @@ def __init__(self, file_path, *args, **kwargs):
self._file_path = file_path
self.ggpk_file = None
self._size = 0
self._time = 0

self.sig_update_progress.connect(self._progress_updater)

self.progress_bar = GGPKProgressDialog('')

def _progress_ggpk(self, func):
"""
Hook for GGPKFile._read_record
"""
fm = self.parent()

@wraps(func)
def temp(*args, **kwargs):
if not self._size:
self._size = kwargs['ggpkfile'].seek(0, os.SEEK_END)
kwargs['ggpkfile'].seek(0, os.SEEK_SET)
else:
#kwargs['offset'])

def _progress_ggpk(self, records, ggpkfile, offset):
if not self._size:
self._size = ggpkfile.seek(0, os.SEEK_END)
ggpkfile.seek(0, os.SEEK_SET)
else:
# Emit the event every 200 ms
current_time = time.perf_counter()
if current_time - self._time > 0.2:
self._time = current_time
self.progress_bar.sig_progress.emit(
int(kwargs['offset'] / self._size * 100)
int(offset / self._size * 100)
)

return func(*args, **kwargs)

return temp

def _progress_updater(self, title, max, *args, **kwargs):
p = self.parent().parent()

Expand All @@ -159,8 +151,8 @@ def run(self):
self.sig_update_progress.emit(self.tr('Reading GGPK records...'), 100)
ggpk_file = GGPKFile()
# Hook the function for progress bar
ggpk_file._read_record = self._progress_ggpk(ggpk_file._read_record)
ggpk_file.read(self._file_path)
# ggpk_file._read_record = self._progress_ggpk(ggpk_file._read_record)
ggpk_file.read(self._file_path, callback=self._progress_ggpk)
# Finished
self.progress_bar.sig_progress.emit(100)

Expand Down