Skip to content

Commit

Permalink
Use ipywidgets to produce forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Deschamps committed Apr 15, 2017
1 parent 78f05c2 commit 91b00c6
Show file tree
Hide file tree
Showing 2 changed files with 388 additions and 71 deletions.
256 changes: 222 additions & 34 deletions descriptor/.ipynb_checkpoints/PopulateSeedsCPP-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"metadata": {
"collapsed": true
},
Expand All @@ -69,7 +69,29 @@
"sys.path.append('/opt/anaconda/anaconda3/lib/python3.6/site-packages')\n",
"import tinydb as tdb\n",
"import time\n",
"#import networkx"
"#import networkx\n",
"from ipywidgets import widgets, Layout"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello\n",
"there\n"
]
}
],
"source": [
"collection_title = wid_collection_title.value\n",
"WALK_collection_folder = wid_WALK_collection_folder.value\n",
"print (collection_title)\n",
"print (WALK_collection_folder)"
]
},
{
Expand Down Expand Up @@ -149,21 +171,211 @@
" \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use a pre-set form to enter information\n",
"\n",
"The next window will ask you for the new information piece by piece. If you do not want to use this form in this way, you can enter the information directly into the Python object below."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bd2d1488c86a40b5aa45513bc6ef8342"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "15d785d6771943aa863d2e7bece83b66"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "979648fb90ae4e2fa9f7914d5f549b19"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8ed2967c4cbf4c1cabe5684e1fc04d06"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "aa7e2abc4f554279912ccef38594c77e"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3c53b889bff24908a941b67d8a021a79"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4a02996b4d54414ca590f146db1cb7d5"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5ed047dfdff241bab31fdb08877d2e01"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c274047466c94012909612031165b9b4"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eac352cec35a438eb3d9961a501cdd2c"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import display\n",
"label1 = widgets.Label(value=\"Enter the Collection\\'s title\", layout=Layout(width=\"50%\"))\n",
"display(label1)\n",
"wid_collection_title = widgets.Text()\n",
"display(wid_collection_title)\n",
"label2 = widgets.Label(value=\"Enter the Collection\\'s filename\", layout=Layout(width=\"50%\"))\n",
"display(label2)\n",
"wid_WALK_collection_folder = widgets.Text()\n",
"display (wid_WALK_collection_folder)\n",
"label3 = widgets.Label(value=\"Enter the Institutional description\", layout=Layout(width=\"50%\"))\n",
"display(label3)\n",
"wid_institutional_description = widgets.Textarea(layout=Layout(width=\"50%\", height=\"150px\"))\n",
"display (wid_institutional_description)\n",
"label4 = widgets.Label(value=\"Describe the collection yourself (about 50 words)\", layout=Layout(width=\"50%\"))\n",
"display(label4)\n",
"wid_WALK_description = widgets.Textarea(layout=Layout(width=\"50%\", height=\"150px\"))\n",
"display (wid_WALK_description)\n",
"label5 = widgets.Label(value=\"Describe the graphViz graph, in your own words.\", layout=Layout(width=\"50%\"))\n",
"display(label5)\n",
"wid_crawl_viz_description = widgets.Textarea(layout=Layout(width=\"50%\", height=\"150px\"))\n",
"display (wid_crawl_viz_description)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Review Your Information\n",
"\n",
"Review your results below. If you discover an error, please go to the previous window and re-enter the information."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the collection title:hello\n"
"Review your results here. If you discover an error, please go to the previous window and re-enter the information.\n",
"The collection title is: \n",
"\n",
"This one\n",
"\n",
"WALK_collection_folder: \n",
"\n",
"That one\n",
"\n",
"Institutional Description \n",
"\n",
"hello ther eslkdjfakljs\n",
"\n",
"WALK_description \n",
"\n",
"other there\n",
"\n",
"Crawl Viz description \n",
"\n",
"alsdkfjsalkj lkajsflkj laskf ljakslfj lsj\n",
"\n"
]
}
],
"source": [
"collection_title = input(\"Enter the collection title:\")\n"
"print (\"Review your results here. If you discover an error, please go to the previous window and re-enter the information.\")\n",
"print (\"The collection title is: \\n\\n\" + wid_collection_title.value + \"\\n\")\n",
"print (\"WALK_collection_folder: \\n\\n\" + wid_WALK_collection_folder.value + \"\\n\")\n",
"print (\"Institutional Description \\n\\n\" + wid_institutional_description.value + \"\\n\")\n",
"print (\"WALK_description \\n\\n\" + wid_WALK_description.value + \"\\n\")\n",
"print (\"Crawl Viz description \\n\\n\" + wid_crawl_viz_description.value + \"\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enter data into python object\n",
"\n",
"If everything checks out above, you can enter the information into the database with the code below. Note, you can also skip the Use **\"a pre-set form to enter information\"** step and replace the input variables with a string. A string is information encased in single quotes like:\n",
"\n",
"` 'This is a string' `\n",
"\n",
"So if the collection is called \"COLLECTION\", the you could replace the line that says\n",
"\n",
"`'collection_title' : collection_title,`\n",
"\n",
"with:\n",
"\n",
"` 'collection_title' : 'COLLECTION',`\n",
"\n",
"You could also include more information by adding another item at the end followed by a comma. For instance, \n",
"\n",
"` 'special_notes' : 'The crawls on 2012 appear to be lost.', `\n",
"\n",
"Would add an entry called 'special_notes' that includes the information about the missing 2012 web crawls. You do not have to enter this information if you do not want to.\n",
"\n",
"If the collection title and collection folder are both not matched in the database, the code below will enter the data and print \"inserted.\" If the collection title already exists, it will enter 'updated (name of collection)\" and the old data entry will be put in a backup database for future reference."
]
},
{
Expand All @@ -185,45 +397,22 @@
" ## collection_title and WALK_collection_folder are used to decide\n",
" ## whether to insert a new item or to update an old one ...\n",
" \n",
" 'collection_title' : 'Canadian Political Parties and Political Interest Groups',\n",
" 'collection_title' : collection_title,\n",
" \n",
" 'WALK_collection_folder' : 'TORONTO_Canadian_Political_Parties',\n",
" 'WALK_collection_folder' : WALK_collection_folder,\n",
" \n",
" ## If you accidentally update the wrong item, you can retrieve the old value from the \n",
" ## collections_backup table.\n",
" \n",
" \n",
" # How does the Library/Archives describe the archive?\n",
" 'institutional_description' : '''\n",
" \n",
" Canadian Political Parties and Political Interest Groups will archive the websites of all \n",
" the national Canadian political parties, and a number of special interest groups across \n",
" the political spectrum.\n",
" \n",
" ''',\n",
" 'institutional_description' : institutional_description,\n",
" \n",
" # In your own words, how do you describe the collection\n",
" 'WALK_description' : '''\n",
" \n",
" Contains the web archives for the main parties (Liberal, Conservatives, NDP, Bloc, Green) but \n",
" also a wide range marginal parties (Cosmopolitan Party, Canadian Action, Christian Heritage and\n",
" so on). The \"special interest groups\" include the David Suzuki Foundation (an environmental \n",
" advocacy group) and fairvote.ca (advocacy for changing the electoral system).\n",
" \n",
" ''',\n",
" 'WALK_description' : WALK_description,\n",
" \n",
" # What file did you use to view the viz-link?\n",
" 'crawl_viz_link_file' : 'TORONTO_Canadian_Political_Parties-urls.html',\n",
" \n",
" 'crawl_viz_description' : '''\n",
" \n",
" - Between March 06 and January 07 and then again between July 09 & November 09, Policy Alternatives had the\n",
" largest amount of activity.\n",
" - A rise in activity for equalvoice.ca (advocacy for women in political leadership) between December 09 and \n",
" November 2011.\n",
" - Of the major parties, the Liberal Party of Canada and the Green Party had the most activity.\n",
" \n",
" ''',\n",
" 'crawl_viz_description' : crawl_viz_description,\n",
" \n",
" ## You can add additional items here using the format \n",
" ## 'META_DATA_TAG' : 'DATA_VALUES',\n",
Expand Down Expand Up @@ -296,7 +485,6 @@
" political party\" that seeks the \"political, economic and cultural assimilation of Canada, into the\n",
" United States, under the _Security and Prosperity Partnership_ (SPP).\"\n",
" ''', \n",
" \"some new information\" : \"\"\n",
" }\n",
"\n",
"seed_exists = ((seed_main.search(Seed.collection_title==seed['collection_title']) or seed_main.search(Seed.WALK_collection_folder==seed['WALK_collection_folder']))\n",
Expand Down
Loading

0 comments on commit 91b00c6

Please sign in to comment.