Skip to content

Commit 225aca8

Browse files
committed
Merge pull request #3 from SasView/standalone_cleanup
Standalone cleanup
2 parents ae2a197 + d06c34c commit 225aca8

File tree

11 files changed

+115
-185
lines changed

11 files changed

+115
-185
lines changed

sasview/sasview.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ def write(self, buf):
9090
PLUGIN_MODEL_DIR = 'plugin_models'
9191
APP_NAME = 'SasView'
9292

93-
class SasViewApp(gui_manager.ViewApp):
94-
"""
95-
"""
96-
97-
9893
class SasView():
9994
"""
10095
Main class for running the SasView application
@@ -103,7 +98,7 @@ def __init__(self):
10398
"""
10499
"""
105100
#from gui_manager import ViewApp
106-
self.gui = SasViewApp(0)
101+
self.gui = gui_manager.SasViewApp(0)
107102
# Set the application manager for the GUI
108103
self.gui.set_manager(self)
109104
# Add perspectives to the basic application
@@ -125,7 +120,7 @@ def __init__(self):
125120
# P(r) perspective
126121
try:
127122
import sas.perspectives.pr as module
128-
pr_plug = module.Plugin(standalone=False)
123+
pr_plug = module.Plugin()
129124
self.gui.add_perspective(pr_plug)
130125
except:
131126
logging.error("%s: could not find P(r) plug-in module"% APP_NAME)
@@ -134,7 +129,7 @@ def __init__(self):
134129
#Invariant perspective
135130
try:
136131
import sas.perspectives.invariant as module
137-
invariant_plug = module.Plugin(standalone=False)
132+
invariant_plug = module.Plugin()
138133
self.gui.add_perspective(invariant_plug)
139134
except:
140135
logging.error("%s: could not find Invariant plug-in module"% \
@@ -144,7 +139,7 @@ def __init__(self):
144139
#Calculator perspective
145140
try:
146141
import sas.perspectives.calculator as module
147-
calculator_plug = module.Plugin(standalone=False)
142+
calculator_plug = module.Plugin()
148143
self.gui.add_perspective(calculator_plug)
149144
except:
150145
logging.error("%s: could not find Calculator plug-in module"% \

src/sas/guiframe/gui_manager.py

Lines changed: 45 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def __init__(self, parent, title,
234234
"""
235235
Initialize the Frame object
236236
"""
237-
238237
PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size)
239238
# title
240239
self.title = title
@@ -363,7 +362,7 @@ def put_icon(self, frame):
363362
icon = self.GetIcon()
364363
frame.SetIcon(icon)
365364
except:
366-
pass
365+
logging.error("ViewerFrame.put_icon: could not set icon")
367366

368367
def get_client_size(self):
369368
"""
@@ -751,7 +750,6 @@ def reset_bookmark_menu(self, panel):
751750
wx.EVT_MENU(self, id, cpanel._back_to_bookmark)
752751
self._toolbar.Realize()
753752

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

781-
782779
if not wx.VERSION_STRING >= '3.0.0.0':
783780
self.SetMenuBar(self._menubar)
784781

@@ -821,7 +818,6 @@ def _setup_layout(self):
821818
self.SetStatusBar(self.sb)
822819
# Load panels
823820
self._load_panels()
824-
self.set_default_perspective()
825821

826822
def SetStatusText(self, *args, **kwds):
827823
"""
@@ -930,11 +926,7 @@ def _find_plugins(self, dir="perspectives"):
930926
module = imp.load_module(name, file, item, info)
931927
if hasattr(module, "PLUGIN_ID"):
932928
try:
933-
plug = module.Plugin()
934-
if plug.set_default_perspective():
935-
self._current_perspective = plug
936-
plugins.append(plug)
937-
929+
plugins.append(module.Plugin())
938930
msg = "Found plug-in: %s" % module.PLUGIN_ID
939931
logging.info(msg)
940932
except:
@@ -1510,42 +1502,42 @@ def _populate_file_menu(self):
15101502
if len(plugin.populate_file_menu()) > 0:
15111503
for item in plugin.populate_file_menu():
15121504
m_name, m_hint, m_handler = item
1513-
id = wx.NewId()
1514-
self._file_menu.Append(id, m_name, m_hint)
1515-
wx.EVT_MENU(self, id, m_handler)
1505+
wx_id = wx.NewId()
1506+
self._file_menu.Append(wx_id, m_name, m_hint)
1507+
wx.EVT_MENU(self, wx_id, m_handler)
15161508
self._file_menu.AppendSeparator()
15171509

15181510
style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS
15191511
if OPEN_SAVE_MENU:
1520-
id = wx.NewId()
1512+
wx_id = wx.NewId()
15211513
hint_load_file = "read all analysis states saved previously"
1522-
self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file)
1523-
wx.EVT_MENU(self, id, self._on_open_state_project)
1514+
self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file)
1515+
wx.EVT_MENU(self, wx_id, self._on_open_state_project)
15241516

15251517
if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
15261518
# some menu of plugin to be seen under file menu
15271519
hint_load_file = "Read a status files and load"
15281520
hint_load_file += " them into the analysis"
1529-
id = wx.NewId()
1530-
self._save_appl_menu = self._file_menu.Append(id,
1521+
wx_id = wx.NewId()
1522+
self._save_appl_menu = self._file_menu.Append(wx_id,
15311523
'&Open Analysis', hint_load_file)
1532-
wx.EVT_MENU(self, id, self._on_open_state_application)
1524+
wx.EVT_MENU(self, wx_id, self._on_open_state_application)
15331525
if OPEN_SAVE_MENU:
15341526
self._file_menu.AppendSeparator()
1535-
id = wx.NewId()
1536-
self._file_menu.Append(id, '&Save Project',
1527+
wx_id = wx.NewId()
1528+
self._file_menu.Append(wx_id, '&Save Project',
15371529
'Save the state of the whole analysis')
1538-
wx.EVT_MENU(self, id, self._on_save_project)
1530+
wx.EVT_MENU(self, wx_id, self._on_save_project)
15391531
if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
1540-
id = wx.NewId()
1541-
self._save_appl_menu = self._file_menu.Append(id, \
1532+
wx_id = wx.NewId()
1533+
self._save_appl_menu = self._file_menu.Append(wx_id, \
15421534
'&Save Analysis', 'Save state of the current active analysis panel')
1543-
wx.EVT_MENU(self, id, self._on_save_application)
1535+
wx.EVT_MENU(self, wx_id, self._on_save_application)
15441536
if not sys.platform == 'darwin':
15451537
self._file_menu.AppendSeparator()
1546-
id = wx.NewId()
1547-
self._file_menu.Append(id, '&Quit', 'Exit')
1548-
wx.EVT_MENU(self, id, self.Close)
1538+
wx_id = wx.NewId()
1539+
self._file_menu.Append(wx_id, '&Quit', 'Exit')
1540+
wx.EVT_MENU(self, wx_id, self.Close)
15491541

15501542
def _add_menu_file(self):
15511543
"""
@@ -1716,12 +1708,9 @@ def create_gui_data(self, data, path=None):
17161708
def get_data(self, path):
17171709
"""
17181710
"""
1719-
message = ""
17201711
log_msg = ''
1721-
output = []
1722-
error_message = ""
17231712
basename = os.path.basename(path)
1724-
root, extension = os.path.splitext(basename)
1713+
_, extension = os.path.splitext(basename)
17251714
if extension.lower() not in EXTENSIONS:
17261715
log_msg = "File Loader cannot "
17271716
log_msg += "load: %s\n" % str(basename)
@@ -2224,18 +2213,6 @@ def post_init(self):
22242213
if hasattr(item, "post_init"):
22252214
item.post_init()
22262215

2227-
def set_default_perspective(self):
2228-
"""
2229-
Choose among the plugin the first plug-in that has
2230-
"set_default_perspective" method and its return value is True will be
2231-
as a default perspective when the welcome page is closed
2232-
"""
2233-
for item in self.plugins:
2234-
if hasattr(item, "set_default_perspective"):
2235-
if item.set_default_perspective():
2236-
item.on_perspective(event=None)
2237-
return
2238-
22392216
def set_perspective(self, panels):
22402217
"""
22412218
Sets the perspective of the GUI.
@@ -2413,13 +2390,12 @@ def remove_data(self, data_id, theory_id=None):
24132390
theory_data, theory_state = item
24142391
total_plot_list.append(theory_data)
24152392
for new_plot in total_plot_list:
2416-
id = new_plot.id
24172393
for group_id in new_plot.list_group_id:
2418-
wx.PostEvent(self, NewPlotEvent(id=id,
2394+
wx.PostEvent(self, NewPlotEvent(id=new_plot.id,
24192395
group_id=group_id,
24202396
action='remove'))
24212397
#remove res plot: Todo: improve
2422-
wx.CallAfter(self._remove_res_plot, id)
2398+
wx.CallAfter(self._remove_res_plot, new_plot.id)
24232399
self._data_manager.delete_data(data_id=data_id,
24242400
theory_id=theory_id)
24252401

@@ -2454,26 +2430,26 @@ def save_data1d(self, data, fname):
24542430
# This is MAC Fix
24552431
ext_num = dlg.GetFilterIndex()
24562432
if ext_num == 0:
2457-
format = '.txt'
2433+
ext_format = '.txt'
24582434
else:
2459-
format = '.xml'
2460-
path = os.path.splitext(path)[0] + format
2435+
ext_format = '.xml'
2436+
path = os.path.splitext(path)[0] + ext_format
24612437
mypath = os.path.basename(path)
24622438

24632439
#Instantiate a loader
24642440
loader = Loader()
2465-
format = ".txt"
2466-
if os.path.splitext(mypath)[1].lower() == format:
2441+
ext_format = ".txt"
2442+
if os.path.splitext(mypath)[1].lower() == ext_format:
24672443
# Make sure the ext included in the file name
24682444
# especially on MAC
2469-
fName = os.path.splitext(path)[0] + format
2445+
fName = os.path.splitext(path)[0] + ext_format
24702446
self._onsaveTXT(data, fName)
2471-
format = ".xml"
2472-
if os.path.splitext(mypath)[1].lower() == format:
2447+
ext_format = ".xml"
2448+
if os.path.splitext(mypath)[1].lower() == ext_format:
24732449
# Make sure the ext included in the file name
24742450
# especially on MAC
2475-
fName = os.path.splitext(path)[0] + format
2476-
loader.save(fName, data, format)
2451+
fName = os.path.splitext(path)[0] + ext_format
2452+
loader.save(fName, data, ext_format)
24772453
try:
24782454
self._default_save_location = os.path.dirname(path)
24792455
except:
@@ -2597,21 +2573,21 @@ def save_data2d(self, data, fname):
25972573
# This is MAC Fix
25982574
ext_num = dlg.GetFilterIndex()
25992575
if ext_num == 0:
2600-
format = '.dat'
2576+
ext_format = '.dat'
26012577
else:
2602-
format = ''
2603-
path = os.path.splitext(path)[0] + format
2578+
ext_format = ''
2579+
path = os.path.splitext(path)[0] + ext_format
26042580
mypath = os.path.basename(path)
26052581

26062582
#Instantiate a loader
26072583
loader = Loader()
26082584

2609-
format = ".dat"
2610-
if os.path.splitext(mypath)[1].lower() == format:
2585+
ext_format = ".dat"
2586+
if os.path.splitext(mypath)[1].lower() == ext_format:
26112587
# Make sure the ext included in the file name
26122588
# especially on MAC
2613-
fileName = os.path.splitext(path)[0] + format
2614-
loader.save(fileName, data, format)
2589+
fileName = os.path.splitext(path)[0] + ext_format
2590+
loader.save(fileName, data, ext_format)
26152591
try:
26162592
self._default_save_location = os.path.dirname(path)
26172593
except:
@@ -3205,9 +3181,9 @@ def __init__(self, parent, *args, **kwds):
32053181

32063182

32073183

3208-
class ViewApp(wx.App):
3184+
class SasViewApp(wx.App):
32093185
"""
3210-
Toy application to test this Frame
3186+
SasView application
32113187
"""
32123188
def OnInit(self):
32133189
"""
@@ -3293,8 +3269,8 @@ def clean_plugin_models(self, path):
32933269
if os.path.exists(model_folder) and os.path.isdir(model_folder):
32943270
if len(os.listdir(model_folder)) > 0:
32953271
try:
3296-
for file in os.listdir(model_folder):
3297-
file_path = os.path.join(model_folder, file)
3272+
for filename in os.listdir(model_folder):
3273+
file_path = os.path.join(model_folder, filename)
32983274
if os.path.isfile(file_path):
32993275
os.remove(file_path)
33003276
except:
@@ -3313,10 +3289,7 @@ def build_gui(self):
33133289
Build the GUI
33143290
"""
33153291
#try to load file at the start
3316-
try:
3317-
self.open_file()
3318-
except:
3319-
raise
3292+
self.open_file()
33203293
self.frame.build_gui()
33213294

33223295
def set_welcome_panel(self, panel_class):

src/sas/guiframe/local_perspectives/data_loader/data_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
class Plugin(PluginBase):
4242

43-
def __init__(self, standalone=False):
44-
PluginBase.__init__(self, name="DataLoader", standalone=standalone)
43+
def __init__(self):
44+
PluginBase.__init__(self, name="DataLoader")
4545
# Default location
4646
self._default_save_location = DEFAULT_OPEN_FOLDER
4747
self.loader = Loader()

src/sas/guiframe/local_perspectives/plotting/plotting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Plugin(PluginBase):
3535
Plug-in class to be instantiated by the GUI manager
3636
"""
3737

38-
def __init__(self, standalone=False):
39-
PluginBase.__init__(self, name="Plotting", standalone=standalone)
38+
def __init__(self):
39+
PluginBase.__init__(self, name="Plotting")
4040

4141
## Plot panels
4242
self.plot_panels = {}

src/sas/guiframe/plugin_base.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ class for the Foo plug-in. The interface of that Plugin class
3333
See dummyapp.py for a plugin example.
3434
"""
3535

36-
def __init__(self, name="Test_plugin", standalone=True):
36+
def __init__(self, name="Test_plugin"):
3737
"""
3838
Abstract class for gui_manager Plugins.
3939
"""
4040
# Define if the plugin is local to Viewerframe and always active
4141
self._always_active = False
4242
## Plug-in name. It will appear on the application menu.
4343
self.sub_menu = name
44-
#standalone flag
45-
self.standalone = standalone
4644
## Reference to the parent window. Filled by get_panels() below.
4745
self.parent = None
4846
self.frame = None
@@ -262,17 +260,6 @@ def post_init(self):
262260
"""
263261
pass
264262

265-
def set_default_perspective(self):
266-
"""
267-
Call back method that True to notify the parent that the current plug-in
268-
can be set as default perspective.
269-
when returning False, the plug-in is not candidate for an automatic
270-
default perspective setting
271-
"""
272-
if self.standalone:
273-
return True
274-
return False
275-
276263
def set_state(self, state=None, datainfo=None):
277264
"""
278265
update state

src/sas/perspectives/calculator/calculator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Plugin(PluginBase):
3232
This class defines the interface for a Plugin class
3333
for calculator perspective
3434
"""
35-
def __init__(self, standalone=True):
36-
PluginBase.__init__(self, name="Calculator", standalone=standalone)
35+
def __init__(self):
36+
PluginBase.__init__(self, name="Calculator")
3737
# Log startup
3838
logging.info("Calculator plug-in started")
3939
self.sub_menu = "Tool"

0 commit comments

Comments
 (0)