Skip to content

Commit

Permalink
python3: revert some of the changes by toubol and try not to break pr…
Browse files Browse the repository at this point in the history
…evious workflows
  • Loading branch information
paulmueller committed May 10, 2018
1 parent 11113e7 commit 788e416
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 8,267 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ tests/data
.cache
.eggs
.env

.pytest_cache
3 changes: 3 additions & 0 deletions .travis/linux_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ sudo apt-get update -qq
# Fixes the error:
# - ImportError: No module named _tkinter, please install the python-tk package
sudo apt-get install -qq python-pip python-tk
# requirements for building wxPython4 on Ubuntu 17.10
# see https://github.com/wxWidgets/Phoenix/blob/master/README.rst
#sudo apt-get install -qq libgtk2.0 libgtk2.0-dev libwebkitgtk-dev dpkg-dev build-essential python3.6-dev libjpeg-dev libtiff-dev libsdl1.2-dev libnotify-dev freeglut3 freeglut3-dev libsm-dev libgtk-3-dev libwebkit2gtk-4.0-dev libxtst-dev libgstreamer-plugins-base1.0-dev
sudo pip install virtualenv
# use separate virtual environment
virtualenv --system-site-packages ~/env
Expand Down
5 changes: 2 additions & 3 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
2.0.0
- BREAKING CHANGE: Move to Python3
- GUI:
- mice don't change the parameter box automatically
- close the tools after use
- add shortcuts:
- Add option in Preferences to automatically close tools after usage
- Add keybord shortcuts:
- Load data: Ctrl + O
- Load session: Ctrl + Shift + O
- Clear Session: Alt + C
Expand Down
8 changes: 0 additions & 8 deletions pycorrfit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
PyCorrFit is a tool to fit fluorescence correlation spectroscopy
data on a logarithmic scale.
"""

from os import walk
import sys

for path, _, _ in walk('..'):
sys.path.append(path)


from . import meta
from . import models
from . import openfile
Expand Down
3 changes: 0 additions & 3 deletions pycorrfit/_version_save.py

This file was deleted.

2 changes: 1 addition & 1 deletion pycorrfit/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def fit_model(self):
def fit_model(self, value):
"""set the fit model
"""
if isinstance(value, (int, float)):
if isinstance(value, int):
newmodel = mdls.modeldict[value]
elif isinstance(value, mdls.Model):
newmodel = value
Expand Down
14 changes: 8 additions & 6 deletions pycorrfit/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def parameters(self):
"""
Returns list of dict for each parameter.
"""
parms = [ it for it in self.constraint if isinstance(it, (int, float))]
parms = [ it for it in self.constraint if isinstance(it, int)]
id2 = self.constraint.index(parms[1])

p1 = {"id": parms[0],
Expand All @@ -68,7 +68,7 @@ def parameters(self):

@property
def operator(self):
strval = [ it for it in self.constraint if not isinstance(it, (int, float))]
strval = [ it for it in self.constraint if not isinstance(it, int)]
return strval[0]

@property
Expand Down Expand Up @@ -672,8 +672,8 @@ def compute_weights(correlation, verbose=0, uselatex=False):
elif weights.shape[0] == x_full.shape[0]:
dataweights = weights[ival[0]:ival[1]]
else:
raise ValueError("`weights` must have length of full \
or cropped array.")
msg = "`weights` must have length of full or cropped array."
raise ValueError(msg)

return dataweights

Expand Down Expand Up @@ -803,8 +803,10 @@ def lmfitparm2array(parms, parmid="parm", attribute="value"):
"""
if isinstance(parms, lmfit.parameter.Parameters):
items = parms.items()
# items.sort(key=lambda x: x[0])
parr = [getattr(p[1], attribute) for p in sorted(items, key=lambda x: x[0]) if p[0].startswith(parmid)]
parr = []
for p in sorted(items, key=lambda x: x[0]):
if p[0].startswith(parmid):
parr.append(getattr(p[1], attribute))
else:
parr = parms

Expand Down
44 changes: 23 additions & 21 deletions pycorrfit/gui/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
The frontend displays the GUI (Graphic User Interface). All necessary
functions and modules are called from here.
"""

from distutils.version import LooseVersion # For version checking
from distutils.version import LooseVersion # For version checking
import os
import webbrowser
import wx
import wx.lib.agw.flatnotebook as fnb
import wx.py.shell
import wx.adv
import numpy as np
import pathlib
import platform
import sys
import traceback
import warnings
import webbrowser

import numpy as np
import wx.adv
import wx.lib.agw.flatnotebook as fnb
import wx.py.shell

from pycorrfit import models as mdls
from pycorrfit import openfile as opf
Expand Down Expand Up @@ -90,9 +90,8 @@ def __init__(self, parent, anid, version):
## Set initial variables that make sense
self.version = version

##Init of the superClass
# super(MyFrame, self).__init__(parent, anid, "PyCorrFit " + self.version)
wx.Frame.__init__(self, parent, anid, "PyCorrFit " + self.version)
## Init of the superClass
super(MyFrame, self).__init__(parent, anid, "PyCorrFit " + self.version)

self.CreateStatusBar() # A Statusbar in the bottom of the window
self.StatusBar.SetStatusText("Find help and updates online:"+
Expand Down Expand Up @@ -305,6 +304,9 @@ def MakeMenu(self):
"Enables/Disables displaying weights of fit.",
kind=wx.ITEM_CHECK)
self.MenuShowWeights.Check()
self.MenuAutocloseTools = prefmenu.Append(wx.ID_ANY, "Autoclose tools",
"Automatically close tools after usage.",
kind=wx.ITEM_CHECK)
# toolmenu
toolkeys = list(tools.ToolDict.keys())
toolkeys.sort()
Expand Down Expand Up @@ -607,7 +609,7 @@ def OnCommSession(self,e=None):
self.EditCommentDlg = tools.EditComment(self)
self.EditCommentDlg.Bind(wx.EVT_CLOSE, self.EditCommentDlg.OnClose)
self.filemenu.Check(self.menuComm.GetId(), True)
except RuntimeError as rte:
except RuntimeError:
del self.EditCommentDlg
self.OnCommSession()
else:
Expand All @@ -634,23 +636,23 @@ def OnDeletePage(self, event=None):

def OnDocumentation(self, e=None):
""" Get the documentation and view it with browser"""
filename = doc.GetLocationOfDocumentation()
if filename is None:
path = doc.GetLocationOfDocumentation()
if path is None:
# Now we have to tell the user that there is no documentation
self.StatusBar.SetStatusText("...documentation not found.")
else:
self.StatusBar.SetStatusText("...documentation: "+filename)
path = pathlib.Path(path)
self.StatusBar.SetStatusText("...documentation: {}".format(path))
if platform.system().lower() == 'windows':
path = '\\'.join(filename.split('\\')[:-1])
file = filename.split('\\')[-1]
os.system("start /d \"{}\" {}".format(path, file))
cmd = 'start /d "{}" {}'.format(path.parent, path.name)
elif platform.system().lower() == 'linux':
os.system("xdg-open "+filename+" &")
cmd = 'xdg-open "{}" &'.format(path)
elif platform.system().lower() == 'darwin':
os.system("open "+filename+" &")
cmd = 'open "{}" &'.format(path)
else:
# defaults to linux style:
os.system("xdg-open "+filename+" &")
cmd = 'xdg-open "{}" &'.format(path)
os.system(cmd)


def OnExit(self,e=None):
Expand Down
2 changes: 1 addition & 1 deletion pycorrfit/gui/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, parent, counter, modelid, active_parms, tau=None):
self.canvascorr.SetSize((canvasx, cupsizey))
# Lower Plot for plotting of the residuals
self.canvaserr = plot.PlotCanvas(self.spcanvas)
self.canvaserr.logScale =(True, False)
self.canvaserr.logScale = (True, False)
self.canvaserr.enableZoom = True
self.canvaserr.SetSize((canvasx, size[1]-cupsizey))
self.spcanvas.SplitHorizontally(self.canvascorr, self.canvaserr,
Expand Down
5 changes: 3 additions & 2 deletions pycorrfit/gui/tools/average.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ def OnAverage(self, evt=None):
self.AvgPage.apply_parameters()
self.AvgPage.corr.set_weights(listname, standarddev)
self.AvgPage.PlotAll()
# Keep the average tool open.
self.OnClose()
if self.parent.MenuAutocloseTools.IsChecked():
# Autoclose
self.OnClose()

def SetPageNumbers(self, pagestring):
self.WXTextPages.SetValue(pagestring)
Expand Down
6 changes: 5 additions & 1 deletion pycorrfit/gui/tools/batchcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def OnFit(self, event):
fit_page_list.append(pageii)

FitProgressDlg(self, fit_page_list, trigger="fit_batch")
self.OnClose()

if self.parent.MenuAutocloseTools.IsChecked():
# Autoclose
self.OnClose()


def OnPageChanged(self, Page=None, trigger=None):
"""
Expand Down
5 changes: 4 additions & 1 deletion pycorrfit/gui/tools/globalfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def OnFit(self, e=None):
if int(j) in global_pages:
Page.apply_parameters_reverse()
Page.PlotAll()
self.OnClose()
if self.parent.MenuAutocloseTools.IsChecked():
# Autoclose
self.OnClose()


def OnPageChanged(self, page, trigger=None):
"""
Expand Down
5 changes: 3 additions & 2 deletions pycorrfit/gui/tools/parmrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,6 @@ def OnSetParmRange(self, e):
parm1 = mdls.GetInternalFromHumanReadableParm(corr.fit_model.id,
self.parameter_range[:,1])[1]
corr.fit_parameters_range = np.dstack((parm0, parm1))[0]
#self.Page.PlotAll()
self.OnClose()
if self.parent.MenuAutocloseTools.IsChecked():
# Autoclose
self.OnClose()
4 changes: 2 additions & 2 deletions pycorrfit/gui/wxutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class PCFFloatTextCtrl(wx.TextCtrl):
def __init__(self, *args, **kwargs):
wx.TextCtrl.__init__(self, *args, validator=PCFFloatValidator(), size=(110,-1),
style=wx.TE_PROCESS_ENTER, **kwargs)
# self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
# self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self._PCFvalue = 0.0

def OnMouseEnter(self, e):
Expand Down
11 changes: 8 additions & 3 deletions pycorrfit/models/classes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
import copy
import numpy as np
import numbers
import warnings

import numpy as np


class Model(object):
"""General class for handling FCS fitting models"""
Expand All @@ -27,7 +28,11 @@ def __init__(self, datadict):
# larger than the last.
newcc = []
for cc in datadict["Constraints"]:
if cc[0] < cc[2]:
# check for integral numbers to avoid comparison to strings
# in e.g. confocal t_3d_3d_3d model.
if (isinstance(cc[0], numbers.Integral) and
isinstance(cc[2], numbers.Integral) and
cc[0] < cc[2]):
if cc[1] == ">":
cc = [cc[2], "<", cc[0]]
elif cc[1] == "<":
Expand Down
2 changes: 1 addition & 1 deletion pycorrfit/models/model_confocal_t_3d_3d_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def supplements(parms, countrate=None):
False, True, False, False,
False, False, True, False],
par_boundaries=boundaries,
par_constraints=[[2, ">", 1], [3, ">", 2], [9, "<", 1]], # , [5, 4, "<", "1"]],
par_constraints=[[2, ">", 1], [3, ">", 2], [9, "<", 1], [5, 4, "<", "1"]],
par_hr_labels=[
u"n",
u"τ"+u"\u2081"+" [ms]",
Expand Down
2 changes: 1 addition & 1 deletion pycorrfit/models/model_confocal_t_3d_3d_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def supplements(parms, countrate=None):
False, True, False, False,
False, False, True, False],
par_boundaries=boundaries,
par_constraints=[[2, ">", 1], [3, ">", 2], [9, "<", 1]], # [5, 4, "<", "1"]],
par_constraints=[[2, ">", 1], [3, ">", 2], [9, "<", 1], [5, 4, "<", "1"]],
par_hr_labels=[
u"n",
u"τ"+u"\u2081"+" [ms]",
Expand Down
Loading

0 comments on commit 788e416

Please sign in to comment.