Skip to content

Commit

Permalink
when deleting axes labels only set their text to '' instead of hiding…
Browse files Browse the repository at this point in the history
… them (fixed #18)
  • Loading branch information
rgerum committed Feb 28, 2023
1 parent 683a06e commit ab9e3ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 16 additions & 2 deletions pylustrator/change_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def get_describtion_string(self, element, exclude_default=True):
if getattr(element, "is_new_text", False):
return element.axes or element.figure, f".text(0, 0, "", visible=False)"
else:
is_label = np.any([ax.xaxis.get_label() == element or ax.yaxis.get_label() == element for ax in
element.figure.axes])
if is_label:
return element, f".set(text='')"
return element, f".set(visible=False)"

# properties to store
Expand Down Expand Up @@ -574,15 +578,25 @@ def removeElement(self, element: Artist):
if reference_obj == element:
del self.changes[reference_obj, reference_command]
if not created_by_pylustrator or isinstance(element, Text):
is_label = np.any([ax.xaxis.get_label() == element or ax.yaxis.get_label() == element for ax in element.figure.axes])
if is_label:
text_content = element.get_text()

def redo():
element.set_visible(False)
if is_label:
element.set_text("")
else:
element.set_visible(False)
if isinstance(element, Text):
main_figure(element).change_tracker.addNewTextChange(element)
else:
self.addChange(element, ".set(visible=False)")

def undo():
element.set_visible(True)
if is_label:
element.set_text(text_content)
else:
element.set_visible(True)
if isinstance(element, Text):
main_figure(element).change_tracker.addNewTextChange(element)
else:
Expand Down
3 changes: 2 additions & 1 deletion pylustrator/components/qitem_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from pylustrator.change_tracker import getReference
from pylustrator.QLinkableWidgets import QColorWidget, CheckWidget, TextWidget, DimensionsWidget, NumberWidget, ComboWidget
from pylustrator.helper_functions import main_figure
from pylustrator.change_tracker import UndoRedo, add_text_default
from pylustrator.change_tracker import UndoRedo, add_text_default, add_axes_default


class TextPropertiesWidget(QtWidgets.QWidget):
Expand Down Expand Up @@ -1153,6 +1153,7 @@ def addChange(element, command):
self.fig.change_tracker.addChange(self.element,
".add_axes([0.25, 0.25, 0.5, 0.5], label=\"%s\") # id=%s.new" % (
filename, getReference(axes)), axes, ".new")
add_axes_default(axes)
addChange(axes, ".imshow(plt.imread(\"%s\"))" % filename)
addChange(axes, '.set_xticks([])')
addChange(axes, '.set_yticks([])')
Expand Down

0 comments on commit ab9e3ce

Please sign in to comment.