Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bokeh.io import output_file, show
- from bokeh.layouts import row, column, layout
- from bokeh.plotting import figure, curdoc
- from bokeh.layouts import widgetbox
- from bokeh.models import ColumnDataSource
- from bokeh.models.widgets import Button, RadioButtonGroup, Select, Slider, TextInput
- from bokeh.models.widgets import RadioGroup, CheckboxGroup, MultiSelect, Dropdown
- from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, Panel, Tabs
- from bokeh.models.widgets import Paragraph
- from bokeh.events import ButtonClick
- from bokeh.palettes import Spectral6
- from datetime import date
- from functools import partial
- from random import randint
- import string
- refresh = Button(label="Refresh")
- btnGroupTitle = RadioButtonGroup(name='title', labels=[
- "begins with...", "...contains...", "...ends with"], active=1)
- btnGroupDept = RadioButtonGroup(name='dept', labels=[
- "begins with...", "...contains...", "...ends with"], active=1)
- # down
- def onClick(idx=-1, name=None):
- print('onClick:', name, idx)
- refresh.on_click(partial(onClick, name='refresh'))
- btnGroupTitle.on_click(partial(onClick, name='Group Title'))
- btnGroupDept.on_click(partial(onClick, name='Group Dept'))
- # up
- paragraph = Paragraph(text="option")
- optionGroup = RadioGroup(labels=["and", "or"],
- active=0, width=100, inline=True)
- btnGroupLetters = RadioButtonGroup(
- labels=list(string.ascii_uppercase), active=-1)
- # down
- title_input = TextInput(value="", title="Title:", placeholder="contains....")
- dept_input = TextInput(value="", title="Department:",
- placeholder="contains....")
- def onChange(attr, old, new, name=None):
- print('onChange:{}:{}'.format(name, new))
- title_input.on_change('value', partial(onChange, name='Title Input'))
- dept_input.on_change('value', partial(onChange, name='Dept Input'))
- # up
- layout_query = layout(
- [
- [widgetbox(btnGroupLetters, width=1000)],
- [widgetbox(btnGroupTitle), widgetbox(btnGroupDept)],
- [widgetbox(title_input), widgetbox(
- paragraph, optionGroup, width=100), widgetbox(dept_input)],
- [widgetbox(refresh, width=100)],
- ]
- )
- # down
- columns = [
- TableColumn(field='id', title='Course ID'),
- TableColumn(field='title', title='Title'),
- TableColumn(field='dept', title='Department'),
- TableColumn(field='credit', title='Credit'),
- TableColumn(field='instructor', title='Instructor'),
- ]
- table_master = DataTable(source=ColumnDataSource(),
- columns=columns, width=800, height=200)
- data = dict(
- id=['CSC1001', 'CSC1002', 'MAT1001', 'ENG2001'],
- title=['Python Programming', 'Computataional Lab',
- 'Calculus I', 'English Essay'],
- dept=['SSE', 'SSE', 'SSE', 'HSS'],
- credit=[3, 1, 3, 3],
- instructor=['Prof. Huang', 'Kinley', 'Prof. Wang', 'Prof. Tyler']
- )
- table_master.source.data = data
- def onTableMasterSelect(attr, old, new):
- indices = new['1d']['indices']
- print(indices)
- id = table_master.source.data['id']
- title = table_master.source.data['title']
- credit = table_master.source.data['credit']
- instructor = table_master.source.data['instructor']
- dept = table_master.source.data['dept']
- for idx in indices:
- print('{} {} {} {} {}'.format(
- id[idx], title[idx], dept[idx], credit[idx], instructor[idx]))
- table_master.source.on_change('selected', onTableMasterSelect)
- # up
- x = list(range(11))
- y0 = x
- y1 = [10 - i for i in x]
- y2 = [abs(i - 5) for i in x]
- # create a new plot
- s1 = figure(plot_width=250, plot_height=250, title=None)
- s1.circle(x, y0, size=10, color="navy", alpha=0.5)
- # create another one
- s2 = figure(plot_width=250, plot_height=250, title=None)
- s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
- # create and another
- s3 = figure(plot_width=250, plot_height=250, title=None)
- s3.square(x, y2, size=10, color="olive", alpha=0.5)
- layout_chart = layout(
- [s1, s2],
- [s3]
- )
- tab1 = Panel(child=layout_query, title="Course Info")
- tab2 = Panel(child=layout_chart, title="Statistics")
- tabs = Tabs(tabs=[tab1, tab2])
- curdoc().add_root(tabs)
- show(tabs)
- attr = dict(
- server='10.20.213.10',
- database='csc1002',
- username='csc1002',
- password='csc1002',
- port=1433,
- driver='SQL Server'
- )
- conn_str = 'DRIVER={driver};' \
- 'SERVER={server};' \
- 'PORT={port};' \
- 'DATABASE={database};' \
- 'UID={username};' \
- 'PWD={password}'
- conn_str = conn_str.format(**attr)
- # try:
- # pyodbc.connect(conn_str)
- # except Exception as e:
- # print(e)
- # quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement