Skip to content

Commit

Permalink
Merge pull request #194 from SasView/py37-sasgui
Browse files Browse the repository at this point in the history
improved support for py37 in sasgui
  • Loading branch information
pkienzle authored Mar 12, 2019
2 parents 9a1204d + f923967 commit 09d7021
Show file tree
Hide file tree
Showing 98 changed files with 1,033 additions and 917 deletions.
17 changes: 13 additions & 4 deletions src/sas/sasgui/guiframe/CategoryInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

logger = logging.getLogger(__name__)

if sys.version_info[0] > 2:
def json_dump(obj, filename):
with open(filename, 'w', newline='\n') as fd:
json.dump(obj, fd)
else: # CRUFT: python 2.7 support
def json_dump(obj, filename):
with open(filename, 'wb') as fd:
json.dump(obj, fd)

class CategoryInstaller(object):
"""
Class for making sure all category stuff is installed
Expand Down Expand Up @@ -120,7 +129,7 @@ def check_install(homedir = None, model_list=None):
Plugin Models which are user supplied.
"""
_model_dict = {model.name: model for model in model_list}
_model_list = _model_dict.keys()
_model_list = list(_model_dict.keys())

serialized_file = None
if homedir is None:
Expand All @@ -145,8 +154,8 @@ def check_install(homedir = None, model_list=None):
try:
by_model_dict.pop(model_name)
model_enabled_dict.pop(model_name)
except Exception:
logger.error("CategoryInstaller: %s", sys.exc_value)
except Exception as exc:
logger.error("CategoryInstaller: %s", exc)
else:
add_list.remove(model_name)
if del_name or (len(add_list) > 0):
Expand All @@ -170,4 +179,4 @@ def check_install(homedir = None, model_list=None):
CategoryInstaller._regenerate_master_dict(by_model_dict,
model_enabled_dict)

json.dump(master_category_dict, open(serialized_file, 'wb'))
json_dump(master_category_dict, serialized_file)
4 changes: 2 additions & 2 deletions src/sas/sasgui/guiframe/CategoryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _fill_lists(self):
model_name_list.sort()

for model in model_name_list:
index = self.cat_list.InsertStringItem(sys.maxint, model)
index = self.cat_list.InsertStringItem(sys.maxsize, model)
self.cat_list.SetStringItem(index, 1, \
str(self.by_model_dict[model]).\
replace("u'","").\
Expand Down Expand Up @@ -383,7 +383,7 @@ def _get_cat_list(self):
Returns a simple list of categories
"""
cat_list = list()
for category in self.master_category_dict.iterkeys():
for category in self.master_category_dict.keys():
if not category == 'Uncategorized':
cat_list.append(category)

Expand Down
22 changes: 11 additions & 11 deletions src/sas/sasgui/guiframe/custom_pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ def write_stats(self, *amount):

width = self.max_name_len
if self.fcn_list:
list = self.fcn_list[:]
stats = self.fcn_list[:]
temp_msg = " Ordered by: " + self.sort_type + '\n'
else:
list = self.stats.keys()
stats = list(self.stats.keys())
temp_msg = " Random listing order was used\n"

for selection in amount:
list, temp_msg = self.eval_print_amount(selection, list, temp_msg)
stats, temp_msg = self.eval_print_amount(selection, stats, temp_msg)

count = len(list)
count = len(stats)

if not list:
width, list = 0, list
if not stats:
width = 0
else:
msg += str(temp_msg) + '\n'
msg += str(temp_msg) + '\n'
if count < len(self.stats):
width = 0
for func in list:
for func in stats:
if len(func_std_string(func)) > width:
width = len(func_std_string(func))

width, list = width+2, list
if list:
width = width+2
if stats:
msg += ' ncalls tottime percall cumtime percall'
msg += ' filename:lineno(function)' + "\n"
for func in list:
for func in stats:
cc, nc, tt, ct, callers = self.stats[func]
c = str(nc)
if nc != cc:
Expand Down
28 changes: 13 additions & 15 deletions src/sas/sasgui/guiframe/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self):
_str = ""
_str += "No of states is %s \n" % str(len(self.stored_data))
n_count = 0
for value in self.stored_data.values():
for value in self.stored_data.values():
n_count += 1
_str += "State No %s \n" % str(n_count)
_str += str(value) + "\n"
Expand Down Expand Up @@ -133,7 +133,7 @@ def add_data(self, data_list):
"""
receive a list of
"""
for id, data in data_list.iteritems():
for id, data in data_list.items():
if id in self.stored_data:
msg = "Data manager already stores %s" % str(data.name)
msg += ""
Expand All @@ -149,12 +149,12 @@ def add_data(self, data_list):
def update_data(self, prev_data, new_data):
"""
"""
if prev_data.id not in self.stored_data.keys():
if prev_data.id not in self.stored_data:
return None, {}
data_state = self.stored_data[prev_data.id]
self.stored_data[new_data.id] = data_state.clone()
self.stored_data[new_data.id].data = new_data
if prev_data.id in self.stored_data.keys():
if prev_data.id in self.stored_data:
del self.stored_data[prev_data.id]
return prev_data.id, {new_data.id: self.stored_data[new_data.id]}

Expand All @@ -164,7 +164,7 @@ def update_theory(self, theory, data_id=None, state=None):
uid = data_id
if data_id is None and theory is not None:
uid = theory.id
if uid in self.stored_data.keys():
if uid in self.stored_data:
data_state = self.stored_data[uid]
else:
data_state = DataState()
Expand Down Expand Up @@ -194,7 +194,7 @@ def get_by_id(self, id_list=None):
theory_list = data_state.get_theory()
if search_id == d_id:
_selected_data[search_id] = data
if search_id in theory_list.keys():
if search_id in theory_list:
_selected_theory_list[search_id] = theory_list[search_id]

return _selected_data, _selected_theory_list
Expand All @@ -203,7 +203,7 @@ def get_by_id(self, id_list=None):
def freeze(self, theory_id):
"""
"""
return self.freeze_theory(self.stored_data.keys(), theory_id)
return self.freeze_theory(list(self.stored_data.keys()), theory_id)

def freeze_theory(self, data_id, theory_id):
"""
Expand All @@ -214,7 +214,7 @@ def freeze_theory(self, data_id, theory_id):
data_state = self.stored_data[d_id]
theory_list = data_state.get_theory()
for t_id in theory_id:
if t_id in theory_list.keys():
if t_id in theory_list:
theory_data, theory_state = theory_list[t_id]
new_theory = copy.deepcopy(theory_data)
new_theory.id = time.time()
Expand All @@ -234,7 +234,7 @@ def delete_data(self, data_id, theory_id=None, delete_all=False):
"""
"""
for d_id in data_id:
if d_id in self.stored_data.keys():
if d_id in self.stored_data:
data_state = self.stored_data[d_id]
if data_state.data.name in self.data_name_dict:
del self.data_name_dict[data_state.data.name]
Expand All @@ -252,7 +252,7 @@ def delete_theory(self, data_id, theory_id):
if d_id in self.stored_data:
data_state = self.stored_data[d_id]
theory_list = data_state.get_theory()
if theory_id in theory_list.keys():
if theory_id in theory_list:
del theory_list[theory_id]
#del pure theory
self.delete_by_id(theory_id)
Expand All @@ -272,7 +272,7 @@ def get_by_name(self, name_list=None):
"""
_selected_data = {}
for selected_name in name_list:
for id, data_state in self.stored_data.iteritems():
for id, data_state in self.stored_data.items():
if data_state.data.name == selected_name:
_selected_data[id] = data_state.data
return _selected_data
Expand All @@ -282,7 +282,7 @@ def delete_by_name(self, name_list=None):
save data and path
"""
for selected_name in name_list:
for id, data_state in self.stored_data.iteritems():
for id, data_state in self.stored_data.items():
if data_state.data.name == selected_name:
del self.stored_data[id]

Expand All @@ -292,7 +292,7 @@ def get_data_state(self, data_id):
"""
_selected_data_state = {}
for id in data_id:
if id in self.stored_data.keys():
if id in self.stored_data:
_selected_data_state[id] = self.stored_data[id]
return _selected_data_state

Expand All @@ -302,5 +302,3 @@ def get_all_data(self):
"""
return self.stored_data



45 changes: 23 additions & 22 deletions src/sas/sasgui/guiframe/data_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"""
from __future__ import print_function

import wx
from wx.build import build_options

import sys

import wx
from wx.lib.scrolledpanel import ScrolledPanel
import wx.lib.agw.customtreectrl as CT
#from wx.build import build_options

from sas.sasgui.guiframe.dataFitting import Data1D
from sas.sasgui.guiframe.dataFitting import Data2D
from sas.sasgui.guiframe.panel_base import PanelBase
Expand Down Expand Up @@ -443,9 +444,9 @@ def _get_data_selection(self, event):
data_list, theory_list = \
self.parent.get_data_manager().get_by_id(id_list=[id])
if data_list:
data = data_list.values()[0]
data = list(data_list.values())[0]
if data is None:
data = theory_list.values()[0][0]
data = list(theory_list.values())[0][0]
return data

def on_edit_data(self, event):
Expand Down Expand Up @@ -666,7 +667,7 @@ def load_data_list(self, list):
add need data with its theory under the tree
"""
if list:
for state_id, dstate in list.iteritems():
for state_id, dstate in list.items():
data = dstate.get_data()
theory_list = dstate.get_theory()
if data is not None:
Expand Down Expand Up @@ -763,7 +764,7 @@ def append_theory(self, state_id, theory_list):
"""
if not theory_list:
return
if state_id not in self.list_cb_data.keys():
if state_id not in self.list_cb_data:
root = self.tree_ctrl_theory.root
tree = self.tree_ctrl_theory
else:
Expand All @@ -782,11 +783,11 @@ def append_theory_helper(self, tree, root, state_id, theory_list):
"""
Append theory helper
"""
if state_id in self.list_cb_theory.keys():
if state_id in self.list_cb_theory:
# update current list of theory for this data
theory_list_ctrl = self.list_cb_theory[state_id]

for theory_id, item in theory_list.iteritems():
for theory_id, item in theory_list.items():
theory_data, _ = item
if theory_data is None:
name = "Unknown"
Expand Down Expand Up @@ -827,7 +828,7 @@ def append_theory_helper(self, tree, root, state_id, theory_list):
else:
# data didn't have a theory associated it before
theory_list_ctrl = {}
for theory_id, item in theory_list.iteritems():
for theory_id, item in theory_list.items():
theory_data, _ = item
if theory_data is not None:
name = theory_data.name
Expand Down Expand Up @@ -867,7 +868,7 @@ def set_data_helper(self):
state_to_plot.append(state_id)

for theory_dict in self.list_cb_theory.values():
for _, value in theory_dict.iteritems():
for _, value in theory_dict.items():
item, _, _ = value
if item.IsChecked():
theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
Expand Down Expand Up @@ -923,17 +924,17 @@ def on_remove(self, event, prompt=True):
data_key = []
theory_key = []
# remove data from treectrl
for d_key, item in self.list_cb_data.iteritems():
for d_key, item in self.list_cb_data.items():
data_c, _, _, _, _, _, _, _ = item
if data_c.IsChecked():
self.tree_ctrl.Delete(data_c)
data_key.append(d_key)
if d_key in self.list_cb_theory.keys():
if d_key in self.list_cb_theory:
theory_list_ctrl = self.list_cb_theory[d_key]
theory_to_remove += theory_list_ctrl.keys()
theory_to_remove += list(theory_list_ctrl.keys())
# Remove theory from treectrl
for _, theory_dict in self.list_cb_theory.iteritems():
for key, value in theory_dict.iteritems():
for _, theory_dict in self.list_cb_theory.items():
for key, value in theory_dict.items():
item, _, _ = value
if item.IsChecked():
try:
Expand All @@ -949,9 +950,9 @@ def on_remove(self, event, prompt=True):
del self.list_cb_theory[key]
# remove theory references independently of data
for key in theory_key:
for _, theory_dict in self.list_cb_theory.iteritems():
for _, theory_dict in self.list_cb_theory.items():
if key in theory_dict:
for key, value in theory_dict.iteritems():
for key, value in theory_dict.items():
item, _, _ = value
if item.IsChecked():
try:
Expand Down Expand Up @@ -1046,7 +1047,7 @@ def set_panel_on_focus(self, name=None):
"""
if self.cb_plotpanel and self.cb_plotpanel.IsBeingDeleted():
return
for _, value in self.parent.plot_panels.iteritems():
for _, value in self.parent.plot_panels.items():
name_plot_panel = str(value.window_caption)
if name_plot_panel not in self.cb_plotpanel.GetItems():
self.cb_plotpanel.Append(name_plot_panel, value)
Expand Down Expand Up @@ -1128,7 +1129,7 @@ def on_help(self, event):

#import documentation window here to avoid circular imports
#if put at top of file with rest of imports.
from documentation_window import DocumentationWindow
from .documentation_window import DocumentationWindow

_TreeLocation = "user/sasgui/guiframe/data_explorer_help.html"
_doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "",
Expand Down Expand Up @@ -1498,8 +1499,8 @@ def set_data_state(data=None, path=None, theory=None, state=None):
window.load_data_list(list=data_list1)
window.Show(True)
window.load_data_list(list=temp_data_list)
except:
except Exception as exc:
# raise
print("error", sys.exc_value)
print("error", exc)

app.MainLoop()
Loading

0 comments on commit 09d7021

Please sign in to comment.