Commit 618d75c2 authored by Taylor Hanayik's avatar Taylor Hanayik
Browse files

style updates

parent 42b86f2c
......@@ -10,6 +10,7 @@ import wx
import yaml
import fsleyes_props as props
from fsl.utils import idle
import fsl.gui.exceptions as fslerrs
import fsl.gui.widgets as fslwidgets
......@@ -36,6 +37,27 @@ allowedKeys = (
)
def runCommand(propObj, button):
"""
if a propObj has a run method, then this funnction will call it
and run it on the idle loop.
"""
if hasattr(propObj, "run"):
idle.run(propObj.run, onFinish=updateStatus)
updateStatus("BUSY")
else:
print(propObj, " has no attribute: run")
def updateStatus(msg="IDLE"):
"""
if a frame has a statusbar then set its text with msg.
Useful for indicating "busy" or "idle" for jobs runnining on another thread
"""
tlw = wx.GetTopLevelWindows()[0]
if hasattr(tlw, "statusbar"):
tlw.statusbar.SetStatusText(msg)
def isGroupKey(key):
"""
returns True is key == "group"
......@@ -165,6 +187,15 @@ def widgetFromKey(key):
widget = getattr(fslwidgets, key)
return widget
def popStyle(v):
if type(v) is dict and "style" in v.keys():
style = v.pop("style")
flag = style["flag"]
att = getattr(wx, flag, 0)
return att
else:
return 0
def makeWidget(parent, propObj, key, tag, value):
"""
returns the appropriate widget from a key string
......@@ -192,6 +223,14 @@ def makeWidget(parent, propObj, key, tag, value):
w = wid(parent)
return w
def addToParent(parent, widget, style=0, proportion=0, defflags=wx.ALL | wx.EXPAND, border=5):
if style == wx.CENTER:
parent.GetSizer().AddStretchSpacer(prop=1)
parent.GetSizer().Add(widget, proportion=0, flag=defflags | style, border=border)
parent.GetSizer().AddStretchSpacer(prop=1)
else:
parent.GetSizer().Add(widget, proportion=0, flag=defflags | style, border=border)
def layout(parent, buildSpec, propObj):
"""
layout all allowed widgets in a buildSpec
......@@ -199,9 +238,10 @@ def layout(parent, buildSpec, propObj):
for entry in buildSpec:
for k, v in entry.items():
k, t = parseWidgetKey(k)
w = makeWidget(parent, propObj, k, t, v,)
style = popStyle(v)
w = makeWidget(parent, propObj, k, t, v)
if not isPage(w):
parent.GetSizer().Add(w, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
addToParent(parent=parent, widget=w, style=style)
layoutFrom(w)
if isContainerKey(k):
if type(v) is list:
......@@ -216,6 +256,8 @@ def buildGUI(buildSpec, propObj):
"""
checkSpec(buildSpec)
mainWin = wx.Frame(None)
mainWin.statusbar = mainWin.CreateStatusBar(1)
updateStatus()
mainWin.SetTitle(buildSpec['appName'])
mainWin.SetSize((buildSpec['windowSize']['width'], buildSpec['windowSize']['height']))
......@@ -223,7 +265,8 @@ def buildGUI(buildSpec, propObj):
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainWin.SetSizer(mainSizer)
mainWin = layout(mainWin, buildSpec['layout'], propObj)
mainWin.Fit()
mainWin.Centre()
mainWin.Show()
return mainWin
......
......@@ -186,7 +186,7 @@ class FsleyesImage(wx.Panel):
# bind events
self.btn_fsleyes.Bind(wx.EVT_BUTTON, self.launch_fsleyes)
propobj.addListener('inputFile', 'inputFileListener', self.add_image)
propobj.addListener('inputFile', 'FsleyesListener', self.add_image)
def _run_fsleyes(self):
imgs = [img.dataSource for img in self.overlayList]
......@@ -209,6 +209,7 @@ class FsleyesImage(wx.Panel):
self.overlayList.clear()
def add_image(self, new_img, valid, context, name):
self.reset()
img = fslimage.Image(new_img)
self.overlayList.append(img)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment