Skip to content
Snippets Groups Projects
Commit 9df4108e authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Loads of trouble getting dialogs (SimpleMessageDialog and subclasses) to

actually draw under Linux/GTK. ProcessingDialog now (by default) runs
task in a separate thread, and periodically wx.Yields, to ensure that
the dialog does get drawn.
parent 313bef98
No related branches found
No related tags found
No related merge requests found
......@@ -204,6 +204,7 @@ class AtlasOverlayPanel(fslpanel.FSLViewPanel):
self.__atlasPanel,
label.index)
regionList.SetItemWidget(i, widget)
wx.Yield()
filterStr = self.__regionFilter.GetValue().lower().strip()
regionList.ApplyFilter(filterStr, ignoreCase=True)
......@@ -213,7 +214,7 @@ class AtlasOverlayPanel(fslpanel.FSLViewPanel):
dialog.ProcessingDialog(
None,
strings.messages[self, 'loadRegions'].format(atlasDesc.name),
buildRegionList).Run()
buildRegionList).Run(mainThread=True)
log.debug('Showing region list for {} ({})'.format(
atlasDesc.atlasID, id(regionList)))
......
......@@ -225,9 +225,8 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default', saveDir=True):
# being used, create a dialog window
# to show the currently loading image
if defaultLoad:
import wx
import fsl.utils.dialog as fsldlg
loadDlg = fsldlg.SimpleMessageDialog(wx.GetApp().GetTopWindow())
loadDlg = fsldlg.SimpleMessageDialog()
# The default load function updates
# the dialog window created above
......
......@@ -7,11 +7,14 @@
import wx
import threading
import fsl.data.strings as strings
SMD_KEEP_CENTERED = 1
class SimpleMessageDialog(wx.Dialog):
......@@ -20,11 +23,18 @@ class SimpleMessageDialog(wx.Dialog):
Style defaults to SMD_KEEP_CENTERED.
"""
if style is None:
style = SMD_KEEP_CENTERED
wx.Dialog.__init__(self, parent, style=wx.STAY_ON_TOP)
if parent is None:
parent = wx.GetApp().GetTopWindow()
wx.Dialog.__init__(self,
parent,
style=wx.STAY_ON_TOP | wx.FULL_REPAINT_ON_RESIZE)
self.__style = style
self.__message = wx.StaticText(
......@@ -39,41 +49,45 @@ class SimpleMessageDialog(wx.Dialog):
proportion=1,
flag=wx.CENTRE | wx.ALL)
self.SetTransparent(240)
self.SetBackgroundColour((225, 225, 200))
self.SetSizer(self.__sizer)
self.SetMessage(message)
def SetMessage(self, msg):
msg = str(msg)
self.__message.SetLabel(msg)
# Figure out the dialog size
# required to fit the message
dc = wx.ClientDC(self.__message)
defWidth, defHeight = 25, 25
msgWidth, msgHeight = dc.GetTextExtent(msg)
width, height = dc.GetTextExtent(msg)
if msgWidth > defWidth: width = msgWidth + 25
else: width = defWidth
if msgHeight > defHeight: height = msgHeight + 25
else: height = defHeight
# +50 to account for sizer borders (see __init__),
# plus a bit more for good measure. In particular,
# under GTK, the message seems to be vertically
# truncated if we don't add some extra padding
width += 60
height += 70
self.__message.SetMinSize((width, height))
self.SetMinClientSize((width, height))
self.SetClientSize(( width, height))
self.Fit()
self.Refresh()
self.Update()
self.Layout()
if self.__style & SMD_KEEP_CENTERED:
self.CentreOnParent()
self.Refresh()
self.Update()
wx.Yield()
class TimeoutDialog(SimpleMessageDialog):
......@@ -107,7 +121,7 @@ class ProcessingDialog(SimpleMessageDialog):
:arg message:
:arg task:
:arg task:
:arg passFuncs:
......@@ -127,26 +141,51 @@ class ProcessingDialog(SimpleMessageDialog):
kwargs['errortFunc'] = kwargs.get('errorFunc',
self.__defaultErrorFunc)
self.task = task
self.args = args
self.kwargs = kwargs
self.task = task
self.args = args
self.kwargs = kwargs
self.message = message
style = kwargs.pop('style', None)
SimpleMessageDialog.__init__(self, parent, message, style=style)
SimpleMessageDialog.__init__(self, parent, style=style)
def Run(self):
def Run(self, mainThread=False):
"""
disable = wx.WindowDisabler()
If mainThread=True, the task should call wx.Yield periodically
(under GTK, there is a chance that the ProcessingDialog will not
get drawn before the task begins).
"""
self.CentreOnParent()
self.SetMessage(self.message)
self.Show()
self.SetFocus()
self.Refresh()
self.Update()
wx.Yield()
disable = wx.WindowDisabler(self)
if mainThread:
result = self.task(*self.args, **self.kwargs)
else:
returnVal = [None]
def wrappedTask():
returnVal[0] = self.task(*self.args, **self.kwargs)
thread = threading.Thread(target=wrappedTask)
thread.start()
while thread.isAlive():
thread.join(0.2)
wx.Yield()
result = returnVal[0]
result = self.task(*self.args, **self.kwargs)
self.Close()
self.Destroy()
......@@ -281,8 +320,7 @@ class TextEditDialog(wx.Dialog):
if cb.Open():
cb.SetData(wx.TextDataObject(text))
cb.Close()
td = TimeoutDialog(self, 'Copied!')
td.CentreOnParent()
td = TimeoutDialog(self, 'Copied!', 1000)
td.Show()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment