Skip to content

Commit

Permalink
Update field labels when launching editor
Browse files Browse the repository at this point in the history
  • Loading branch information
glutanimate committed Mar 29, 2016
1 parent 704c724 commit 220b203
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ Image Occlusion 2.0 Enhanced can be customized, but only to a certain degree

**What you really should not do**:

- delete or rename the `Image Q/A - 2.0 Enhanced` note type
+ deleting the note type should restore it to default next time I/O is launched, but doing so will remove all notes associated with it
- re-order the fields of the note-type
- add new fields or remove existing ones
- rename the following fields: *Question*, *Answer*, *SVG*, *Original Image*

**What you can do**:

- rename the following fields: *Header*, *Footer*, *Remarks*, *Sources*, *TempField3*, *TempField4*, *TempField5*
+ depending on whether you've already used I/O in your Anki session you might first have to restart Anki to see the changes in the Image Occlusion Editor
- modify the card template and CSS
+ Be careful, though, as the right styling and layout is essential for layering the original image and SVG mask over each other
+ be careful, though: the right styling and layout is essential for layering the original image and SVG mask over each other

## Tips

Expand Down
52 changes: 30 additions & 22 deletions image_occlusion_2/image_occlusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def add_notes(self):
orig_tags = self.ed.tags.text()
if model_name == IMAGE_QA_MODEL_NAME:
valid_model = True
orig_image = self.ed.note.fields[3].replace('<br />', '\n')
orig_image = self.ed.note.fields[3]
orig_header = self.ed.note.fields[4].replace('<br />', '\n')
orig_footer = self.ed.note.fields[5].replace('<br />', '\n')
orig_remarks = self.ed.note.fields[6].replace('<br />', '\n')
Expand Down Expand Up @@ -226,7 +226,7 @@ def call_ImageOcc_Editor(self, path, orig_tags, orig_header, orig_footer,
width = d['width']

# existing instance of I/O Editor
# TODO: understand why we don't just launch a new instance each time I/O is invoked
## TODO: understand why we don't just launch a new instance each time I/O is invoked
try:
mw.ImageOcc_Editor is not None
select_rect_tool = "svgCanvas.setMode('rect'); "
Expand All @@ -238,9 +238,9 @@ def call_ImageOcc_Editor(self, path, orig_tags, orig_header, orig_footer,
mw.ImageOcc_Editor.svg_edit.eval(command)

# update pyobj with new instance
# this is necessary for instance variables (e.g. self.reuse_note) to get
# updated properly in the add_notes_* functions.
# TODO: understand what's going on and find a better solution
## this is necessary for instance variables (e.g. self.reuse_note) to get
## updated properly in the add_notes_* functions.
## TODO: understand what's going on and find a better solution
mw.ImageOcc_Editor.svg_edit.\
page().\
mainFrame().\
Expand All @@ -251,22 +251,30 @@ def call_ImageOcc_Editor(self, path, orig_tags, orig_header, orig_footer,
# only copy sources field if not undefined
if orig_sources is not None:
mw.ImageOcc_Editor.sources_edit.setPlainText(orig_sources)
# reuse all fields if started from existing i/o note
# reuse fields if started from existing i/o note
if self.reuse_note:
mw.ImageOcc_Editor.header_edit.setPlainText(orig_header)
mw.ImageOcc_Editor.footer_edit.setPlainText(orig_footer)
mw.ImageOcc_Editor.remarks_edit.setPlainText(orig_remarks)
else:
mw.ImageOcc_Editor.reset_main_fields()

# this redundant sequence of setFocus() calls prevents a bug where
# SVG-Edit would stop working when the Editor window is closed
# before adding I/O notes
# TODO: find another solution
# update labels
mw.ImageOcc_Editor.header_label.setText(header_field)
mw.ImageOcc_Editor.footer_label.setText(footer_field)
mw.ImageOcc_Editor.sources_label.setText(sources_field)
mw.ImageOcc_Editor.remarks_label.setText(remarks_field)
# set tab index
mw.ImageOcc_Editor.tab_widget.setCurrentIndex(0)
# set widget focus
## this redundant sequence of setFocus() calls prevents a bug where
## SVG-Edit would stop working when the Editor window is closed
## before adding I/O notes
## TODO: find another solution
mw.ImageOcc_Editor.svg_edit.setFocus()
mw.ImageOcc_Editor.header_edit.setFocus()
mw.ImageOcc_Editor.svg_edit.setFocus()

mw.ImageOcc_Editor.show()

# no existing instance of I/O Editor. Launch new one
Expand Down Expand Up @@ -387,41 +395,41 @@ def initUI(self, tags):
# Header
self.header_edit = QPlainTextEdit()
self.header_edit.setTabChangesFocus(True)
header_label = QLabel(header_field)
header_label.setFixedWidth(70)
self.header_label = QLabel(header_field)
self.header_label.setFixedWidth(70)

header_hbox = QHBoxLayout()
header_hbox.addWidget(header_label)
header_hbox.addWidget(self.header_label)
header_hbox.addWidget(self.header_edit)

# Footer
self.footer_edit = QPlainTextEdit()
self.footer_edit.setTabChangesFocus(True)
footer_label = QLabel(footer_field)
footer_label.setFixedWidth(70)
self.footer_label = QLabel(footer_field)
self.footer_label.setFixedWidth(70)

footer_hbox = QHBoxLayout()
footer_hbox.addWidget(footer_label)
footer_hbox.addWidget(self.footer_label)
footer_hbox.addWidget(self.footer_edit)

# Remarks
self.remarks_edit = QPlainTextEdit()
self.remarks_edit.setTabChangesFocus(True)
remarks_label = QLabel(remarks_field)
remarks_label.setFixedWidth(70)
self.remarks_label = QLabel(remarks_field)
self.remarks_label.setFixedWidth(70)

remarks_hbox = QHBoxLayout()
remarks_hbox.addWidget(remarks_label)
remarks_hbox.addWidget(self.remarks_label)
remarks_hbox.addWidget(self.remarks_edit)

# Sources
self.sources_edit = QPlainTextEdit()
self.sources_edit.setTabChangesFocus(True)
sources_label = QLabel(sources_field)
sources_label.setFixedWidth(70)
self.sources_label = QLabel(sources_field)
self.sources_label.setFixedWidth(70)

sources_hbox = QHBoxLayout()
sources_hbox.addWidget(sources_label)
sources_hbox.addWidget(self.sources_label)
sources_hbox.addWidget(self.sources_edit)

# Tags
Expand Down

0 comments on commit 220b203

Please sign in to comment.