def _add_auto_new_question_gui(self, box):
hbox = gu.bHBox(box, False)
hbox.set_spacing(gu.PAD_SMALL)
adj = Gtk.Adjustment(0, 0, 10, 0.1, 1)
spin = gu.nSpinButton(self.m_exname, 'seconds_before_new_question',
adj)
spin.set_digits(1)
label = Gtk.Label(label=_("Delay (seconds):"))
label.show()
def f(button, spin=spin, label=label):
spin.set_sensitive(button.get_active())
label.set_sensitive(button.get_active())
b = gu.nCheckButton(self.m_exname, 'new_question_automatically',
_("_New question automatically."), callback=f)
hbox.pack_start(b, False, False, 0)
label.set_sensitive(b.get_active())
hbox.pack_start(label, False, False, 0)
spin.set_sensitive(b.get_active())
hbox.pack_start(spin, False, False, 0)
python类Adjustment()的实例源码
def add_select_num_beats_gui(self):
###
hbox = Gtk.HBox()
hbox.set_spacing(gu.hig.SPACE_SMALL)
label = Gtk.Label(label=_("Number of beats in question:"))
hbox.pack_start(label, False, False, 0)
self.config_box_sizegroup.add_widget(label)
label.set_alignment(1.0, 0.5)
hbox.pack_start(gu.nSpinButton(self.m_exname, "num_beats",
Gtk.Adjustment(4, 1, 100, 1, 10)), False, False, 0)
self.config_box.pack_start(hbox, False, False, 0)
hbox.show_all()
#
hbox = Gtk.HBox()
hbox.set_spacing(gu.hig.SPACE_SMALL)
label = Gtk.Label(label=_("Count in before question:"))
hbox.pack_start(label, False, False, 0)
self.config_box_sizegroup.add_widget(label)
label.set_alignment(1.0, 0.5)
hbox.pack_start(gu.nSpinButton(self.m_exname, "count_in",
Gtk.Adjustment(2, 0, 10, 1, 10)), False, False, 0)
hbox.show_all()
self.config_box.pack_start(hbox, False, False, 0)
def on_fontsize_adjustment_value_changed(self, adjustment):
'''
The fontsize adjustment in the header bar has been changed
:param adjustment: The adjustment used to change the fontsize
:type adjustment: Gtk.Adjustment object
'''
value = adjustment.get_value()
if _ARGS.debug:
sys.stdout.write(
'on_fontsize_adjustment_value_changed() value = %s\n'
%value)
self._fontsize = value
self._save_options()
self._busy_start()
GLib.idle_add(self._change_flowbox_font)
def _do_vadjustment_value_changed(self, vadj: Gtk.Adjustment):
"""Handler for when the GtkAdjustment's value is changed.
Emits `nvim-vscrolled` if the widget is not in the middle of an
update and the bounds are still valid, i.e. not changed automatically
by GTK.
:vadj: the adjustment.
"""
if not self.props.updating and vadj.get_upper() == 1.0:
v = vadj.get_value()
v = v if v == 0.0 else v + vadj.get_page_size()
self.emit('nvim-vscrolled', int(v * self.props.lines))
def gui():
"""Start the graphical user interface."""
try:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
except ImportError:
print("Sorry, this needs pygobject to be installed!")
sys.exit()
win = Gtk.Window(title="Set display brightness")
ad1 = Gtk.Adjustment(value=get_actual_brightness(), lower=11, upper=255)
scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=ad1)
def on_scale_changed(s, _):
value = int(s.get_value())
set_brightness(value)
scale.connect("button-release-event", on_scale_changed)
scale.connect("key_release_event", on_scale_changed)
scale.connect("scroll-event", on_scale_changed)
scale.set_size_request(350, 50)
# Main Container
main_container = Gtk.Fixed()
main_container.put(scale, 10, 10)
# Main Window
win.connect("delete-event", Gtk.main_quit)
win.connect("destroy", Gtk.main_quit)
win.add(main_container)
win.resize(400, 50)
win.set_position(Gtk.WindowPosition.CENTER)
win.show_all()
Gtk.main()
def on_num_int_spin(self, _o):
adj = Gtk.Adjustment(self.get_int('cur_edit_interval'), 1,
self.get_int('number_of_intervals'), 1, self.MAX_INT)
self.g_int_sel_spin.set_adjustment(adj)
self.g_int_sel_spin.update()
def add_select_num_notes_gui(self):
hbox = Gtk.HBox()
hbox.set_spacing(gu.hig.SPACE_SMALL)
label = Gtk.Label(label=_("Number of tones:"))
hbox.pack_start(label, False, False, 0)
self.config_box_sizegroup.add_widget(label)
label.set_alignment(1.0, 0.5)
hbox.pack_start(gu.nSpinButton(self.m_exname, "num_notes",
Gtk.Adjustment(4, 1, 100, 1, 10)), False, False, 0)
self.config_box.pack_start(hbox, False, False, 0)
hbox.show_all()
self.config_box.pack_start(hbox, False, False, 0)
def tSpinButton(table, x1, x2, y1, y2,
value, lower, upper, step_incr=1, page_incr=10, callback=None):
adj = Gtk.Adjustment(value, lower, upper, step_incr, page_incr)
spin = Gtk.SpinButton(adj, digits=0)
if callback:
spin.connect('value-changed', callback)
table.attach(spin, x1, x2, y1, y2)
return spin
def __init__(self, value):
#
Gtk.Dialog.__init__(self,
'Backlight Indicator | ' + _('Set backlight'),
None,
Gtk.DialogFlags.MODAL |
Gtk.DialogFlags.DESTROY_WITH_PARENT,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.connect('close', self.close_ok)
self.set_icon_from_file(comun.ICON)
#
vbox0 = Gtk.VBox(spacing=5)
vbox0.set_border_width(5)
self.get_content_area().add(vbox0)
frame0 = Gtk.Frame()
vbox0.pack_start(frame0, False, True, 1)
table0 = Gtk.Table(2, 2, False)
frame0.add(table0)
label23 = Gtk.Label(_('Backlight') + ':')
label23.set_alignment(0, 0.5)
table0.attach(label23, 0, 1, 0, 1,
xpadding=5, ypadding=5)
configuration = Configuration()
minimum_backlight = configuration.get('minimum-backlight')
maximum_backlight = configuration.get('maximum-backlight')
ba = BacklightManager()
backlight = ba.get_backlight()
adjustment3 = Gtk.Adjustment(backlight,
minimum_backlight,
maximum_backlight, 5, 10, 1)
self.backlight = Gtk.Scale()
self.backlight.set_digits(0)
self.backlight.set_size_request(200, 10)
self.backlight.set_adjustment(adjustment3)
table0.attach(self.backlight, 1, 2, 0, 1,
xpadding=5, ypadding=5)
self.backlight.set_value(value)
self.show_all()
def __init__(self, digits=0, start=0, lower=-999999, upper=999999, increment=1,
change_handler=None):
# beware: the default values for lower/upper are both zero
adjustment = gtk.Adjustment(value=start, lower=lower, upper=upper, step_incr=increment)
self.control = gtk.SpinButton.new(adjustment, climb_rate=1, digits=digits)
self.control.set_value(start)
self.connect("value-changed", change_handler)
def add_spin(self, label, key, adjust_props={}, spin_props={}, type_=int):
def on_changed(spin):
value = None
if type_ is int:
value = spin.get_value_as_int()
else:
value = spin.get_value()
self._settings[key] = value
adjust_default = {
'lower': 0,
'upper': 100,
'step_increment': 1
}
adjustment = Gtk.Adjustment()
adjustment.set_lower(
adjust_props.get('lower', adjust_default['lower'])
)
adjustment.set_upper(
adjust_props.get('upper', adjust_default['upper'])
)
adjustment.set_step_increment(
adjust_props.get('step_increment', adjust_default['step_increment'])
)
spin_button = Gtk.SpinButton()
spin_button.set_adjustment(adjustment)
spin_button.set_numeric(True)
spin_button.set_snap_to_ticks(True)
spin_button.set_value(self._settings[key])
spin_button.connect('value-changed', on_changed)
if type_ is float:
spin_button.set_digits(2)
return self.add_row(label, spin_button, True)
def build_data_stores(self):
"""Build stores for GUI dataviews"""
self.store = dict()
# custom icons
self.ied = {'Name': 0, 'State': 1}
self.store['custom_icons'] = Gtk.ListStore(str, bool)
self.store['custom_icons'].append(["Simple Icon Group", False])
renderer_toggle = Gtk.CellRendererToggle()
renderer_toggle.connect("toggled", self.on_custom_icon_toggled)
self.gui['custom_icons_treeview'].append_column(Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0))
self.gui['custom_icons_treeview'].append_column(Gtk.TreeViewColumn("State", renderer_toggle, active=1))
self.gui['custom_icons_treeview'].set_model(self.store['custom_icons'])
# color list
self.ced = {'Color': 0, 'Alpha': 1, 'Offset': 2, 'RGBA': 3}
colorstore_visible_keys = [k for k in self.ced.keys() if k != 'RGBA']
self.store['colorlist'] = Gtk.ListStore(str, float, int, str)
for key in sorted(colorstore_visible_keys, key=lambda k: self.ced[k]):
self.gui['colorlist_treeview'].append_column(
Gtk.TreeViewColumn(key, Gtk.CellRendererText(), text=self.ced[key])
)
self.gui['colorlist_treeview'].set_model(self.store['colorlist'])
# gradient direction
self.ded = {'Coord': 0, 'Value': 1}
self.store['direction'] = Gtk.ListStore(str, int)
self.gui['renderer_spin'] = Gtk.CellRendererSpin(editable=True, adjustment=Gtk.Adjustment(0, 0, 100, 5, 0, 0))
self.signals['direction_edited'] = self.gui['renderer_spin'].connect("edited", self.on_direction_edited)
self.gui['direction_treeview'].append_column(Gtk.TreeViewColumn("Coord", Gtk.CellRendererText(), text=0))
self.gui['direction_treeview'].append_column(Gtk.TreeViewColumn("Value", self.gui['renderer_spin'], text=1))
self.gui['direction_treeview'].set_model(self.store['direction'])
def __init__(self, keyfile, settings, key, min_value, max_value):
self.key = key
self.keyfile = keyfile
try:
self.value = keyfile.get_integer(GROUP_NAME, key)
except:
self.value = settings.get_int(key)
Gtk.SpinButton.__init__(self)
adjustment = Gtk.Adjustment(self.value, min_value, max_value, 1, 10, 0)
self.set_adjustment(adjustment)
self.set_value(self.value)
self.connect("value-changed", self.on_value_changed)
SBrickMotorChannelBox.py 文件源码
项目:sbrick-controller
作者: wintersandroid
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def __init__(self, channel, sbrick_channel):
Gtk.Frame.__init__(self)
self.sbrickChannel = sbrick_channel
self.channel = channel
self.sbrick = None
self.set_label("Channel: %d - %s" % ((channel + 1), self.sbrickChannel["name"]))
self.vbox = Gtk.FlowBox() # , orientation=Gtk.Orientation.HORIZONTAL, spacing=3)
self.vbox.set_border_width(2)
self.vbox.set_max_children_per_line(7)
self.vbox.set_min_children_per_line(7)
self.vbox.set_selection_mode(Gtk.SelectionMode.NONE)
self.add(self.vbox)
# self.vbox.pack_start(Gtk.Label("PWM: "), True, False, 0)
self.vbox.add(Gtk.Label("PWM: "))
self.pwmAdjustment = Gtk.Adjustment(255, 0, 255, 5, 10, 0.0)
self.spinPWM = Gtk.SpinButton.new(self.pwmAdjustment, 5, 0)
# self.vbox.pack_start(self.spinPWM, True, False, 0)
self.vbox.add(self.spinPWM)
self.pwmAdjustment.connect("value-changed", self.on_pwm_changed)
self.checkReverse = Gtk.CheckButton("Reverse")
self.checkReverse.connect("toggled", self.on_reverse_changed)
self.vbox.add(self.checkReverse)
# self.vbox.pack_start(self.checkReverse, True, False, 0)
self.checkTime = Gtk.CheckButton("Time MS:")
# self.vbox.pack_start(self.checkTime, True, False, 0)
self.vbox.add(self.checkTime)
self.checkTime.connect("toggled", self.on_time_toggled)
self.timeAdjustment = Gtk.Adjustment(1000, -1, 30000, 100, 1000, 0.0)
self.spinTime = Gtk.SpinButton.new(self.timeAdjustment, 10, 0)
# self.vbox.pack_start(self.spinTime, True, False, 0)
self.vbox.add(self.spinTime)
self.spinTime.set_sensitive(False)
self.checkBrake = Gtk.CheckButton("Break Stop")
# self.vbox.pack_start(self.checkBrake, True, False, 0)
self.vbox.add(self.checkBrake)
self.buttonGo = Gtk.Button("Start")
self.buttonGo.connect("clicked", self.on_switch_go_clicked)
# self.vbox.pack_start(self.buttonGo, True, False, 0)
self.vbox.add(self.buttonGo)
self.set_sensitive(False)
self.on = False
self.pwm = 0
self.reverse = False
# noinspection PyUnusedLocal
def __init__(self, step_configuration, functions):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
self.set_homogeneous(False)
self.step_configuration = step_configuration
self.functions = functions
self.sbrick = None
self.show_all()
self.function_group_model = Gtk.ListStore(str, str)
self.function_model = Gtk.ListStore(str, str)
# function group
self.pack_start(Gtk.Label("Function Group:"), False, True, 0)
self.combo_function_group = Gtk.ComboBoxText()
self.combo_function_group.set_id_column(0)
self.combo_function_group.set_model(self.function_group_model)
renderer_text = Gtk.CellRendererText()
self.combo_function_group.clear()
self.combo_function_group.pack_start(renderer_text, True)
self.combo_function_group.add_attribute(renderer_text, "text", 1)
self.pack_start(self.combo_function_group, False, True, 0)
self.combo_function_group.connect("changed", self.on_group_changed)
# function group
self.add(Gtk.Label("Function:"))
self.combo_function = Gtk.ComboBoxText()
self.combo_function.set_id_column(0)
self.combo_function.set_model(self.function_model)
renderer_text = Gtk.CellRendererText()
self.combo_function.clear()
self.combo_function.pack_start(renderer_text, True)
self.combo_function.add_attribute(renderer_text, "text", 1)
self.pack_start(self.combo_function, False, True, 0)
self.pack_start(Gtk.Label("MS Delay After:"), False, True, 0)
self.timeAdjustment = Gtk.Adjustment(1000, -1, 120000, 10, 100, 0.0)
self.spinDelayAfter = Gtk.SpinButton.new(self.timeAdjustment, 10, 0)
self.pack_start(self.spinDelayAfter, False, True, 0)
self.update_group_model()
if "function_group" in self.step_configuration:
self.combo_function_group.set_active_id(self.step_configuration["function_group"])
self.update_function_model(self.combo_function_group.get_active_id())
if "function" in self.step_configuration:
self.combo_function.set_active_id(self.step_configuration["function"])
if "delay_time" in self.step_configuration:
self.timeAdjustment.set_value(int(step_configuration["delay_time"]))
def __init__(self, teacher):
abstract.Gui.__init__(self, teacher)
self.m_key_bindings = {'backspace_ak': self.on_backspace}
self.g_answer_box = gu.NewLineBox()
self.practise_box.pack_start(self.g_answer_box, False, False, 0)
#-------
hbox = gu.bHBox(self.practise_box)
b = Gtk.Button(_("Play"))
b.show()
b.connect('clicked', self.play_users_answer)
hbox.pack_start(b, False, True, 0)
self.practise_box.pack_start(Gtk.HBox(False, 0), False, False,
padding=gu.PAD_SMALL)
self.g_rhythm_viewer = RhythmViewer(self)
#FIXME the value 52 is dependant on the theme used
self.g_rhythm_viewer.set_size_request(-1, 52)
self.g_rhythm_viewer.create_holders()
hbox.pack_start(self.g_rhythm_viewer, True, True, 0)
# action area
self.std_buttons_add(
('new', self.new_question),
('repeat', self.repeat_question),
('give_up', self.give_up),
('backspace', self.on_backspace))
self.practise_box.show_all()
##############
# config_box #
##############
self.add_select_elements_gui()
#--------
self.config_box.pack_start(Gtk.HBox(False, 0), False, False,
padding=gu.PAD_SMALL)
self.add_select_num_beats_gui()
#-----
self.config_box.pack_start(Gtk.HBox(False, 0), False, False,
padding=gu.PAD_SMALL)
#------
hbox = gu.bHBox(self.config_box, False)
hbox.set_spacing(gu.PAD_SMALL)
hbox.pack_start(gu.nCheckButton(self.m_exname,
"not_start_with_rest",
_("Don't start the question with a rest")), False, False, 0)
sep = Gtk.VSeparator()
hbox.pack_start(sep, False, False, 0)
hbox.pack_start(Gtk.Label(_("Beats per minute:")), False, False, 0)
spin = gu.nSpinButton(self.m_exname, 'bpm',
Gtk.Adjustment(60, 20, 240, 1, 10))
hbox.pack_start(spin, False, False, 0)
self._add_auto_new_question_gui(self.config_box)
self.config_box.show_all()
def __init__(self, teacher):
abstract.Gui.__init__(self, teacher)
self.m_key_bindings = {'backspace_ak': self.on_backspace}
self.g_answer_box = Gtk.VBox()
self.answer_buttons = []
self.m_answer_buttons = {}
#-------
hbox = gu.bHBox(self.practise_box)
b = Gtk.Button(_("Play"))
b.show()
b.connect('clicked', self.play_users_answer)
hbox.pack_start(b, False, True, 0)
self.practise_box.pack_start(Gtk.HBox(), False, False,
padding=gu.PAD_SMALL)
self.g_rhythm_viewer = RhythmViewer(self)
self.g_rhythm_viewer.create_holders()
hbox.pack_start(self.g_rhythm_viewer, True, True, 0)
self.practise_box.pack_start(self.g_answer_box, False, False, 0)
# action area
self.std_buttons_add(
('new', self.new_question),
('repeat', self.repeat_question),
#('play_answer', self.play_users_answer),
('give_up', self.give_up),
('backspace', self.on_backspace))
self.practise_box.show_all()
##############
# config_box #
##############
self.add_select_elements_gui()
#--------
self.config_box.pack_start(Gtk.HBox(), False, False,
padding=gu.PAD_SMALL)
self.add_select_num_notes_gui()
#-----
self.config_box.pack_start(Gtk.HBox(), False, False,
padding=gu.PAD_SMALL)
#------
hbox = gu.bHBox(self.config_box, False)
hbox.set_spacing(gu.PAD_SMALL)
hbox.pack_start(Gtk.Label(_("Beats per minute:")), False, False, 0)
spin = gu.nSpinButton(self.m_exname, 'bpm',
Gtk.Adjustment(60, 20, 240, 1, 10))
hbox.pack_start(spin, False, False, 0)
hbox = gu.bHBox(self.config_box, False)
hbox.set_spacing(gu.PAD_SMALL)
hbox.pack_start(gu.nCheckButton(self.m_exname,
"show_first_note",
_("Show the first tone")), False, False, 0)
hbox.pack_start(gu.nCheckButton(self.m_exname,
"play_cadence",
_("Play cadence")), False, False, 0)
self._add_auto_new_question_gui(self.config_box)
self.config_box.show_all()
def create_midi_config(self):
it, page_vbox = self.new_page_box(None, _("Instruments"))
vbox, category_vbox = gu.hig_category_vbox(_("Tempo"))
page_vbox.pack_start(vbox, False, False, 0)
sizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
tempo_hbox = Gtk.Box(spacing=6)
self.g_default_bpm = gu.nSpinButton('config', 'default_bpm',
Gtk.Adjustment(self.get_int('config/default_bpm'), 10, 500, 1, 10))
self.g_arpeggio_bpm = gu.nSpinButton('config', 'arpeggio_bpm',
Gtk.Adjustment(self.get_int('config/arpeggio_bpm'), 10, 500, 1, 10))
for text, widget in [(_("_Default:") ,self.g_default_bpm),
(_("A_rpeggio:") ,self.g_arpeggio_bpm)]:
label = Gtk.Label(_("BPM"))
tempo_hbox.pack_start(
gu.hig_label_widget(text, [widget, label], None),
False, False, 0)
label.set_tooltip_text(_("Beats per minute"))
category_vbox.pack_start(tempo_hbox, False, False, 0)
box, category_vbox = gu.hig_category_vbox(_("Preferred Instrument"))
page_vbox.pack_start(box, False, False, 0)
self.g_instrsel = nInstrumentSelector('config',
'preferred_instrument', None)
category_vbox.pack_start(self.g_instrsel, False, False, 0)
box, category_vbox = gu.hig_category_vbox(_("Chord Instruments"))
page_vbox.pack_start(box, False, False, 0)
self.g_instrument_configurator \
= InstrumentConfigurator("config", 3,
_("Use different instruments for chords and harmonic intervals"))
category_vbox.pack_start(self.g_instrument_configurator, False, False, 0)
vbox, category_box = gu.hig_category_vbox(_("Percussion Instruments"))
page_vbox.pack_start(vbox, False, False, 0)
category_box.pack_start(gu.hig_label_widget(
_("Count in:"),
gu.PercussionNameButton("config", "countin_perc", "Claves"),
sizegroup, True, True), True, True, 0)
category_box.pack_start(gu.hig_label_widget(
_("Rhythm:"),
gu.PercussionNameButton("config", "rhythm_perc", "Side Stick"),
sizegroup, True, True), False, False, 0)
def __init__(self, mainapp):
self._mainapp = mainapp
elements = (
"mainbox", "restart_button", "bars_spinbutton", "sensitivity_spinbutton", "framerate_spinbutton",
"lower_cutoff_freq_spinbutton", "higher_cutoff_freq_spinbutton", "gravity_spinbutton",
"integral_spinbutton", "ignore_spinbutton", "monstercat_switch", "autosens_switch", "style_combobox",
"eq_treeview",
)
super().__init__("cavaset.glade", elements)
# some gui constants
self.OUTPUT_STYLE = ("mono", "stereo")
self.EQ_STORE = AttributeDict(LABEL=0, VALUE=1)
# setup base elements
self.gui["restart_button"].connect("clicked", self.on_restart_button_click)
self.int_sp_buttons = (
("general", "framerate"), ("general", "bars"), ("general", "sensitivity"),
("general", "higher_cutoff_freq"), ("general", "lower_cutoff_freq"), ("smoothing", "ignore")
)
self.float_sp_buttons = (("smoothing", "integral"), ("smoothing", "gravity"))
self.bool_switches = (("smoothing", "monstercat"), ("general", "autosens"))
for section, key in self.int_sp_buttons + self.float_sp_buttons:
self.gui[key + "_spinbutton"].set_value(self._mainapp.cavaconfig[section][key])
for section, key in self.bool_switches:
self.gui[key + "_switch"].set_active(self._mainapp.cavaconfig[section][key])
self.gui["style_combobox"].set_active(self.OUTPUT_STYLE.index(self._mainapp.cavaconfig["output"]["style"]))
# setup equalizer
self.eq_store = Gtk.ListStore(str, float)
self.gui['renderer_spin'] = Gtk.CellRendererSpin(
digits=2, editable=True, adjustment=Gtk.Adjustment(1, 0.1, 1, 0.1, 0, 0)
)
self.gui['renderer_spin'].connect("edited", self.on_eq_edited)
column1 = Gtk.TreeViewColumn("Frequency Bands", Gtk.CellRendererText(), text=self.EQ_STORE.LABEL)
column1.set_expand(True)
column2 = Gtk.TreeViewColumn("Value", self.gui['renderer_spin'], text=self.EQ_STORE.VALUE)
column2.set_min_width(200)
self.gui['eq_treeview'].append_column(column1)
self.gui['eq_treeview'].append_column(column2)
self.gui['eq_treeview'].set_model(self.eq_store)
for i, value in enumerate(self._mainapp.cavaconfig["eq"]):
self.eq_store.append(["Frequency band %d" % (i + 1), value])
# gui handlers