forked from IPKM/nmreval
add flag for partial fits; closes #83
This commit is contained in:
@ -1,80 +1 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
HAS_IMPORTLIB_RESOURCE = False
|
||||
from pkg_resources import resource_filename
|
||||
else:
|
||||
HAS_IMPORTLIB_RESOURCE = True
|
||||
from importlib.resources import path
|
||||
|
||||
from ..Qt import QtGui, QtWidgets
|
||||
|
||||
|
||||
# def get_path_importlib(package, resource):
|
||||
# return path(package, resource)
|
||||
#
|
||||
#
|
||||
# def _get_path_pkg(package, resource):
|
||||
# return resource_filename(package, resource)
|
||||
#
|
||||
#
|
||||
# if HAS_IMPORTLIB_RESOURCE:
|
||||
# get_path = get_path_importlib
|
||||
# else:
|
||||
# get_path = _get_path_pkg
|
||||
|
||||
|
||||
def make_action_icons(widget):
|
||||
global HAS_IMPORTLIB_RESOURCE
|
||||
icon_type = QtWidgets.QApplication.instance().theme
|
||||
from json import loads
|
||||
|
||||
if HAS_IMPORTLIB_RESOURCE:
|
||||
with path('resources.icons', 'icons.json') as fp:
|
||||
with fp.open('r') as f:
|
||||
icon_list = loads(f.read())
|
||||
|
||||
for ac, img in icon_list[widget.objectName()].items():
|
||||
dirname = 'resources.icons.%s_light' % icon_type
|
||||
with path(dirname, img+'.png') as imgpath:
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
getattr(widget, ac).setIcon(icon)
|
||||
|
||||
else:
|
||||
with open(resource_filename('resources.icons', 'icons.json'), 'r') as f:
|
||||
icon_list = loads(f.read())
|
||||
|
||||
for ac, img in icon_list[widget.objectName()].items():
|
||||
dirname = 'resources.icons.%s_light' % icon_type
|
||||
imgpath = resource_filename(dirname, img+'.png')
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
getattr(widget, ac).setIcon(icon)
|
||||
|
||||
|
||||
def get_icon(icon_name):
|
||||
try:
|
||||
icon_type = QtWidgets.QApplication.instance().theme
|
||||
except AttributeError:
|
||||
icon_type = 'normal'
|
||||
|
||||
global HAS_IMPORTLIB_RESOURCE
|
||||
|
||||
if icon_name != 'logo':
|
||||
dirname = f'resources.icons.{icon_type}_light'
|
||||
else:
|
||||
dirname = 'resources.icons'
|
||||
|
||||
if HAS_IMPORTLIB_RESOURCE:
|
||||
with path(dirname, icon_name+'.png') as imgpath:
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
|
||||
return icon
|
||||
else:
|
||||
imgpath = resource_filename(dirname, icon_name+'.png')
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(imgpath), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
|
||||
return icon
|
||||
from .enums import Relations
|
||||
|
8
src/gui_qt/lib/enums.py
Normal file
8
src/gui_qt/lib/enums.py
Normal file
@ -0,0 +1,8 @@
|
||||
from enum import IntEnum, auto
|
||||
|
||||
|
||||
class Relations(IntEnum):
|
||||
isFitOf = auto()
|
||||
hasFit = auto()
|
||||
isFitPartOf = auto()
|
||||
hasFitPart = auto()
|
66
src/gui_qt/lib/iconloading.py
Normal file
66
src/gui_qt/lib/iconloading.py
Normal file
@ -0,0 +1,66 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
HAS_IMPORTLIB_RESOURCE = False
|
||||
from pkg_resources import resource_filename
|
||||
else:
|
||||
HAS_IMPORTLIB_RESOURCE = True
|
||||
from importlib.resources import path
|
||||
|
||||
from ..Qt import QtGui, QtWidgets
|
||||
|
||||
|
||||
def make_action_icons(widget):
|
||||
global HAS_IMPORTLIB_RESOURCE
|
||||
icon_type = QtWidgets.QApplication.instance().theme
|
||||
from json import loads
|
||||
|
||||
if HAS_IMPORTLIB_RESOURCE:
|
||||
with path('resources.icons', 'icons.json') as fp:
|
||||
with fp.open('r') as f:
|
||||
icon_list = loads(f.read())
|
||||
|
||||
for ac, img in icon_list[widget.objectName()].items():
|
||||
dirname = 'resources.icons.%s_light' % icon_type
|
||||
with path(dirname, img+'.png') as imgpath:
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
getattr(widget, ac).setIcon(icon)
|
||||
|
||||
else:
|
||||
with open(resource_filename('resources.icons', 'icons.json'), 'r') as f:
|
||||
icon_list = loads(f.read())
|
||||
|
||||
for ac, img in icon_list[widget.objectName()].items():
|
||||
dirname = 'resources.icons.%s_light' % icon_type
|
||||
imgpath = resource_filename(dirname, img+'.png')
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
getattr(widget, ac).setIcon(icon)
|
||||
|
||||
|
||||
def get_icon(icon_name):
|
||||
try:
|
||||
icon_type = QtWidgets.QApplication.instance().theme
|
||||
except AttributeError:
|
||||
icon_type = 'normal'
|
||||
|
||||
global HAS_IMPORTLIB_RESOURCE
|
||||
|
||||
if icon_name != 'logo':
|
||||
dirname = f'resources.icons.{icon_type}_light'
|
||||
else:
|
||||
dirname = 'resources.icons'
|
||||
|
||||
if HAS_IMPORTLIB_RESOURCE:
|
||||
with path(dirname, icon_name+'.png') as imgpath:
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(str(imgpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
|
||||
return icon
|
||||
else:
|
||||
imgpath = resource_filename(dirname, icon_name+'.png')
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(imgpath), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
|
||||
return icon
|
@ -1,4 +1,4 @@
|
||||
from . import HAS_IMPORTLIB_RESOURCE
|
||||
from .iconloading import HAS_IMPORTLIB_RESOURCE
|
||||
from ..Qt import QtGui, QtWidgets, QtCore
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ import copy
|
||||
|
||||
from numpy import argsort
|
||||
|
||||
from . import Relations
|
||||
from ..Qt import QtWidgets, QtCore
|
||||
from ..data.container import FitContainer
|
||||
from ..graphs.graphwindow import QGraphWindow
|
||||
@ -242,10 +243,17 @@ class DeleteCommand(QtWidgets.QUndoCommand):
|
||||
|
||||
if isinstance(val, FitContainer):
|
||||
try:
|
||||
self.__container[sid].fitted_key._fits.remove(sid)
|
||||
self.__container[val.fitted_key]._fits.remove(sid)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
for (flag1, flag2) in ((Relations.isFitPartOf, Relations.hasFitPart), (Relations.hasFitPart, Relations.isFitPartOf)):
|
||||
for related_item in val.get_relation(flag1):
|
||||
try:
|
||||
self.__container[related_item].remove_relation(flag2, sid)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
del self.__container[sid]
|
||||
|
||||
self.__graph_container[self.__graph_key].block(False)
|
||||
@ -264,6 +272,13 @@ class DeleteCommand(QtWidgets.QUndoCommand):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
for (flag1, flag2) in (('isFitPartOf', 'hasFitPartOf'), ('hasFitPartOf', 'isFitPartOf')):
|
||||
for related_item in val.get_relation(flag1):
|
||||
try:
|
||||
self.__container[related_item].add_relation(flag2, sid)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
self.__signal_add.emit(list(self.__keys), self.__graph_key)
|
||||
|
||||
self.__graph_container[self.__graph_key].block(False)
|
||||
|
Reference in New Issue
Block a user