Skip to content

Commit

Permalink
Use pkg_resource to handle gui icons. Bump version to 0.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Mertens committed Apr 16, 2019
1 parent 3234331 commit 22d30cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion libwise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.4.6'
__version__ = '0.4.7'


def get_version():
Expand Down
5 changes: 3 additions & 2 deletions libwise/imgutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import imghdr
import decimal
import datetime
import pkg_resources
import numpy as np
import PIL.Image

Expand All @@ -30,7 +31,7 @@

import matplotlib.ticker as mticker

RESSOURCE_PATH = os.path.join(os.path.dirname(__file__), 'ressource')
RESSOURCE_PATH = 'ressource'

import nputils
import signalutils
Expand Down Expand Up @@ -206,7 +207,7 @@ def ellipsoide(size, a, b=None):


def galaxy():
gif = PIL.Image.open(GALAXY_GIF_PATH)
gif = PIL.Image.open(pkg_resources.resource_stream(__name__, GALAXY_GIF_PATH))
return np.array(list(gif.getdata())).reshape(256, 256)


Expand Down
45 changes: 25 additions & 20 deletions libwise/plotutils_ui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pkg_resources

try:
__import__('PyQt5')
use_pyqt5 = True
Expand Down Expand Up @@ -38,12 +40,12 @@ def subplots_replayable(plt_fct, *args):
window = BaseFigureWindow(figure=figure)
window.show()

return figure
return figure


class Cursor(QtCore.QObject):

cursorMoved = QtCore.pyqtSignal(list)
cursorMoved = QtCore.pyqtSignal(list)

def __init__(self, ax, figure, other_axs=[]):
QtCore.QObject.__init__(self)
Expand Down Expand Up @@ -191,7 +193,7 @@ def clear(self):
self.init_line()
self.canvas.restore_region(self.background)
self.canvas.update()
except:
except Exception:
print "Issue clearing"
pass

Expand Down Expand Up @@ -391,7 +393,7 @@ def action(self):
i0 = np.where(x >= x0)[0][0]
fct_index2coord = lambda index: x[i0 + index[0]]
self.stats_window.add_data(self.axes, data, str(artist), fct_index2coord)
except:
except Exception:
pass

if not self.stats_window.has_data():
Expand Down Expand Up @@ -514,7 +516,7 @@ def __init__(self, figure=None, name="", parent=None, extended_toolbar=True):
figure.navigation = ExtendedNavigationToolbar(figure.canvas, self)
else:
figure.navigation = NavigationToolbar(figure.canvas, self)
#
#
self.layout().addWidget(figure.canvas)
self.layout().addWidget(figure.navigation)
self.figure.canvas.draw()
Expand Down Expand Up @@ -661,10 +663,10 @@ class ExtendedNavigationToolbar(NavigationToolbar):

def __init__(self, canvas, window, profile=True):
self.toolitems = list(self.toolitems)
self.toolitems.insert(6, ('Profile', 'Get the profile of a line in an image',
os.path.join(imgutils.RESSOURCE_PATH, "profile"), 'profile'))
self.toolitems.insert(7, ('Stats', 'Get statistics on a portion of an image/line',
os.path.join(imgutils.RESSOURCE_PATH, "stats"), 'stats'))
self.toolitems.insert(6, ('Profile', 'Get the profile of a line in an image',
os.path.join(imgutils.RESSOURCE_PATH, "profile"), 'profile'))
self.toolitems.insert(7, ('Stats', 'Get statistics on a portion of an image/line',
os.path.join(imgutils.RESSOURCE_PATH, "stats"), 'stats'))
NavigationToolbar.__init__(self, canvas, window)
self._actions['profile'].setCheckable(True)
self._actions['stats'].setCheckable(True)
Expand All @@ -673,8 +675,10 @@ def closeEvent(self, event):
self.toogle_off_all_active()

def _icon(self, name):
if name.startswith(os.path.sep):
return QtGui.QIcon(name)
if name.startswith(imgutils.RESSOURCE_PATH):
img = QtGui.QImage()
img.loadFromData(pkg_resources.resource_string(imgutils.__name__, name))
return QtGui.QIcon(QtGui.QPixmap.fromImage(img))
return NavigationToolbar._icon(self, name)

def _update_buttons_checked(self):
Expand Down Expand Up @@ -835,7 +839,7 @@ def setup_data(self):
def flags(self, index):
if not index.isValid():
return 0
if index.column() == 2:
if index.column() == 2:
return QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable

Expand Down Expand Up @@ -883,10 +887,10 @@ def filterAcceptsRow(self, row, sourceParent):

class PresetEditor(uiutils.UI):

changed = QtCore.pyqtSignal()
changed = QtCore.pyqtSignal()

def __init__(self, preset, parent):
uiutils.UI.__init__(self, 400, 350, "Preset Editor: %s" % preset.get_name(),
uiutils.UI.__init__(self, 400, 350, "Preset Editor: %s" % preset.get_name(),
parent=parent, window_flags=QtCore.Qt.Dialog)

self.preset = preset
Expand All @@ -898,8 +902,8 @@ def __init__(self, preset, parent):
vbox = QtGui.QVBoxLayout()
self.setLayout(vbox)

self.tree = QtGui.QTreeView()
self.tree.setModel(self.model)
self.tree = QtGui.QTreeView()
self.tree.setModel(self.model)
vbox.addWidget(self.tree)

ctl = QtGui.QHBoxLayout()
Expand Down Expand Up @@ -947,8 +951,8 @@ def match_func(self, model, iter):
return False

def on_save_clicked(self, bn):
name, ok = QtGui.QInputDialog.getText(self, "Preset name",
"Enter the preset name:", text=self.preset.get_name())
name, ok = QtGui.QInputDialog.getText(self, "Preset name",
"Enter the preset name:", text=self.preset.get_name())
if ok and len(name) > 0:
self.preset.set_name(name)
self.preset.save()
Expand Down Expand Up @@ -1087,7 +1091,7 @@ def on_explore_clicked(self, bn):

figureoptions.figure_edit(axes, self)
self.update(False)

def on_subplot_clicked(self, bn):
self.figure.navigation.configure_subplots()

Expand Down Expand Up @@ -1124,7 +1128,7 @@ def update(self, replay=True):
class FigureStack(uiutils.UI, BaseFigureStack):

def __init__(self, title="Figure Stack", fixed_aspect_ratio=False, **kwargs):
BaseFigureStack.__init__(self, title=title,
BaseFigureStack.__init__(self, title=title,
fixed_aspect_ratio=fixed_aspect_ratio, **kwargs)
uiutils.UI.__init__(self, 800, 500, title, window_flags=QtCore.Qt.Window)
self.window_title = title
Expand Down Expand Up @@ -1286,6 +1290,7 @@ def show(self, start_main=True):
else:
QtGui.QWidget.show(self)


if __name__ == '__main__':
editor = PresetEditor(presetutils.RcPreset.load('display_v2'), None)
editor.start()

0 comments on commit 22d30cf

Please sign in to comment.