def __init__(self, app, name, use_icon, widget):
ControllerWidget.__init__(self, app, name, use_icon, widget)
if use_icon:
vbox = Gtk.Box(Gtk.Orientation.HORIZONTAL)
separator = Gtk.Separator(orientation = Gtk.Orientation.VERTICAL)
vbox.pack_start(self.icon, False, False, 1)
vbox.pack_start(separator, False, False, 1)
vbox.pack_start(self.label, False, True, 1)
self.widget.add(vbox)
else:
self.widget.add(self.label)
self.widget.show_all()
self.label.set_max_width_chars(12)
if name == "C":
self.label.set_max_width_chars(10)
python类Separator()的实例源码
def add_year(self, year_number):
# Create a new grid for the year
year_grid = yearGrid(year_number)
# Update map of years
self.year_map[year_number] = year_grid
label_box = Gtk.EventBox()
label_box.connect('button-press-event', self.year_clicked)
label = Gtk.Label(self.nth[year_number] + " Year")
label_box.add(label)
left_separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
left_separator.set_margin_start(1)
left_separator.set_margin_end(10)
self.attach(left_separator, self.new_column(), 0, 1, 3)
self.attach(year_grid, self.new_column(), 2, 1, 1)
self.attach(label_box, self.width, 0, 1, 1)
right_separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
right_separator.set_margin_start(10)
right_separator.set_margin_end(1)
self.attach(right_separator, self.new_column(), 0, 1, 3)
def _build_stream_vbox(self):
title = Gtk.Label("Streaming server")
title.set_margin_top(6)
self.stream_add_button = self._build_add_button(
callback=self.on_add_clicked)
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
separator.set_margin_top(6)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_margin_right(6)
_pack_widgets(vbox,
title,
self.settings_revealer,
separator,
self.stream_add_button)
self._make_scrolled_window(vbox)
return vbox
def _build_store_vbox(self):
title = Gtk.Label("Storing")
title.set_margin_top(6)
self.store_add_button = self._build_add_button(
callback=self.on_add_clicked)
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
separator.set_margin_top(6)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_margin_right(6)
_pack_widgets(vbox,
title,
self.settings_revealer,
separator,
self.store_add_button)
self._make_scrolled_window(vbox)
return vbox
def __init__(self, artist_playlist, row_activated, button_press_event):
self.artist_playlist = artist_playlist
self.view = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.view.pack_start(Gtk.Separator(margin_bottom=5, margin_left=10, margin_right=10, margin_top=0), False, True, 0)
for album_playlist in artist_playlist.collections_album():
self.view.pack_start(AlbumView(album_playlist,
row_activated,
button_press_event).get_view(), False, False, 0)
self.view.show_all()
def evict(self):
for row in reversed(sorted(set(self.all_row_numbers()))):
self.grid.remove_row(row)
if hasattr(self.grid, 'on_row_change'):
self.grid.on_row_change()
top = self.grid.get_child_at(top=0, left=0)
if top and type(top) is Gtk.Separator:
top.hide()
def add_to_grid(self, grid: Gtk.Grid):
if self.tenant:
raise Exception('Already added to a grid')
tenant = self.tenant = GridRowTenant(grid)
tenant_top = 0
if tenant.base_row > 0:
tenant.attach(Gtk.Separator(visible=True), width=RUNNING_JOB_COLUMNS)
tenant_top += 1
tenant.attach(self.title_box, top=tenant_top)
tenant.attach(self.cancel_btn, left=1, top=tenant_top)
tenant.attach(self.progress_bar, top=tenant_top + 1, width=RUNNING_JOB_COLUMNS)
tenant.attach(self.stats, top=tenant_top + 2, width=RUNNING_JOB_COLUMNS)
def add_to_grid(self, grid: Gtk.Grid):
if self.tenant:
raise Exception('Already added to a grid')
tenant = self.tenant = GridRowTenant(grid)
base = 0
if tenant.base_row > 0:
tenant.attach(Gtk.Separator(visible=True, hexpand=True), width=FINISHED_JOB_COLUMNS)
base += 1
tenant.attach(self.title_box, top=base)
tenant.attach(self.finish_box, top=base, left=1)
tenant.attach(self.buttons, top=base, left=2)
tenant.attach(self.extra, top=base+1, width=FINISHED_JOB_COLUMNS)
grid.get_toplevel().register_interest_in_sources(on_update_callback=self.on_source_update)
def add_to_grid(self, grid: Gtk.Grid):
if self.tenant:
raise Exception('Already added to a grid')
tenant = self.tenant = GridRowTenant(grid)
base = 0
if tenant.base_row > 0:
tenant.attach(Gtk.Separator(visible=True, hexpand=True), width=FINISHED_JOB_COLUMNS)
base += 1
tenant.attach(self.title_box, top=base)
tenant.attach(self.finish_box, top=base, left=1)
tenant.attach(self.buttons, top=base, left=2)
tenant.attach(self.extra, top=base + 1, width=FINISHED_JOB_COLUMNS)
grid.get_toplevel().register_interest_in_sources(on_update_callback=self.on_source_update)
def add_to_grid(self, grid: Gtk.Grid):
if self.tenant:
raise Exception('Already added to a grid')
tenant = self.tenant = GridRowTenant(grid)
base = 0
if tenant.base_row > 0:
tenant.attach(Gtk.Separator(visible=True, hexpand=True), width=FINISHED_JOB_COLUMNS)
base += 1
tenant.attach(self.title_box, top=base)
tenant.attach(self.finish_box, top=base, left=1)
tenant.attach(self.buttons, top=base, left=2)
tenant.attach(self.extra, top=base+1, width=FINISHED_JOB_COLUMNS)
def __init__(self, years=4):
Gtk.Grid.__init__(self)
# Tells which position the rightmost column is
self.width = 0
self.nth = {
1: "First",
2: "Second",
3: "Third",
4: "Fourth",
5: "Fifth",
6: "Sixth"
}
self.year_map = {}
self.set_margin_top(10)
self.set_margin_bottom(10)
self.set_margin_start(10)
self.set_margin_end(10)
horizontal_separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
horizontal_separator.set_margin_top(5)
horizontal_separator.set_margin_bottom(10)
self.attach(horizontal_separator, 0, 1, 2, 1)
for x in range(1,years+1):
self.add_year(x)
self.show_all()
def add_separator(self):
separator = Gtk.Separator()
separator.set_orientation(Gtk.Orientation.HORIZONTAL)
return self.add_item(separator)
def __init__(self, title='Statistics Line', count=None, *args, **kwargs):
super(StatLine, self).__init__(*args, **kwargs)
self.set_vexpand(False)
self.set_column_homogeneous(True)
self.get_style_context().add_class('transparencible')
self.title = Gtk.Label(label=title)
self.title.get_style_context().add_class('title')
self.title.set_hexpand(True)
self.statistics = list()
self.separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
if count is not None:
self.set_statistics_count(count)
def _build_summary_box(self, filename):
"""
Build a container that sums up information about an output sink.
:param filename: filename of stored stream as :class:`str`
:return: :class:`Gtk.Box`
"""
self.full_filename_label = Gtk.Label(filename)
settings_button = Gtk.Button(stock=Gtk.STOCK_PROPERTIES)
settings_button.connect("clicked", self.on_settings_clicked)
summary_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
summary_hbox.set_margin_top(6)
_pack_widgets(summary_hbox,
self.full_filename_label, settings_button)
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
separator.set_margin_top(6)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
_pack_widgets(vbox,
summary_hbox,
self._revealer,
separator)
return vbox
def list_header_func(row, before, user_data):
if before and not row.get_header():
row.set_header(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
def __init__(self, title):
Gtk.Frame.__init__(self)
self.set_shadow_type(Gtk.ShadowType.IN)
frame_style = self.get_style_context()
frame_style.add_class("view")
self.size_group = Gtk.SizeGroup()
self.size_group.set_mode(Gtk.SizeGroupMode.VERTICAL)
self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(self.box)
toolbar = Gtk.Toolbar.new()
toolbar_context = toolbar.get_style_context()
Gtk.StyleContext.add_class(Gtk.Widget.get_style_context(toolbar), "cs-header")
label = Gtk.Label.new()
label.set_markup("<b>%s</b>" % title)
title_holder = Gtk.ToolItem()
title_holder.add(label)
toolbar.add(title_holder)
self.box.add(toolbar)
toolbar_separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
self.box.add(toolbar_separator)
separator_context = toolbar_separator.get_style_context()
frame_color = frame_style.get_border_color(Gtk.StateFlags.NORMAL).to_string()
# css_provider = Gtk.CssProvider()
# css_provider.load_from_data(".separator { -GtkWidget-wide-separators: 0; \
# color: %s; \
# }" % frame_color)
# separator_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.list_box = Gtk.ListBox()
self.list_box.set_selection_mode(Gtk.SelectionMode.NONE)
self.list_box.set_header_func(list_header_func, None)
self.box.add(self.list_box)
def favoritesBuildSeparator( self ):
separator = Gtk.Separator( orientation=Gtk.Orientation.HORIZONTAL )
separator.set_margin_top( 5 )
separator.set_margin_bottom( 5 )
separator.type = "separator"
separator.show_all()
box = Gtk.EventBox()
box.type = "separator"
box.add(separator)
box.set_visible_window(False)
box.connect( "button-press-event", self.favPopup )
box.show_all()
return box
def generate_widget(self, item):
""" Generates gtk widget for specified menutitem """
if isinstance(item, Separator) and item.label:
widget = Gtk.Button.new_with_label(item.label)
widget.set_relief(Gtk.ReliefStyle.NONE)
widget.set_name("osd-menu-separator")
return widget
elif isinstance(item, Separator):
widget = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
widget.set_name("osd-menu-separator")
return widget
else:
widget = Gtk.Button.new_with_label(item.label)
widget.set_relief(Gtk.ReliefStyle.NONE)
if hasattr(widget.get_children()[0], "set_xalign"):
widget.get_children()[0].set_xalign(0)
else:
widget.get_children()[0].set_halign(Gtk.Align.START)
if isinstance(item, Submenu):
item.callback = self.show_submenu
label1 = widget.get_children()[0]
label2 = Gtk.Label(_(">>"))
label2.set_property("margin-left", 30)
box = Gtk.Box(Gtk.Orientation.HORIZONTAL)
widget.remove(label1)
box.pack_start(label1, True, True, 1)
box.pack_start(label2, False, True, 1)
widget.add(box)
widget.set_name("osd-menu-item")
elif item.id is None:
widget.set_name("osd-menu-dummy")
else:
widget.set_name("osd-menu-item")
if isinstance(item.icon, Gio.FileIcon):
icon_file = item.icon.get_file().get_path()
has_colors = True
elif isinstance(item.icon, Gio.ThemedIcon):
icon = Gtk.IconTheme.get_default().choose_icon(
item.icon.get_names(), 64, 0)
icon_file = icon.get_filename() if icon else None
has_colors = True
else:
icon_file, has_colors = find_icon(item.icon, self.PREFER_BW_ICONS)
if icon_file:
icon = MenuIcon(icon_file, has_colors)
label = widget.get_children()[0]
for c in [] + widget.get_children():
widget.remove(c)
box = Gtk.Box()
box.pack_start(icon, False, True, 0)
box.pack_start(label, True, True, 10)
widget.add(box)
return widget
def __init__(self, year):
Gtk.Grid.__init__(self)
self.year = year
self.selected_quarter = None
self.quarters = {
0: "Fall",
1: "Winter",
2: "Spring",
3: "Summer"
}
self.hidden = {x: False for x in [0,2,4,6]}
self.quarter_map = {}
self.set_vexpand(True)
self.set_hexpand(True)
self.set_valign(Gtk.Align.FILL)
self.set_halign(Gtk.Align.FILL)
horizontal_separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
horizontal_separator.set_margin_top(2)
horizontal_separator.set_margin_bottom(5)
self.attach(horizontal_separator, 0, 1, 2, 1)
for x in [0,2,4,6]:
if x < 6:
# Don't insert a column if it's at position 0
if x: self.insert_column(x)
# Insert column to expand horizontal separator
self.insert_column(x+1)
vertical_separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
vertical_separator.set_margin_start(5)
vertical_separator.set_margin_end(5)
self.attach(vertical_separator, x+1, 0, 1, 3)
quarter = quarterColumn(self.year, self.quarters[x/2])
label_box = Gtk.EventBox()
label = Gtk.Label(self.quarters[x/2])
label_box.add(label)
label_box.connect('button-press-event', self.quarter_clicked)
self.attach(label_box, x, 0, 1, 1)
self.quarter_map[x/2] = quarter
self.attach(quarter, x, 2, 1, 1)
self.hide_menu = Gtk.Menu()
hide_button = Gtk.MenuItem.new_with_label('Hide')
self.hide_menu.append(hide_button)
hide_button.show()
hide_button.connect('activate', self.toggle_quarter)
self.show_all()
def _build_audio_vbox(self):
"""
"""
title = Gtk.Label("Audio Source")
title.set_margin_top(6)
self.mic_sources = Gtk.ComboBoxText()
for source in self.pipeline.audio_sources:
self.mic_sources.append_text(source.description)
self.sources_list.append(source.description)
self.mic_sources.connect("changed", self.on_input_change)
self.mic_sources.set_margin_left(24)
self.mute_checkbutton = Gtk.CheckButton("Mute (soon)")
self.mute_checkbutton.connect("toggled", self.on_mute_toggle)
self.mute_checkbutton.set_sensitive(False)
self.output_sinks = Gtk.ComboBoxText()
index = 0
for description, device in self.pipeline.speaker_sinks.items():
self.output_sinks.append_text(description)
self.sinks_list.append(description)
if device == self.pipeline.speaker_sink.get_property("device"):
self.output_sinks.set_active(index)
index += 1
self.output_sinks.connect("changed", self.on_output_change)
self.output_sinks.set_margin_left(24)
self.audio_confirm_button = self._build_confirm_changes_button(
callback=self.on_confirm_clicked)
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
separator.set_margin_top(6)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_margin_right(6)
_pack_widgets(vbox,
title,
self.mic_sources,
self.mute_checkbutton,
self.output_sinks,
self.audio_confirm_button,
separator)
self._make_scrolled_window(vbox)
return vbox
def _build_settings_vbox(self):
title = Gtk.Label("Settings")
title.set_margin_bottom(6)
self.text_overlay_entry = Gtk.Entry()
self.text_overlay_entry.set_placeholder_text("Text displayed on screen")
self.text_overlay_entry.set_width_chars(30)
self.text_overlay_entry.connect("changed", self.on_text_change)
self.text_overlay_entry.set_sensitive(True) # DEV
self.text_position_combobox = Gtk.ComboBoxText()
for position in self.positions:
self.text_position_combobox.append_text(position)
self.text_position_combobox.set_active(0)
self.text_position_combobox.set_margin_left(24)
self.text_position_combobox.set_sensitive(False) # DEV
self.hide_text_checkbutton = Gtk.CheckButton("Hide Text")
self.hide_text_checkbutton.connect("toggled", self.on_hide_text_toggle)
self.image_chooser_button = Gtk.FileChooserButton()
self.image_chooser_button.set_title("Select an image to display")
self.image_chooser_button.connect("file-set", self.on_image_selected)
self.image_chooser_button.set_sensitive(True) # DEV
self.image_position_combobox = Gtk.ComboBoxText()
for position in self.positions:
self.image_position_combobox.append_text(position)
self.image_position_combobox.set_active(1)
self.image_position_combobox.set_margin_left(24)
self.image_position_combobox.set_sensitive(False) # DEV
self.hide_image_checkbutton = Gtk.CheckButton("Hide Image")
self.hide_image_checkbutton.connect(
"toggled", self.on_hide_image_toggle)
self.settings_confirm_button = self._build_confirm_changes_button(
callback=self.on_confirm_clicked)
self.settings_confirm_button.set_label("Confirm")
self.settings_confirm_button.set_size_request(250, 20)
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
separator.set_margin_top(6)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_margin_right(6)
_pack_widgets(vbox,
title,
self.text_overlay_entry,
self.text_position_combobox,
self.hide_text_checkbutton,
self.image_chooser_button,
self.image_position_combobox,
self.hide_image_checkbutton,
self.settings_confirm_button,
separator)
self._make_scrolled_window(vbox)
return vbox