Ejemplo n.º 1
0
def instmenu_deact():
    """
    Removes the instructor menu from the Jupyter menu bar
    :return:
    """
    display(JS('deleteInstructorToolsMenu()'))
    print("Delete this cell after the menu has been removed.")
    pass
Ejemplo n.º 2
0
def ipynb_oauth_dance():

    _twitter = twitter.Twitter(auth=twitter.OAuth('', '', CONSUMER_KEY,
                                                  CONSUMER_SECRET),
                               format='',
                               api_version=None)

    oauth_token, oauth_token_secret = parse_oauth_tokens(
        _twitter.oauth.request_token(oauth_callback=oauth_callback))

    # Need to write these interim values out to a file to pick up on the callback from Twitter
    # that is handled by the web server in /oauth_helper
    write_token_file(OAUTH_FILE, oauth_token, oauth_token_secret)

    oauth_url = ('http://api.twitter.com/oauth/authorize?oauth_token=' +
                 oauth_token)

    # Tap the browser's native capabilities to access the web server through a new window to get
    # user authorization
    display(JS("window.open('%s')" % oauth_url))
Ejemplo n.º 3
0
def instmenu_act():
    """
    Adds the instructor menu to the Jupyter menu bar
    :return:
    """
    tempJSfile = open(
        os.path.join(mydir, 'javascript', 'InstructorToolsmnu.js'))
    tempscript = '<script type="text/javascript">'
    tempscript += tempJSfile.read() + '</script>'
    tempJSfile.close()
    display(HTML(tempscript))
    display(
        JS('JPSLUtils.createJPSLToolsMenu('
           ');InstructorTools.createInstructorToolsMenu();'))
    warnstr = "This cell should only contain `import InstructorTools`"
    warnstr += " as it will be deleted when the tools"
    warnstr += " are deactivated.\n\nWARNING: if you select the '!deactivate "
    warnstr += " permanently!' option to make a student worksheet, the menu "
    warnstr += "cannot be reactivated. Only use that option on a copy you "
    warnstr += "intend to pass out to students."
    print(warnstr)
    pass
Ejemplo n.º 4
0
 def collectclick(self, btn):
     if (btn.description == 'Start Collecting'):
         btn.description = 'Stop Collecting'
         btn.button_style = 'danger'
         btn.tooltip = 'Stop the data collection'
         # do not allow parameters to be reset after starting run.
         self.setupbtn.disabled = True
         self.setupbtn.tooltip = 'Parameters locked. The run has started.'
         self.rateinp.disabled = True
         self.timelbl.disabled = True
         thread = threading.Thread(target=self.updatingplot, args=())
         thread.start()
         # self.updatingplot() hangs up user interface
     else:
         btn.description = 'Done'
         btn.button_style = ''
         btn.tooltip = ''
         time.sleep(3)  # wait a few seconds for end of data collection
         self.data = data
         self.timestamp = timestamp
         self.stdev = stdev
         self.fillpandadf()
         # save data to csv file so can be loaded elsewhere.
         svname = self.title + '_' + time.strftime(
             '%y-%m-%d_%H%M%S', time.localtime()) + '.csv'
         self.pandadf.to_csv(svname)
         self.collectbtn.close()
         del self.collectbtn
         #display(self.collecttxt)
         display(
             HTML(
                 '<span style="color:blue;font-weight:bold;">DATA SAVED TO:'
                 + svname + '</span>'))
         # Save the notebook with current widget states (plotly plots).
         jscode = 'Jupyter.actions.call(' \
                  '"widgets:save-with-widgets");'
         display(JS(jscode))
Ejemplo n.º 5
0
######
# Interactive elements definitions
######

# Locate JupyterPiDAQ package directory
mydir = os.path.dirname(
    __file__)  # absolute path to directory containing this file.

# Add a "DAQ Menu" to the notebook.
tempJSfile = open(os.path.join(mydir, 'javascript', 'JupyterPiDAQmnu.js'))
tempscript = '<script type="text/javascript">'
tempscript += tempJSfile.read() + '</script>'
tempJSfile.close()
display(HTML(tempscript))
display(JS('createCmdMenu()'))

print('Done with setup.')

# cleanup log file if it is empty
logging.shutdown()
try:
    if os.stat(logname).st_size == 0:
        os.remove(logname)
except FileNotFoundError:
    pass


# Data Aquistion Instance (a run).
class DAQinstance():
    def __init__(self, idno, livefig, title='None', ntraces=4, **kwargs):
Ejemplo n.º 6
0
def access_token_capture():
    access_token = request.args.get('access_token')
    f = open(OAUTH_FILE, 'w')  # Store the code as a file
    f.write(access_token)
    f.close()

    # It is safe (and convenient) to shut down the web server after this request
    shutdown_after_request = request.environ.get('werkzeug.server.shutdown')
    shutdown_after_request()
    return access_token


# Send an OAuth request to Facebook, handle the redirect, and display the access
# token that's included in the redirect for the user to copy and paste

args = dict(client_id=APP_ID,
            redirect_uri=REDIRECT_URI,
            scope=','.join(EXTENDED_PERMS),
            type='user_agent',
            display='popup')

oauth_url = 'https://facebook.com/dialog/oauth?' + urllib.parse.urlencode(args)

Timer(1, lambda: display(JS("window.open('%s')" % oauth_url))).start()

webserver.run(host='0.0.0.0')

access_token = open(OAUTH_FILE).read()

print(access_token)