-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1bd8e4
commit 01d61d5
Showing
9 changed files
with
655 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,62 @@ | ||
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_file_viewer.ipynb. | ||
|
||
# %% auto 0 | ||
__all__ = ['FileViewer'] | ||
__all__ = ['FileViewerView', 'FileModel', 'FileViewer'] | ||
|
||
# %% ../nbs/03_file_viewer.ipynb 1 | ||
import ipywidgets as widgets | ||
from ipywidgets import VBox, HBox, HTML, Button, Label, Text, Checkbox, Accordion, FileUpload | ||
from IPython.display import display, clear_output | ||
import ipyvuetify as v | ||
from traitlets import observe | ||
from traitlets import observe, HasTraits, Unicode | ||
from ipyfilechooser import FileChooser | ||
|
||
# %% ../nbs/03_file_viewer.ipynb 2 | ||
class FileViewer(VBox): | ||
class FileViewerView(Accordion): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
|
||
self.file_upload = widgets.FileUpload( | ||
accept='', # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf' | ||
multiple=False # True to accept multiple files upload else False | ||
) | ||
self.file_browser = FileChooser() | ||
self.file_browser.sandbox_path = '.' | ||
self.file_browser.filter_pattern = ['*.pdf', '*.md'] | ||
self.file_browser.title = '<b>File Selector</b>' # Change the title (use '' to hide) | ||
|
||
# TODO: file_download | ||
|
||
# File viewer (hidden in accordion) | ||
self.file_viewer_accordion = Accordion(children=[HTML('File viewer content')]) | ||
self.file_viewer_accordion.selected_index = None # Hide the accordion content initially | ||
self.selected_index = None # Hide the accordion content initially | ||
self.titles = ('Course Files',) # this isn't working for some reason | ||
|
||
self.vbox = VBox() | ||
self.vbox.children = (self.file_upload, self.file_browser) # File viewer (hidden initially) | ||
|
||
self.children = (self.vbox, ) | ||
|
||
# Arrange widgets vertically | ||
self.children = [ | ||
self.file_viewer_accordion, # File viewer (hidden initially) | ||
] | ||
# %% ../nbs/03_file_viewer.ipynb 8 | ||
class FileModel(HasTraits): | ||
# Define a Unicode string trait | ||
select = Unicode() | ||
|
||
def save_content_from_upload(values): | ||
for value in values: | ||
with open(value['name'], "wb") as fp: | ||
fp.write(value['content']) | ||
|
||
# %% ../nbs/03_file_viewer.ipynb 10 | ||
class FileViewer(FileViewerView): | ||
|
||
def __init__(self, model): | ||
super().__init__() | ||
self.model = model | ||
self.file_browser.register_callback(self.observe_file_select) | ||
|
||
def observe_file_select(self, file_browser): | ||
# update download button with correct filepath | ||
# filepath stored in self.file_browser.selected | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/05_madlib.ipynb. | ||
|
||
# %% auto 0 | ||
__all__ = ['MadLibModel', 'MadLib'] | ||
|
||
# %% ../nbs/05_madlib.ipynb 1 | ||
import ipywidgets as widgets | ||
import traitlets | ||
from ipywidgets import Textarea, Text, Layout, HBox, Stack, Layout | ||
from traitlets import HasTraits | ||
import os | ||
|
||
# %% ../nbs/05_madlib.ipynb 2 | ||
class MadLibModel(object): | ||
def __init__(self, description, variables, template, **kwargs): | ||
self.description = description | ||
# two ways to save variables... | ||
for key, value in variables.items(): # ... as attributes | ||
setattr(self, key, value) | ||
self.variables = variables # ...or as a dictionary, ex. { 'input_text': 'value' } | ||
self.template = template # string: '{input_text}' | ||
|
||
# %% ../nbs/05_madlib.ipynb 5 | ||
class MadLib(HBox): | ||
|
||
def __init__(self, model, **kwargs): | ||
super().__init__() | ||
|
||
self.model = model | ||
self.variables = {} | ||
for i, (key, value) in enumerate(self.model.variables.items()): | ||
text = Text(description=self.model.description, style={'description_width': 'initial'}) | ||
self.variables[key] = text | ||
|
||
self.submit_button = widgets.Button( | ||
value=False, | ||
disabled=False, | ||
button_style='success', | ||
icon='arrow-circle-right' | ||
) | ||
self.submit_button.on_click(self.observe_submit_button) | ||
self.children = list(self.variables.values()) + [self.submit_button] | ||
|
||
def observe_submit_button(self, change): | ||
for key, value in self.variables.items(): | ||
setattr(self.model, key, value.value) |
Oops, something went wrong.