Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Go back to using a single instance for ImgOccAcc and ImgOccEdit
Browse files Browse the repository at this point in the history
Haven't found a way to resolve the significant memory issues caused by calling a new instance any time the IO button isp ressed

Switching back to this will likely mean that some of the glitchy behaviour on OS X that might have been eliminated with the older changes will appear again, but compared to the memory leaks we saw before this is nothing to be overly concerned about
  • Loading branch information
glutanimate committed Oct 4, 2016
1 parent 67ec799 commit 6d222df
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 43 deletions.
3 changes: 2 additions & 1 deletion image_occlusion_enhanced/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class ImgOccEdit(QDialog):
def __init__(self, ImgOccAdd, mw):
QDialog.__init__(self, parent=mw)
QDialog.__init__(self, parent=None)
self.mw = mw
self.ImgOccAdd = ImgOccAdd
self.mode = self.ImgOccAdd.mode
Expand All @@ -32,6 +32,7 @@ def __init__(self, ImgOccAdd, mw):
def closeEvent(self, event):
if mw.pm.profile is not None:
saveGeom(self, "imageOccEditor")
QWidget.closeEvent(self, event)

def setupUi(self):
self.svg_edit = webview.AnkiWebView()
Expand Down
84 changes: 47 additions & 37 deletions image_occlusion_enhanced/image_occlusion_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ImgOccAdd(object):
def __init__(self, ed):
self.ed = ed
self.mw = mw
self.dialog = None
self.mode = "add"
self.onote = {}

Expand Down Expand Up @@ -138,18 +137,33 @@ def getImage(self, mode=None):
self.call_ImgOccEdit()

def call_ImgOccEdit(self):
self.dialog = ImgOccEdit(self, mw)
dialog = self.dialog
onote = self.onote

width, height = svgutils.imageProp(self.image_path)
initFill_color = self.mw.col.conf['image_occlusion_conf']['initFill[color]']
url = QUrl.fromLocalFile(svg_edit_path)
url.setQueryItems(svg_edit_queryitems)
url.addQueryItem('initFill[color]', initFill_color)
url.addQueryItem('dimensions', '{0},{1}'.format(width, height))
url.addQueryItem('bkgd_url', path2url(self.image_path))

bkgd_url = path2url(self.image_path)
try:
mw.ImgOccEdit is not None
existing_instance = True
except:
existing_instance = False
mw.ImgOccEdit = ImgOccEdit(self, mw)
dialog = mw.ImgOccEdit

if not existing_instance:
url = QUrl.fromLocalFile(svg_edit_path)
url.setQueryItems(svg_edit_queryitems)
url.addQueryItem('initFill[color]', initFill_color)
url.addQueryItem('dimensions', '{0},{1}'.format(width, height))
url.addQueryItem('bkgd_url', bkgd_url)
dialog.svg_edit.load(url)
else:
dialog.svg_edit.eval("""
svgCanvas.clear();
svgCanvas.setBackground('#FFF', '%s');
svgCanvas.setResolution(%s, %s);
svgCanvas.runExtensions('onNewDocument');
svgCanvas.zoomChanged('', 'canvas');
""" %(bkgd_url, width, height))

if self.mode != "add":
dialog.header_edit.setPlainText(onote["header"])
dialog.footer_edit.setPlainText(onote["footer"])
Expand All @@ -163,13 +177,11 @@ def call_ImgOccEdit(self):
dialog.tags_edit.setCol(self.mw.col)
dialog.sources_edit.setPlainText(onote["sources"])

dialog.svg_edit.load(url)
dialog.show()
dialog.exec_()


def onAddNotesButton(self, choice):
svg_edit = self.dialog.svg_edit
svg_edit = mw.ImgOccEdit.svg_edit
svg_contents = svg_edit.page().mainFrame().evaluateJavaScript(
"svgCanvas.svgCanvasToString();"
)
Expand All @@ -181,38 +193,36 @@ def onAddNotesButton(self, choice):
extra1, extra2) = self.getUserInputs()

# Add notes to the current deck of the collection:
if choice in ["nonoverlapping", "overlapping"]:
# add_notes_non_overlapping(svg, mask_fill_color,
# tags, self.image_path,
# header, footer, remarks, sources,
# extra1, extra2, did)
if choice == "nonoverlapping":
gen = ImgOccNoteGeneratorHiding(self.image_path, svg, tags, header, footer, remarks, sources, extra1, extra2, did)
gen.generate_notes()
if self.ed.note:
elif choice == "overlapping":
gen = ImgOccNoteGeneratorSeparate(self.image_path, svg, tags, header, footer, remarks, sources, extra1, extra2, did)
gen.generate_notes()
elif choice == "edit":
pass
elif choice == "edit-and-switch":
pass

if self.ed.note:
if choice in ["overlapping", "nonoverlapping"]:
# Update Editor with modified tags and sources field
self.ed.tags.setText(" ".join(tags))
self.ed.saveTags()
if IO_FLDS["sources"] in self.ed.note:
self.ed.note[IO_FLDS["sources"]] = sources
self.ed.loadNote()
else:
update_notes(choice, svg, mask_fill_color,
tags, self.image_path,
header, footer, remarks, sources,
extra1, extra2, did)
if self.ed.note:
self.ed.loadNote()
self.mw.reset()

def getUserInputs(self):
header = self.dialog.header_edit.toPlainText().replace('\n', '<br />')
footer = self.dialog.footer_edit.toPlainText().replace('\n', '<br />')
remarks = self.dialog.remarks_edit.toPlainText().replace('\n', '<br />')
sources = self.dialog.sources_edit.toPlainText().replace('\n', '<br />')
extra1 = self.dialog.extra1_edit.toPlainText().replace('\n', '<br />')
extra2 = self.dialog.extra2_edit.toPlainText().replace('\n', '<br />')
did = self.dialog.deckChooser.selectedId()
tags = self.dialog.tags_edit.text().split()
header = mw.ImgOccEdit.header_edit.toPlainText().replace('\n', '<br />')
footer = mw.ImgOccEdit.footer_edit.toPlainText().replace('\n', '<br />')
remarks = mw.ImgOccEdit.remarks_edit.toPlainText().replace('\n', '<br />')
sources = mw.ImgOccEdit.sources_edit.toPlainText().replace('\n', '<br />')
extra1 = mw.ImgOccEdit.extra1_edit.toPlainText().replace('\n', '<br />')
extra2 = mw.ImgOccEdit.extra2_edit.toPlainText().replace('\n', '<br />')
did = mw.ImgOccEdit.deckChooser.selectedId()
tags = mw.ImgOccEdit.tags_edit.text().split()
return (did, tags, header, footer, remarks, sources, extra1, extra2)


Expand All @@ -225,7 +235,7 @@ def invoke_io_help():
openLink(io_help_link)

def onImgOccButton(ed, mode):
ioInstance = ImgOccAdd(ed)
ed.ImgOccAdd = ImgOccAdd(ed)
# note type integrity check
ioModel = mw.col.models.byName(IO_MODEL_NAME)
if ioModel:
Expand All @@ -238,7 +248,7 @@ def onImgOccButton(ed, mode):
<a href="' + io_help_link + '/Customization#a-note-of-warning">\
Wiki - Note Type Customization</a>')
return
ioInstance.getImage(mode)
ed.ImgOccAdd.getImage(mode)

def onSetupEditorButtons(self):
# Add IO button to Editor
Expand Down
12 changes: 8 additions & 4 deletions image_occlusion_enhanced/notegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ def __init__(self, image, svg, tags, header, footer, remarks, sources,
ImgOccNoteGenerator.__init__(self, image, svg, tags, header, footer, remarks, sources,
extra1, extra2, did)

def _create_mask_at_layernode(self, mask_node_index, all_mask_node_indexes, layer_node):
def _create_mask_at_layernode(self, side, mask_node_index, all_mask_node_indexes, layer_node):
#Delete all child nodes except for mask_node_index
for i in reversed(all_mask_node_indexes):
if not i == mask_node_index:
layer_node.removeChild(layer_node.childNodes[i])
if side == "Q":
for i in reversed(all_mask_node_indexes):
if not i == mask_node_index:
layer_node.removeChild(layer_node.childNodes[i])
if side == "A":
layer_node.unlink()
pass



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,7 @@
{sel:'#tool_text', fn: clickText, evt: 'click', key: ['T', true]},
{sel:'#tool_image', fn: clickImage, evt: 'mouseup'},
{sel:'#tool_zoom', fn: clickZoom, evt: 'mouseup', key: ['', true]},
{sel:'#tool_clear', fn: clickClear, evt: 'mouseup', key: ['', true]},
{sel:'#tool_clear', fn: clickClear, evt: 'mouseup', key: ['N', true]},
{sel:'#tool_save', fn: function() { editingsource?saveSourceEditor():clickSave()}, evt: 'mouseup', key: ['', true]},
{sel:'#tool_export', fn: clickExport, evt: 'mouseup'},
{sel:'#tool_open', fn: clickOpen, evt: 'mouseup', key: ['O', true]},
Expand Down

0 comments on commit 6d222df

Please sign in to comment.