本文整理汇总了Python中bokeh.models.widgets.Button类的典型用法代码示例。如果您正苦于以下问题:Python Button类的具体用法?Python Button怎么用?Python Button使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, ut330):
self.ut330 = ut330
self.device_name = TextInput(title="Device name")
self.device_time = TextInput(title="Device time")
self.computer_time = TextInput(title="Computer time")
self.t_high = TextInput(title="High temperature alarm (C)")
self.t_low = TextInput(title="Low temperature alarm (C)")
self.h_high = TextInput(title="High humidity alarm (%RH)")
self.h_low = TextInput(title="Low humidity alarm (%RH)")
self.p_high = TextInput(title="High pressure alarm")
self.p_low = TextInput(title="Low pressure alarm")
self.sampling = TextInput(title="Sampling interval (s)")
self.overwrite_records = Select(title="Overwrite records",
options=['False', 'True'])
self.delay_start = Select(title="Delay start",
options=['No delay', 'Delay'])
self.delay = TextInput(title="Delay (s)")
self.power = TextInput(title="Battery power (%)")
self.readings = TextInput(title="Readings")
self.read_config = Button(label='Read config')
self.write_config = Button(label='Write config')
示例2: read_file_tab
def read_file_tab(self):
"""Lets the user choose a data file to read"""
# Drop down list
self.file_select = Select(name='Data files',
value='',
options=[],
title='Data files')
# Status text
self.file_status = Div(text='', width=self.page_width)
# Update the file_select and file_status controls with scan data
self.scan_folder()
# This line is here deliberately. The scan_folder would trigger
# the on-change function and we don't want that first time around.
self.file_select.on_change('value', self.file_changed)
# Re-scan button
file_rescan = Button(label="Rescan folder", button_type="success")
file_rescan.on_click(self.scan_folder)
# Layout
c = column(self.file_select,
self.file_status,
file_rescan)
return Panel(child=c, title="Read from file")
示例3: __init__
def __init__(self, ut330):
self.ut330 = ut330
self.source = ColumnDataSource(data=dict(ts=[], t=[], h=[]))
self.plot = figure(x_axis_type="datetime")
self.plot.title = "Temperature and humidity vs. time"
self.plot.line(x="ts",
y="t",
source=self.source,
color="blue",
legend="Temperature",
line_width=2)
self.plot.xaxis.axis_label = "Timestamp"
self.plot.yaxis.axis_label = "Temperature (C)"
self.plot.extra_y_ranges = {"humidity": Range1d(0, 100)}
self.plot.line(x="ts",
y="h",
source=self.source,
y_range_name="humidity",
color="green",
legend="Humidity",
line_width=2)
self.plot.add_layout(LinearAxis(y_range_name="humidity",
axis_label="Relative humidity (%)"),
'right')
self.read = Button(label='Read data')
self.delete = Button(label='Delete data')
示例4: mass_plotting
def mass_plotting(self, filename):
data_dict = self.data_generation(filename)
self.data_test(data_dict)
name_check = data_dict["gen_info"]["DATA FILES"]
attr_id = name_check[1][4][:-3] + "_" + name_check[2][2]
TOOLS="pan,wheel_zoom,box_zoom,reset, hover, previewsave"
figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log",
title = attr_id, tools = TOOLS)
figure_obj.yaxis.axis_label = data_dict["data"][0]["y_unit"]
figure_obj.xaxis.axis_label = data_dict["data"][0]["x_unit"]
hover = figure_obj.select(dict(type = HoverTool))
hover.tooltips=[("Value:", "$top")]
hist, edges = np.histogram(data_dict["data"][0]["y"], bins = data_dict["data"][0]["x"])
source = ColumnDataSource(data = dict(top = hist, left = edges[:-1], right = edges[1:],
x_unit = data_dict["data"][0]["x_unit"], y_unit = data_dict["data"][0]["y_unit"],
edges = edges))
#hist = figure_obj.Histogram(source )
figure_obj.quad(top = "top", bottom = 0, left = "left" , right = "right", source = source)
matplot_button = Button(label = "create matplotlib plot")
matplot_button.on_click(lambda source_list = source:
self.matplotlib_export_ms(source_list))
return Panel(child = hplot(figure_obj, matplot_button), title = attr_id)
示例5: button_print_page
def button_print_page():
"""Button to print currently displayed webpage to paper or pdf.
Notes
-----
* Available styles: 'default', 'primary', 'success', 'warning', 'danger'
"""
button = Button(label="Print this page", button_type="success")
button.callback = CustomJS(code="""print()""")
return widgetbox(button)
示例6: Offsets_Panel
class Offsets_Panel(object):
def __init__(self, ut330):
self.ut330 = ut330
self.t_current = TextInput(title="Temperature current")
self.h_current = TextInput(title="Humidity current")
self.p_current = TextInput(title="Pressure current")
self.t_offset = TextInput(title="Temperature offset")
self.h_offset = TextInput(title="Humidity offset")
self.p_offset = TextInput(title="Pressure offset")
self.read_offsets = Button(label='Read offsets')
self.write_offsets = Button(label='Write offsets')
def _layout_(self):
return VBox(HBox(self.t_current, self.t_offset, width=500),
HBox(self.h_current, self.h_offset, width=500),
HBox(self.p_current, self.p_offset, width=500),
HBox(self.read_offsets, self.write_offsets, width=500))
def panel(self):
return Panel(child=self._layout_(), title="Offsets")
def _read_(self):
offsets = self.ut330.read_offsets()
self.t_current.value = str(offsets['temperature'])
self.h_current.value = str(offsets['humidity'])
self.p_current.value = str(offsets['pressure'])
self.t_offset.value = str(offsets['temperature offset'])
self.h_offset.value = str(offsets['humidity offset'])
self.p_offset.value = str(offsets['pressure offset'])
def _write_(self):
offsets = {'temperature offset': float(self.t_offset.value),
'humidity offset': float(self.h_offset.value),
'pressure offset': float(self.p_offset.value)}
self.ut330.write_offsets(offsets)
def callbacks(self):
self.read_offsets.on_click(self._read_)
self.write_offsets.on_click(self._write_)
def device_read(self):
self._read_()
示例7: make_layout
def make_layout():
plot, source = make_plot()
columns = [
TableColumn(field="dates", title="Date", editor=DateEditor(), formatter=DateFormatter()),
TableColumn(field="downloads", title="Downloads", editor=IntEditor()),
]
data_table = DataTable(source=source, columns=columns, width=400, height=400, editable=True)
button = Button(label="Randomize data", button_type="success")
button.on_click(click_handler)
buttons = WidgetBox(children=[button],width=800)
column = Column(children=[buttons, plot, data_table])
return column
示例8: make_layout
def make_layout():
plot, source = make_plot()
columns = [
TableColumn(field="dates", title="Date"),
TableColumn(field="downloads", title="Downloads"),
]
data_table = DataTable(source=source, columns=columns, width=400, height=400)
button = Button(label="Randomize data", type="success")
button.on_click(click_handler)
buttons = VBox(children=[button])
vbox = VBox(children=[buttons, plot, data_table])
return vbox
示例9: button_save_table
def button_save_table(table):
"""Button to save selected data table as csv.
Notes
-----
* Does not work for column values containing tuples (like 'neighbors')
* Currently columns being saved are hard coded in the javascript callback
* Available styles: 'default', 'primary', 'success', 'warning', 'danger'
"""
button = Button(label="Download selected data", button_type="success")
button.callback = CustomJS(args=dict(source=table.source),
code=open(join(dirname(__file__),
"js/download_data.js")).read())
return widgetbox(button)
示例10: __init__
def __init__(self, ut330):
self.ut330 = ut330
self.t_current = TextInput(title="Temperature current")
self.h_current = TextInput(title="Humidity current")
self.p_current = TextInput(title="Pressure current")
self.t_offset = TextInput(title="Temperature offset")
self.h_offset = TextInput(title="Humidity offset")
self.p_offset = TextInput(title="Pressure offset")
self.read_offsets = Button(label='Read offsets')
self.write_offsets = Button(label='Write offsets')
示例11: print
print("checkbox_group_handler: %s" % active)
session.store_document(document)
def radio_group_handler(active):
print("radio_group_handler: %s" % active)
session.store_document(document)
def checkbox_button_group_handler(active):
print("checkbox_button_group_handler: %s" % active)
session.store_document(document)
def radio_button_group_handler(active):
print("radio_button_group_handler: %s" % active)
session.store_document(document)
button = Button(label="Push button", icon=Icon(name="check"), type="primary")
button.on_click(button_handler)
toggle = Toggle(label="Toggle button", type="success")
toggle.on_click(toggle_handler)
menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3", "item_3")]
dropdown = Dropdown(label="Dropdown button", type="warning", menu=menu)
dropdown.on_click(dropdown_handler)
menu = [("Item 1", "foo"), ("Item 2", "bar"), None, ("Item 3", "baz")]
split = Dropdown(label="Split button", type="danger", menu=menu, default_action="baz")
split.on_click(split_handler)
checkbox_group = CheckboxGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_group.on_click(checkbox_group_handler)
示例12: selection_plot
def selection_plot(response):
# Let's move these into a settings file somewhere?
# height/width could potentially be driven by the request?
# Include color data in the ColumnDataSource to allow for changing the color on
# the client side.
urls = [x[0] for x in response["pages"]]
xdata = [x[1] for x in response["pages"]]
ydata = [x[2] for x in response["pages"]]
tags = [x[3] for x in response["pages"]]
color = [colormap(x[0]) if x else colormap(None) for x in tags]
source = ColumnDataSource(
data=dict(
x=xdata,
y=ydata,
urls=urls,
tags=tags,
color=color,
)
)
# Callback code for CDS.
source.callback = CustomJS(code="""
var inds = cb_obj.get('selected')["1d"].indices;
var data = cb_obj.get('data');
BokehPlots.showPages(inds);
""")
# Create the figure with FIGURE_WIDTH and FIGURE_HEIGHT
p = figure(tools="hover", width=FIGURE_WIDTH,
toolbar_location=None, responsive=True, tags=["clusterPlot"])
# Ensure that the lasso only selects with mouseup, not mousemove.
p.add_tools(LassoSelectTool(select_every_mousemove=False))
# These turn off the x/y axis ticks
p.axis.visible = None
# These turn the major grid off
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
# Plot non-selected circles with a particular style using CIRCLE_SIZE and
# 'color' list
p.circle("x", "y", size=13, line_width=2, line_alpha=1,
line_color=None, fill_alpha=1, color='color', source=source,
name="urls")
nonselected_circle = Circle(fill_alpha=0.1, line_alpha=0.1, fill_color='color',
line_color='color')
renderer = p.select(name="urls")
renderer.nonselection_glyph = nonselected_circle
# Create buttons and their callbacks, use button_code string for callbacks.
button_code = """
event.preventDefault();
var inds = source.get('selected')["1d"].indices;
var data = source.get('data');
var selected = [];
tag = "%s";
for(var i = 0; i < inds.length; i++){
selected.push({
x: data.x[inds[i]],
y: data.y[inds[i]],
url: data.urls[inds[i]],
tags: data.tags[inds[i]],
selected: true,
possible: false,
});
data["color"][inds[i]] = "%s";
}
BokehPlots.updateTags(selected, tag, inds);
source.trigger("change");
"""
# Supply color with print formatting.
button1 = Button(label="Relevant", type="success")
button1.callback = CustomJS(args=dict(source=source),
code=button_code % ("Relevant", POSITIVE_COLOR))
button2 = Button(label="Irrelevant", type="success")
button2.callback = CustomJS(args=dict(source=source),
code=button_code % ("Irrelevant", NEGATIVE_COLOR))
button3 = Button(label="Neutral", type="success")
button3.callback = CustomJS(args=dict(source=source),
code=button_code % ("Neutral", NEUTRAL_COLOR))
# Adjust what attributes are displayed by the HoverTool
hover = p.select(dict(type=HoverTool))
hover.tooltips = [
("urls", "@urls"),
]
layout = vform(p, button1, button2, button3)
# Combine script and div into a single string.
plot_code = components(layout)
#.........这里部分代码省略.........
示例13: clear
t.patches(xs="xss", ys="yss", color="colors", source=session_source, line_width=0, alpha=1)
hover = t.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
("task type", "@tasktype"),
("#tasks", "@running_tasks"),
]
# Function that clears all checkboxes and calls checkbox to redraw the plots
def clear():
checkbox_group_p.active = []
checkbox("", "", "")
# Button to clear all checkboxes
clear_button = Button(label="clear all", width=20)
clear_button.on_click(clear)
# Function that sets all checkboxes and calls checkbox to redraw the plots
def select_all():
checkbox_group_p.active = [i for i in range(len(attributes[1:]))]
checkbox("", "", "")
# Button to select all checkboxes
all_button = Button(label="select all", width=20)
all_button.on_click(select_all)
layout = column(
#row(WidgetBox(dropdown, width=405, height=100), WidgetBox(width=500),WidgetBox(runID)),
row(WidgetBox(dropdown, width=410, height=100)),
row(runID, startTime),
示例14: import
from __future__ import print_function
from bokeh.util.browser import view
from bokeh.document import Document
from bokeh.embed import file_html
from bokeh.resources import INLINE
from bokeh.models import CustomJS, WidgetBox
from bokeh.models.widgets import (
Button, Toggle, Dropdown, CheckboxGroup, RadioGroup, CheckboxButtonGroup, RadioButtonGroup,
)
button = Button(label="Button (enabled) - has click event", button_type="primary")
button.js_on_click(CustomJS(code="console.log('button: click', this.toString())"))
button_disabled = Button(label="Button (disabled) - no click event", button_type="primary", disabled=True)
button_disabled.js_on_click(CustomJS(code="console.log('button_disabled: click', this.toString())"))
toggle_inactive = Toggle(label="Toggle button (initially inactive)", button_type="success")
toggle_inactive.js_on_click(CustomJS(code="console.log('toggle_inactive: ' + this.active, this.toString())"))
toggle_active = Toggle(label="Toggle button (initially active)", button_type="success", active=True)
toggle_active.js_on_click(CustomJS(code="console.log('toggle_active: ' + this.active, this.toString())"))
menu = [("Item 1", "item_1_value"), ("Item 2", "item_2_value"), None, ("Item 3", "item_3_value")]
dropdown = Dropdown(label="Dropdown button", button_type="warning", menu=menu)
dropdown.js_on_click(CustomJS(code="console.log('dropdown: ' + this.value, this.toString())"))
dropdown_disabled = Dropdown(label="Dropdown button (disabled)", button_type="warning", disabled=True, menu=menu)
dropdown_disabled.js_on_click(CustomJS(code="console.log('dropdown_disabled: ' + this.value, this.toString())"))
示例15: device_data_tab
def device_data_tab(self):
"""Reading device data"""
self.data_status = Div(text="", width=self.page_width)
data_connect = Button(label='Connect to UT330',
button_type="success")
data_read = Button(label='Read data',
button_type="success")
data_write = Button(label='Write data to disk',
button_type="success")
data_erase = Button(label='Erase data',
button_type="success")
data_disconnect = Button(label='Disconnect from UT330',
button_type="success")
data_connect.on_click(self.data_connect)
data_read.on_click(self.data_read)
data_write.on_click(self.data_write)
data_erase.on_click(self.data_erase)
data_disconnect.on_click(self.data_disconnect)
if self.device_connected:
self.data_status.text = ('UT330 device connected. The Read, '
'Write, Erase, and Disconnect buttons '
'will work.')
else:
self.data_status.text = ('UT330 device is <strong>NOT</strong> '
'connected. The '
'Read, Write, Erase, and Disconnect '
'buttons will <strong>not work</strong>. '
'Press the '
'Connect button if the UT330 is '
'connected on a USB port.')
# Layout
l = layout([[self.data_status],
[data_connect, data_disconnect],
[data_read, data_write, data_erase]],
width=self.page_width)
return Panel(child=l,
title="Read from device")