Advertisement
Guest User

csc1002

a guest
Apr 14th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.67 KB | None | 0 0
  1. from bokeh.io import output_file, show
  2. from bokeh.layouts import row, column, layout
  3. from bokeh.plotting import figure, curdoc
  4. from bokeh.layouts import widgetbox
  5. from bokeh.models import ColumnDataSource
  6. from bokeh.models.widgets import Button, RadioButtonGroup, Select, Slider, TextInput
  7. from bokeh.models.widgets import RadioGroup, CheckboxGroup, MultiSelect, Dropdown
  8. from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, Panel, Tabs
  9. from bokeh.models.widgets import Paragraph
  10. from bokeh.events import ButtonClick
  11. from bokeh.palettes import Spectral6
  12. from datetime import date
  13. from functools import partial
  14. from random import randint
  15. import string
  16.  
  17.  
  18. refresh = Button(label="Refresh")
  19. btnGroupTitle = RadioButtonGroup(name='title', labels=[
  20.                                  "begins with...", "...contains...", "...ends with"], active=1)
  21. btnGroupDept = RadioButtonGroup(name='dept', labels=[
  22.                                 "begins with...", "...contains...", "...ends with"], active=1)
  23.  
  24.  
  25. # down
  26. def onClick(idx=-1, name=None):
  27.     print('onClick:', name, idx)
  28.  
  29.  
  30. refresh.on_click(partial(onClick, name='refresh'))
  31. btnGroupTitle.on_click(partial(onClick, name='Group Title'))
  32. btnGroupDept.on_click(partial(onClick, name='Group Dept'))
  33. # up
  34.  
  35. paragraph = Paragraph(text="option")
  36. optionGroup = RadioGroup(labels=["and", "or"],
  37.                          active=0, width=100, inline=True)
  38. btnGroupLetters = RadioButtonGroup(
  39.     labels=list(string.ascii_uppercase), active=-1)
  40.  
  41. # down
  42.  
  43. title_input = TextInput(value="", title="Title:", placeholder="contains....")
  44. dept_input = TextInput(value="", title="Department:",
  45.                        placeholder="contains....")
  46.  
  47.  
  48. def onChange(attr, old, new, name=None):
  49.     print('onChange:{}:{}'.format(name, new))
  50.  
  51.  
  52. title_input.on_change('value', partial(onChange, name='Title Input'))
  53. dept_input.on_change('value', partial(onChange, name='Dept Input'))
  54.  
  55. # up
  56.  
  57.  
  58. layout_query = layout(
  59.     [
  60.         [widgetbox(btnGroupLetters, width=1000)],
  61.         [widgetbox(btnGroupTitle), widgetbox(btnGroupDept)],
  62.         [widgetbox(title_input), widgetbox(
  63.             paragraph, optionGroup, width=100), widgetbox(dept_input)],
  64.         [widgetbox(refresh, width=100)],
  65.     ]
  66. )
  67.  
  68. # down
  69. columns = [
  70.     TableColumn(field='id', title='Course ID'),
  71.     TableColumn(field='title', title='Title'),
  72.     TableColumn(field='dept', title='Department'),
  73.     TableColumn(field='credit', title='Credit'),
  74.     TableColumn(field='instructor', title='Instructor'),
  75. ]
  76. table_master = DataTable(source=ColumnDataSource(),
  77.                          columns=columns, width=800, height=200)
  78. data = dict(
  79.     id=['CSC1001', 'CSC1002', 'MAT1001', 'ENG2001'],
  80.     title=['Python Programming', 'Computataional Lab',
  81.            'Calculus I', 'English Essay'],
  82.     dept=['SSE', 'SSE', 'SSE', 'HSS'],
  83.     credit=[3, 1, 3, 3],
  84.     instructor=['Prof. Huang', 'Kinley', 'Prof. Wang', 'Prof. Tyler']
  85. )
  86.  
  87. table_master.source.data = data
  88.  
  89.  
  90. def onTableMasterSelect(attr, old, new):
  91.     indices = new['1d']['indices']
  92.     print(indices)
  93.     id = table_master.source.data['id']
  94.     title = table_master.source.data['title']
  95.     credit = table_master.source.data['credit']
  96.     instructor = table_master.source.data['instructor']
  97.     dept = table_master.source.data['dept']
  98.     for idx in indices:
  99.         print('{} {} {} {} {}'.format(
  100.             id[idx], title[idx], dept[idx], credit[idx], instructor[idx]))
  101.  
  102.  
  103. table_master.source.on_change('selected', onTableMasterSelect)
  104. # up
  105.  
  106. x = list(range(11))
  107. y0 = x
  108. y1 = [10 - i for i in x]
  109. y2 = [abs(i - 5) for i in x]
  110.  
  111. # create a new plot
  112. s1 = figure(plot_width=250, plot_height=250, title=None)
  113. s1.circle(x, y0, size=10, color="navy", alpha=0.5)
  114.  
  115. # create another one
  116. s2 = figure(plot_width=250, plot_height=250, title=None)
  117. s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
  118.  
  119. # create and another
  120. s3 = figure(plot_width=250, plot_height=250, title=None)
  121. s3.square(x, y2, size=10, color="olive", alpha=0.5)
  122.  
  123.  
  124. layout_chart = layout(
  125.     [s1, s2],
  126.     [s3]
  127. )
  128.  
  129. tab1 = Panel(child=layout_query, title="Course Info")
  130. tab2 = Panel(child=layout_chart, title="Statistics")
  131. tabs = Tabs(tabs=[tab1, tab2])
  132.  
  133. curdoc().add_root(tabs)
  134. show(tabs)
  135. attr = dict(
  136.     server='10.20.213.10',
  137.     database='csc1002',
  138.     username='csc1002',
  139.     password='csc1002',
  140.     port=1433,
  141.     driver='SQL Server'
  142. )
  143.  
  144. conn_str = 'DRIVER={driver};' \
  145.     'SERVER={server};' \
  146.     'PORT={port};' \
  147.     'DATABASE={database};' \
  148.     'UID={username};' \
  149.     'PWD={password}'
  150.  
  151. conn_str = conn_str.format(**attr)
  152. # try:
  153. #      pyodbc.connect(conn_str)
  154. # except Exception as e:
  155. #     print(e)
  156. #     quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement