Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
custom BusyDlg, minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Szymaniak committed Jan 31, 2019
1 parent e9b99b7 commit cff5ae4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
40 changes: 34 additions & 6 deletions subsync/gui/busydlg.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import wx


class BusyDlg(object):
def __init__(self, msg):
self.msg = msg
self.dlg = None
class BusyDlg(wx.Frame):
def __init__(self, parent, msg):
style = wx.BORDER_SIMPLE | wx.FRAME_TOOL_WINDOW
if parent:
style |= wx.FRAME_FLOAT_ON_PARENT

super().__init__(parent, style=style)

self.disabler = None
panel = wx.Panel(self)
text = wx.StaticText(panel, label=msg)

fgColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
bgColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)

for win in [panel, text]:
win.SetCursor(wx.HOURGLASS_CURSOR)
win.SetForegroundColour(fgColor)
win.SetBackgroundColour(bgColor)

size = text.GetBestSize()
self.SetClientSize((size.width + 80, size.height + 40))
panel.SetSize(self.GetClientSize())
text.Center()
self.Center()

def __enter__(self):
self.dlg = wx.BusyInfo(self.msg)
self.disabler = wx.WindowDisabler(self)
self.Show()
self.Refresh()
self.Update()
wx.Yield()

def __exit__(self, type, value, traceback):
del self.dlg
self.Close()

if self.disabler:
del self.disabler
self.disabler = None

20 changes: 11 additions & 9 deletions subsync/gui/mainwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def onMenuItemCheckUpdateClick(self, event):
assetManager.updateTask.start()

if assetManager.updateTask.isRunning():
with BusyDlg(_('Checking for update...')):
with BusyDlg(self, _('Checking for update...')):
while assetManager.updateTask.isRunning():
wx.Yield()

Expand Down Expand Up @@ -181,21 +181,23 @@ def validateAssets(self):
langs = sorted([subs.lang, refs.lang])
needAssets.append(assetManager.getAsset('dict', langs))

missingAssets = [ a for a in needAssets if not a.isLocal() ]
downloadAssets = [ a for a in missingAssets if a.isRemote() ]
missingAssets = [ asset for asset in needAssets if not asset.isLocal() ]
downloadAssets = [ asset for asset in missingAssets if asset.isRemote() ]
if downloadAssets:
if not self.askForDownloadAssets(downloadAssets):
return False

updateAssets = [ a for a in needAssets if a.remoteVersion() > a.localVersion() ]
updateAssets = [ asset for asset in needAssets
if asset.remoteVersion() > asset.localVersion()
and asset not in downloadAssets ]
if updateAssets:
self.askForUpdateAssets(updateAssets)

return True

def askForDownloadAssets(self, assetList):
msg = [ _('Following assets must be download to continue:') ]
msg += [ ' - ' + a.getPrettyName() for a in assetList ]
msg = [ _('Following assets must be download to continue:') ]
msg += [ ' - ' + asset.getPrettyName() for asset in assetList ]
msg += [ '', ('Download now?') ]
title = _('Download assets')
flags = wx.YES_NO | wx.ICON_QUESTION
Expand All @@ -205,8 +207,8 @@ def askForDownloadAssets(self, assetList):
return False

def askForUpdateAssets(self, assetList):
msg = [ _('Following assets could be updated:') ]
msg += [ ' - ' + a.getPrettyName() for a in assetList ]
msg = [ _('Following assets could be updated:') ]
msg += [ ' - ' + asset.getPrettyName() for asset in assetList ]
msg += [ '', ('Update now?') ]
title = _('Update assets')
flags = wx.YES_NO | wx.ICON_QUESTION
Expand Down Expand Up @@ -254,7 +256,7 @@ def runUpdater(self, askForUpdate=True):

if askForUpdate:
dlg = wx.MessageDialog(
parent if parent else self,
self,
_('New version is ready to be installed. Upgrade now?'),
_('Upgrade'),
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
Expand Down
8 changes: 4 additions & 4 deletions subsync/gui/openwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def showOpenFileDlg(parent, stream):
_('All files'), '*.*' ])

path = filedlg.showOpenFileDlg(parent, **props)
return readStream(path, stream.types)
return readStream(parent, path, stream.types)


def readStream(path, types):
def readStream(parent, path, types):
if path:
with busydlg.BusyDlg(_('Loading, please wait...')):
with busydlg.BusyDlg(parent, _('Loading, please wait...')):
return Stream(path=path, types=types)


Expand All @@ -44,7 +44,7 @@ def __init__(self, parent, stream):
@error_dlg
def openStream(self, stream=None, path=None):
if path:
return readStream(path, self.stream.types)
return readStream(self, path, self.stream.types)

self.stream = stream
self.m_textPath.SetValue(self.stream.path)
Expand Down
2 changes: 1 addition & 1 deletion subsync/gui/subpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def onDropSubFile(self, filename):

@error_dlg
def showOpenWinWithFile(filename):
stream = openwin.readStream(filename, self.stream.types)
stream = openwin.readStream(self, filename, self.stream.types)
settings().lastdir = os.path.dirname(filename)
self.showOpenWin(stream)

Expand Down
4 changes: 2 additions & 2 deletions subsync/gui/syncwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, parent, subs, refs, refsCache=None, listener=None):
self.updateTimer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onUpdateTimerTick, self.updateTimer)

with busydlg.BusyDlg(_('Loading, please wait...')):
with busydlg.BusyDlg(self, _('Loading, please wait...')):
self.sync = synchro.Synchronizer(self, self.subs, self.refs, refsCache)
self.sync.start()

Expand Down Expand Up @@ -171,7 +171,7 @@ def ShowModal(self):
return res

def onClose(self, event):
with busydlg.BusyDlg(_('Terminating, please wait...')):
with busydlg.BusyDlg(self, _('Terminating, please wait...')):
self.stop()

if self.sync:
Expand Down
2 changes: 1 addition & 1 deletion subsync/loggercfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def filter(self, record):

def init(level=None, path=None):
logging.basicConfig(
format='%(asctime)s:%(threadName)12.12s:%(levelname)8.8s:%(name)12.12s: %(message)s',
format='%(asctime)s:%(threadName)12.12s:%(levelname)8.8s:%(name)24.24s: %(message)s',
level=level,
filename=path)

Expand Down
11 changes: 11 additions & 0 deletions subsync/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def createProducerPipelines(stream, no=None, timeWindows=None):

pipes = []
for i in range(no):
processPendingEvents()

p = createProducerPipeline(stream)
pipes.append(p)

Expand All @@ -173,3 +175,12 @@ def createProducerPipelines(stream, no=None, timeWindows=None):

return pipes


def processPendingEvents():
try:
import wx
if wx.App.Get() and wx.IsMainThread():
wx.Yield()
except:
pass

0 comments on commit cff5ae4

Please sign in to comment.