Skip to content

Commit

Permalink
Merge pull request #3 from SasView/standalone_cleanup
Browse files Browse the repository at this point in the history
Standalone cleanup
  • Loading branch information
mdoucet committed Jul 28, 2015
2 parents ae2a197 + d06c34c commit 225aca8
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 185 deletions.
13 changes: 4 additions & 9 deletions sasview/sasview.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ def write(self, buf):
PLUGIN_MODEL_DIR = 'plugin_models'
APP_NAME = 'SasView'

class SasViewApp(gui_manager.ViewApp):
"""
"""


class SasView():
"""
Main class for running the SasView application
Expand All @@ -103,7 +98,7 @@ def __init__(self):
"""
"""
#from gui_manager import ViewApp
self.gui = SasViewApp(0)
self.gui = gui_manager.SasViewApp(0)
# Set the application manager for the GUI
self.gui.set_manager(self)
# Add perspectives to the basic application
Expand All @@ -125,7 +120,7 @@ def __init__(self):
# P(r) perspective
try:
import sas.perspectives.pr as module
pr_plug = module.Plugin(standalone=False)
pr_plug = module.Plugin()
self.gui.add_perspective(pr_plug)
except:
logging.error("%s: could not find P(r) plug-in module"% APP_NAME)
Expand All @@ -134,7 +129,7 @@ def __init__(self):
#Invariant perspective
try:
import sas.perspectives.invariant as module
invariant_plug = module.Plugin(standalone=False)
invariant_plug = module.Plugin()
self.gui.add_perspective(invariant_plug)
except:
logging.error("%s: could not find Invariant plug-in module"% \
Expand All @@ -144,7 +139,7 @@ def __init__(self):
#Calculator perspective
try:
import sas.perspectives.calculator as module
calculator_plug = module.Plugin(standalone=False)
calculator_plug = module.Plugin()
self.gui.add_perspective(calculator_plug)
except:
logging.error("%s: could not find Calculator plug-in module"% \
Expand Down
117 changes: 45 additions & 72 deletions src/sas/guiframe/gui_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def __init__(self, parent, title,
"""
Initialize the Frame object
"""

PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size)
# title
self.title = title
Expand Down Expand Up @@ -363,7 +362,7 @@ def put_icon(self, frame):
icon = self.GetIcon()
frame.SetIcon(icon)
except:
pass
logging.error("ViewerFrame.put_icon: could not set icon")

def get_client_size(self):
"""
Expand Down Expand Up @@ -751,7 +750,6 @@ def reset_bookmark_menu(self, panel):
wx.EVT_MENU(self, id, cpanel._back_to_bookmark)
self._toolbar.Realize()


def build_gui(self):
"""
Build the GUI by setting up the toolbar, menu and layout.
Expand All @@ -778,7 +776,6 @@ def build_gui(self):
# Append item from plugin under menu file if necessary
self._populate_file_menu()


if not wx.VERSION_STRING >= '3.0.0.0':
self.SetMenuBar(self._menubar)

Expand Down Expand Up @@ -821,7 +818,6 @@ def _setup_layout(self):
self.SetStatusBar(self.sb)
# Load panels
self._load_panels()
self.set_default_perspective()

def SetStatusText(self, *args, **kwds):
"""
Expand Down Expand Up @@ -930,11 +926,7 @@ def _find_plugins(self, dir="perspectives"):
module = imp.load_module(name, file, item, info)
if hasattr(module, "PLUGIN_ID"):
try:
plug = module.Plugin()
if plug.set_default_perspective():
self._current_perspective = plug
plugins.append(plug)

plugins.append(module.Plugin())
msg = "Found plug-in: %s" % module.PLUGIN_ID
logging.info(msg)
except:
Expand Down Expand Up @@ -1510,42 +1502,42 @@ def _populate_file_menu(self):
if len(plugin.populate_file_menu()) > 0:
for item in plugin.populate_file_menu():
m_name, m_hint, m_handler = item
id = wx.NewId()
self._file_menu.Append(id, m_name, m_hint)
wx.EVT_MENU(self, id, m_handler)
wx_id = wx.NewId()
self._file_menu.Append(wx_id, m_name, m_hint)
wx.EVT_MENU(self, wx_id, m_handler)
self._file_menu.AppendSeparator()

style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS
if OPEN_SAVE_MENU:
id = wx.NewId()
wx_id = wx.NewId()
hint_load_file = "read all analysis states saved previously"
self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file)
wx.EVT_MENU(self, id, self._on_open_state_project)
self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file)
wx.EVT_MENU(self, wx_id, self._on_open_state_project)

if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
# some menu of plugin to be seen under file menu
hint_load_file = "Read a status files and load"
hint_load_file += " them into the analysis"
id = wx.NewId()
self._save_appl_menu = self._file_menu.Append(id,
wx_id = wx.NewId()
self._save_appl_menu = self._file_menu.Append(wx_id,
'&Open Analysis', hint_load_file)
wx.EVT_MENU(self, id, self._on_open_state_application)
wx.EVT_MENU(self, wx_id, self._on_open_state_application)
if OPEN_SAVE_MENU:
self._file_menu.AppendSeparator()
id = wx.NewId()
self._file_menu.Append(id, '&Save Project',
wx_id = wx.NewId()
self._file_menu.Append(wx_id, '&Save Project',
'Save the state of the whole analysis')
wx.EVT_MENU(self, id, self._on_save_project)
wx.EVT_MENU(self, wx_id, self._on_save_project)
if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
id = wx.NewId()
self._save_appl_menu = self._file_menu.Append(id, \
wx_id = wx.NewId()
self._save_appl_menu = self._file_menu.Append(wx_id, \
'&Save Analysis', 'Save state of the current active analysis panel')
wx.EVT_MENU(self, id, self._on_save_application)
wx.EVT_MENU(self, wx_id, self._on_save_application)
if not sys.platform == 'darwin':
self._file_menu.AppendSeparator()
id = wx.NewId()
self._file_menu.Append(id, '&Quit', 'Exit')
wx.EVT_MENU(self, id, self.Close)
wx_id = wx.NewId()
self._file_menu.Append(wx_id, '&Quit', 'Exit')
wx.EVT_MENU(self, wx_id, self.Close)

def _add_menu_file(self):
"""
Expand Down Expand Up @@ -1716,12 +1708,9 @@ def create_gui_data(self, data, path=None):
def get_data(self, path):
"""
"""
message = ""
log_msg = ''
output = []
error_message = ""
basename = os.path.basename(path)
root, extension = os.path.splitext(basename)
_, extension = os.path.splitext(basename)
if extension.lower() not in EXTENSIONS:
log_msg = "File Loader cannot "
log_msg += "load: %s\n" % str(basename)
Expand Down Expand Up @@ -2224,18 +2213,6 @@ def post_init(self):
if hasattr(item, "post_init"):
item.post_init()

def set_default_perspective(self):
"""
Choose among the plugin the first plug-in that has
"set_default_perspective" method and its return value is True will be
as a default perspective when the welcome page is closed
"""
for item in self.plugins:
if hasattr(item, "set_default_perspective"):
if item.set_default_perspective():
item.on_perspective(event=None)
return

def set_perspective(self, panels):
"""
Sets the perspective of the GUI.
Expand Down Expand Up @@ -2413,13 +2390,12 @@ def remove_data(self, data_id, theory_id=None):
theory_data, theory_state = item
total_plot_list.append(theory_data)
for new_plot in total_plot_list:
id = new_plot.id
for group_id in new_plot.list_group_id:
wx.PostEvent(self, NewPlotEvent(id=id,
wx.PostEvent(self, NewPlotEvent(id=new_plot.id,
group_id=group_id,
action='remove'))
#remove res plot: Todo: improve
wx.CallAfter(self._remove_res_plot, id)
wx.CallAfter(self._remove_res_plot, new_plot.id)
self._data_manager.delete_data(data_id=data_id,
theory_id=theory_id)

Expand Down Expand Up @@ -2454,26 +2430,26 @@ def save_data1d(self, data, fname):
# This is MAC Fix
ext_num = dlg.GetFilterIndex()
if ext_num == 0:
format = '.txt'
ext_format = '.txt'
else:
format = '.xml'
path = os.path.splitext(path)[0] + format
ext_format = '.xml'
path = os.path.splitext(path)[0] + ext_format
mypath = os.path.basename(path)

#Instantiate a loader
loader = Loader()
format = ".txt"
if os.path.splitext(mypath)[1].lower() == format:
ext_format = ".txt"
if os.path.splitext(mypath)[1].lower() == ext_format:
# Make sure the ext included in the file name
# especially on MAC
fName = os.path.splitext(path)[0] + format
fName = os.path.splitext(path)[0] + ext_format
self._onsaveTXT(data, fName)
format = ".xml"
if os.path.splitext(mypath)[1].lower() == format:
ext_format = ".xml"
if os.path.splitext(mypath)[1].lower() == ext_format:
# Make sure the ext included in the file name
# especially on MAC
fName = os.path.splitext(path)[0] + format
loader.save(fName, data, format)
fName = os.path.splitext(path)[0] + ext_format
loader.save(fName, data, ext_format)
try:
self._default_save_location = os.path.dirname(path)
except:
Expand Down Expand Up @@ -2597,21 +2573,21 @@ def save_data2d(self, data, fname):
# This is MAC Fix
ext_num = dlg.GetFilterIndex()
if ext_num == 0:
format = '.dat'
ext_format = '.dat'
else:
format = ''
path = os.path.splitext(path)[0] + format
ext_format = ''
path = os.path.splitext(path)[0] + ext_format
mypath = os.path.basename(path)

#Instantiate a loader
loader = Loader()

format = ".dat"
if os.path.splitext(mypath)[1].lower() == format:
ext_format = ".dat"
if os.path.splitext(mypath)[1].lower() == ext_format:
# Make sure the ext included in the file name
# especially on MAC
fileName = os.path.splitext(path)[0] + format
loader.save(fileName, data, format)
fileName = os.path.splitext(path)[0] + ext_format
loader.save(fileName, data, ext_format)
try:
self._default_save_location = os.path.dirname(path)
except:
Expand Down Expand Up @@ -3205,9 +3181,9 @@ def __init__(self, parent, *args, **kwds):



class ViewApp(wx.App):
class SasViewApp(wx.App):
"""
Toy application to test this Frame
SasView application
"""
def OnInit(self):
"""
Expand Down Expand Up @@ -3293,8 +3269,8 @@ def clean_plugin_models(self, path):
if os.path.exists(model_folder) and os.path.isdir(model_folder):
if len(os.listdir(model_folder)) > 0:
try:
for file in os.listdir(model_folder):
file_path = os.path.join(model_folder, file)
for filename in os.listdir(model_folder):
file_path = os.path.join(model_folder, filename)
if os.path.isfile(file_path):
os.remove(file_path)
except:
Expand All @@ -3313,10 +3289,7 @@ def build_gui(self):
Build the GUI
"""
#try to load file at the start
try:
self.open_file()
except:
raise
self.open_file()
self.frame.build_gui()

def set_welcome_panel(self, panel_class):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

class Plugin(PluginBase):

def __init__(self, standalone=False):
PluginBase.__init__(self, name="DataLoader", standalone=standalone)
def __init__(self):
PluginBase.__init__(self, name="DataLoader")
# Default location
self._default_save_location = DEFAULT_OPEN_FOLDER
self.loader = Loader()
Expand Down
4 changes: 2 additions & 2 deletions src/sas/guiframe/local_perspectives/plotting/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Plugin(PluginBase):
Plug-in class to be instantiated by the GUI manager
"""

def __init__(self, standalone=False):
PluginBase.__init__(self, name="Plotting", standalone=standalone)
def __init__(self):
PluginBase.__init__(self, name="Plotting")

## Plot panels
self.plot_panels = {}
Expand Down
15 changes: 1 addition & 14 deletions src/sas/guiframe/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ class for the Foo plug-in. The interface of that Plugin class
See dummyapp.py for a plugin example.
"""

def __init__(self, name="Test_plugin", standalone=True):
def __init__(self, name="Test_plugin"):
"""
Abstract class for gui_manager Plugins.
"""
# Define if the plugin is local to Viewerframe and always active
self._always_active = False
## Plug-in name. It will appear on the application menu.
self.sub_menu = name
#standalone flag
self.standalone = standalone
## Reference to the parent window. Filled by get_panels() below.
self.parent = None
self.frame = None
Expand Down Expand Up @@ -262,17 +260,6 @@ def post_init(self):
"""
pass

def set_default_perspective(self):
"""
Call back method that True to notify the parent that the current plug-in
can be set as default perspective.
when returning False, the plug-in is not candidate for an automatic
default perspective setting
"""
if self.standalone:
return True
return False

def set_state(self, state=None, datainfo=None):
"""
update state
Expand Down
4 changes: 2 additions & 2 deletions src/sas/perspectives/calculator/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Plugin(PluginBase):
This class defines the interface for a Plugin class
for calculator perspective
"""
def __init__(self, standalone=True):
PluginBase.__init__(self, name="Calculator", standalone=standalone)
def __init__(self):
PluginBase.__init__(self, name="Calculator")
# Log startup
logging.info("Calculator plug-in started")
self.sub_menu = "Tool"
Expand Down
Loading

0 comments on commit 225aca8

Please sign in to comment.