Skip to content

Commit

Permalink
Export tab functional
Browse files Browse the repository at this point in the history
  • Loading branch information
Dcosthephalump committed Aug 1, 2023
1 parent 88085b0 commit 15c3ef0
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 78 deletions.
Binary file modified glyptodon/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/annotation.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/classes.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/export.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/information.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/manuscriptFiles.cpython-311.pyc
Binary file not shown.
Binary file modified glyptodon/__pycache__/selection.cpython-311.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion glyptodon/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
'glyptodon/annotation.py'),
'glyptodon.annotation.createAnnotationTextArea': ( 'annotation.html#createannotationtextarea',
'glyptodon/annotation.py'),
'glyptodon.annotation.createNextTab': ('annotation.html#createnexttab', 'glyptodon/annotation.py'),
'glyptodon.annotation.createPageSelector': ( 'annotation.html#createpageselector',
'glyptodon/annotation.py'),
'glyptodon.annotation.createSaveAnnotation': ( 'annotation.html#createsaveannotation',
'glyptodon/annotation.py'),
'glyptodon.annotation.createSaveShapes': ( 'annotation.html#createsaveshapes',
'glyptodon/annotation.py')},
'glyptodon.app': { 'glyptodon.app.finalizeSelectionCallback': ('app.html#finalizeselectioncallback', 'glyptodon/app.py'),
'glyptodon.app': { 'glyptodon.app.exportManuscriptCallback': ('app.html#exportmanuscriptcallback', 'glyptodon/app.py'),
'glyptodon.app.finalizeSelectionCallback': ('app.html#finalizeselectioncallback', 'glyptodon/app.py'),
'glyptodon.app.lineNumberCallback': ('app.html#linenumbercallback', 'glyptodon/app.py'),
'glyptodon.app.nextTabCallback': ('app.html#nexttabcallback', 'glyptodon/app.py'),
'glyptodon.app.pageSelectorCallback': ('app.html#pageselectorcallback', 'glyptodon/app.py'),
'glyptodon.app.saveAnnotationCallback': ('app.html#saveannotationcallback', 'glyptodon/app.py'),
'glyptodon.app.saveNContinuteCallback': ('app.html#savencontinutecallback', 'glyptodon/app.py'),
Expand Down
7 changes: 6 additions & 1 deletion glyptodon/annotation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_annotation.ipynb.

# %% auto 0
__all__ = ['createAnnotationTextArea', 'createPageSelector', 'createSaveShapes', 'createSaveAnnotation', 'createAnnotationFigure']
__all__ = ['createAnnotationTextArea', 'createPageSelector', 'createSaveShapes', 'createSaveAnnotation', 'createNextTab',
'createAnnotationFigure']

# %% ../nbs/04_annotation.ipynb 5
from dash import dcc, html
Expand All @@ -25,6 +26,10 @@ def createSaveAnnotation():
return html.Button("Save Annotation", id="save-annotation")

# %% ../nbs/04_annotation.ipynb 17
def createNextTab():
return html.Button("Next Tab", id="next-tab")

# %% ../nbs/04_annotation.ipynb 19
def createAnnotationFigure(path):
img = cv2.imread(path)
# This reorders the color channels (the first two indices relate to the intensity values of individual colors while the last index indicates what
Expand Down
41 changes: 34 additions & 7 deletions glyptodon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# %% auto 0
__all__ = ['selectionKey', 'manuscriptSelect', 'selectionInfo', 'finalizeSelection', 'metadata', 'inputObjects', 'centuries',
'centuriesSlider', 'uploadImages', 'uploadManuscripts', 'informationInfo', 'saveNContinue',
'annotationTextArea', 'pageSelector', 'saveShapes', 'saveAnnotation', 'exportInfo', 'exportName',
'annotationTextArea', 'pageSelector', 'saveShapes', 'saveAnnotation', 'nextTab', 'exportInfo', 'exportName',
'directoryOptions', 'exportButton', 'exportDownload', 'app', 'newManuscript', 'selectedManuscript',
'testVar', 'selectManuscript', 'finalizeSelectionCallback', 'pageSelectorCallback', 'saveShapesCallback',
'lineNumberCallback', 'saveAnnotationCallback', 'saveNContinuteCallback']
'selectManuscript', 'finalizeSelectionCallback', 'pageSelectorCallback', 'saveShapesCallback',
'lineNumberCallback', 'saveAnnotationCallback', 'saveNContinuteCallback', 'nextTabCallback',
'exportManuscriptCallback']

# %% ../nbs/07_app.ipynb 4
from dash import Dash, State, Input, Output, callback, dcc, html
Expand Down Expand Up @@ -47,6 +48,7 @@
pageSelector = createPageSelector()
saveShapes = createSaveShapes()
saveAnnotation = createSaveAnnotation()
nextTab = createNextTab()


##############
Expand Down Expand Up @@ -130,6 +132,7 @@
saveShapes,
annotationTextArea,
saveAnnotation,
nextTab,
]
)
],
Expand Down Expand Up @@ -179,6 +182,7 @@
suppress_callback_exceptions=True,
)
def selectManuscript(work):
global selectedManuscript
if work == "Create New Manuscript":
newManuscript = True
selectedManuscript = None
Expand Down Expand Up @@ -218,6 +222,7 @@ def selectManuscript(work):
prevent_initial_call=True,
)
def finalizeSelectionCallback(clicks):
global selectedManuscript
dropdownOptions = []
relativePaths = manuscriptImages(selectedManuscript[0])

Expand All @@ -237,6 +242,7 @@ def finalizeSelectionCallback(clicks):
prevent_initial_call=True,
)
def pageSelectorCallback(path):
global selectedManuscript
fig = createAnnotationFigure(path)

imageName = path.split("/")[-1] # This takes the file name in the directory
Expand Down Expand Up @@ -293,6 +299,7 @@ def pageSelectorCallback(path):
prevent_initial_call=True,
)
def saveShapesCallback(clicks, shapes, path):
global selectedManuscript
dictLines = []
dictBBoxes = []
for shape in shapes["shapes"]:
Expand Down Expand Up @@ -394,6 +401,7 @@ def lineNumberCallback(shapes, currentText):
prevent_initial_call=True,
)
def saveAnnotationCallback(clicks, shapes, path, currentText):
global selectedManuscript
dictLines = []
dictBBoxes = []
for shape in shapes["shapes"]:
Expand Down Expand Up @@ -466,8 +474,6 @@ def saveAnnotationCallback(clicks, shapes, path, currentText):
return dummy

# %% ../nbs/07_app.ipynb 22
print(selectedManuscript)
testVar = 1
@callback(
Output("tabs-object", "value", allow_duplicate=True),
Input("save-and-continue", "n_clicks"),
Expand Down Expand Up @@ -503,8 +509,7 @@ def saveNContinuteCallback(
# manFilenames,
manSelect, # State manuscript-select
):
print(testVar)
print(selectedManuscript)
global selectedManuscript
centuriesData = ""
if centuriesValue[0] == centuriesValue[1]:
centuriesData = centuries[centuriesValue[0]] + " Century"
Expand Down Expand Up @@ -535,5 +540,27 @@ def saveNContinuteCallback(
return "annotation"

# %% ../nbs/07_app.ipynb 24
@callback(
Output("tabs-object", "value", allow_duplicate=True),
Input("next-tab", "n_clicks"),
prevent_initial_call=True,
)
def nextTabCallback(clicks):
return "export"

# %% ../nbs/07_app.ipynb 26
@callback(
Output("export-download", "data"),
Input("export-button", "n_clicks"),
State("export-name", "value"),
State("directory-options", "value"),
prevent_initial_call=True,
)
def exportManuscriptCallback(clicks, name, options):
global selectedManuscript
path = zipManuscript(options, selectedManuscript[0], name)
return dcc.send_file(path)

# %% ../nbs/07_app.ipynb 28
if __name__ == "__main__":
app.run(debug=True)
2 changes: 1 addition & 1 deletion glyptodon/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def createExportInfo():
return dcc.Markdown(
"""
# Information
# Export
This menu allows you to export the manuscript and transcriptions you've worked on as a zipped folder.
Expand Down
31 changes: 23 additions & 8 deletions glyptodon/manuscriptFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ def directoryNameClean(string):
return string.lower()

# %% ../nbs/01_manuscriptFiles.ipynb 16
def saveImages(contents: list, filenames: list, targetDirectory):
def saveImages(contents, filenames, targetDirectory):
# This function saves content from memory into storage using the keys in the passed files dict (from a FileUpload widget)
# This
baseDirectory = os.getcwd()
os.chdir(os.path.join(targetDirectory, "images"))


if type(contents) != list:
contents = [contents]
filenames = [filenames]

for i in range(0, len(contents)):
string64 = contents[i].encode("utf8").split(b";base64,")[1]
imdata = base64.b64decode(string64)
Expand Down Expand Up @@ -177,18 +181,30 @@ def zipManuscript(directoryOptions: list, manuscriptDirectory, name: str):
import zipfile
# standard call here to avoid getting the system lost in directories
baseDirectory = os.getcwd()


lowerOptions = []
for option in directoryOptions:
lowerOptions.append(option.lower())

files = []
for path in os.listdir(manuscriptDirectory):
# this deletes any currently zipped folder
if path.endswith(".zip"):
os.remove(os.path.join(manuscriptDirectory, path))

# this collects all the files inside option folders
if path in directoryOptions:
tempDirectory = os.path.join(manuscriptDirectory, path)
for file in os.listdir(tempDirectory):
files.append(os.path.join(tempDirectory, file))
if path in lowerOptions:
if path == "states":
tempDirectoryStates = os.path.join(manuscriptDirectory, path)
for statesPath in os.listdir(tempDirectoryStates):
if statesPath in ["bboxes","lines"]:
tempDirectory = os.path.join(tempDirectoryStates, statesPath)
for file in os.listdir(tempDirectory):
files.append(os.path.join(tempDirectory, file))
else:
tempDirectory = os.path.join(manuscriptDirectory, path)
for file in os.listdir(tempDirectory):
files.append(os.path.join(tempDirectory, file))

# this zips the collected files
os.chdir(manuscriptDirectory)
Expand All @@ -215,7 +231,6 @@ def updateMetadata(directory, information):
f = open(file, 'w')
printable = dictToList(information)
for data in printable:
print(data)
f.write(data + '\n')

os.chdir(baseDirectory)
Expand Down
35 changes: 25 additions & 10 deletions nbs/01_manuscriptFiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -368,12 +368,16 @@
"outputs": [],
"source": [
"#| export\n",
"def saveImages(contents: list, filenames: list, targetDirectory):\n",
"def saveImages(contents, filenames, targetDirectory):\n",
" # This function saves content from memory into storage using the keys in the passed files dict (from a FileUpload widget)\n",
" # This\n",
" baseDirectory = os.getcwd()\n",
" os.chdir(os.path.join(targetDirectory, \"images\"))\n",
"\n",
" \n",
" if type(contents) != list:\n",
" contents = [contents]\n",
" filenames = [filenames]\n",
" \n",
" for i in range(0, len(contents)):\n",
" string64 = contents[i].encode(\"utf8\").split(b\";base64,\")[1]\n",
" imdata = base64.b64decode(string64)\n",
Expand Down Expand Up @@ -689,7 +693,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 15,
"metadata": {
"tags": []
},
Expand All @@ -700,18 +704,30 @@
" import zipfile\n",
" # standard call here to avoid getting the system lost in directories\n",
" baseDirectory = os.getcwd()\n",
"\n",
" \n",
" lowerOptions = []\n",
" for option in directoryOptions:\n",
" lowerOptions.append(option.lower())\n",
" \n",
" files = []\n",
" for path in os.listdir(manuscriptDirectory):\n",
" # this deletes any currently zipped folder\n",
" if path.endswith(\".zip\"):\n",
" os.remove(os.path.join(manuscriptDirectory, path))\n",
" \n",
" # this collects all the files inside option folders\n",
" if path in directoryOptions:\n",
" tempDirectory = os.path.join(manuscriptDirectory, path)\n",
" for file in os.listdir(tempDirectory):\n",
" files.append(os.path.join(tempDirectory, file))\n",
" if path in lowerOptions:\n",
" if path == \"states\":\n",
" tempDirectoryStates = os.path.join(manuscriptDirectory, path)\n",
" for statesPath in os.listdir(tempDirectoryStates):\n",
" if statesPath in [\"bboxes\",\"lines\"]:\n",
" tempDirectory = os.path.join(tempDirectoryStates, statesPath)\n",
" for file in os.listdir(tempDirectory):\n",
" files.append(os.path.join(tempDirectory, file))\n",
" else:\n",
" tempDirectory = os.path.join(manuscriptDirectory, path)\n",
" for file in os.listdir(tempDirectory):\n",
" files.append(os.path.join(tempDirectory, file))\n",
" \n",
" # this zips the collected files\n",
" os.chdir(manuscriptDirectory)\n",
Expand Down Expand Up @@ -779,7 +795,6 @@
" f = open(file, 'w')\n",
" printable = dictToList(information)\n",
" for data in printable:\n",
" print(data)\n",
" f.write(data + '\\n')\n",
" \n",
" os.chdir(baseDirectory)"
Expand Down
20 changes: 20 additions & 0 deletions nbs/04_annotation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,26 @@
" return html.Button(\"Save Annotation\", id=\"save-annotation\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## createNextTab\n",
"\n",
"To keep users able to move on to the next tab without using the tab object, this button is created. It's not a complicated button."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"def createNextTab():\n",
" return html.Button(\"Next Tab\", id=\"next-tab\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion nbs/06_export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"def createExportInfo():\n",
" return dcc.Markdown(\n",
" \"\"\"\n",
" # Information\n",
" # Export\n",
" \n",
" This menu allows you to export the manuscript and transcriptions you've worked on as a zipped folder.\n",
" \n",
Expand Down
Loading

1 comment on commit 15c3ef0

@Dcosthephalump
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit hooked the export tab up to the zipManuscript function and has, for all intents and purposes, completed the functionality of the application.

Please sign in to comment.