def create_buttons(self):
self.grid = Gtk.Grid()
self.parent.pack_start(self.grid, True, True, 0)
self._buttons = []
x, y = 0, 0
for label in self.BUTTONS:
if label:
w = self.generate_widget(label)
w.set_name("osd-key-buton")
self.grid.attach(w, x, y, 1, 1)
self._buttons.append(w)
x += 1
if x > 2:
x = 0
y += 1
w = self.generate_widget(_("Run"))
self.grid.attach(w, x, y, 1, 1)
self.grid.set_name("osd-dialog-buttons")
python类Grid()的实例源码
def __init__(self):
#self._widget = Gtk.Notebook()
self._widget = Gtk.Label("Configuration panel for JSHint Plugin")
#grid = Gtk.Grid()
#for i in range(30):
# button = Gtk.CheckButton("Button {}".format(i))
# button.set_tooltip_text("This is the button {}".format(i))
# grid.attach(button, i // 10, i % 10, 1, 1)
#self._widget.append_page(grid, Gtk.Label("Enforcing"))
#page = Gtk.Box()
#page.add(Gtk.Label("Relaxing options"))
#self._widget.append_page(page, Gtk.Label("Relaxing"))
#page = Gtk.Box()
#page.add(Gtk.Label("Environments options"))
#self._widget.append_page(page, Gtk.Label("Environments"))
def __init__(self, exname, callback, sensicallback, vars_to_watch):
IntervalButtonsWidgetBase.__init__(self, exname, callback, sensicallback)
g1 = Gtk.Grid()
for i, (x, y) in enumerate((
(0, 0), (1, 0), (2, 0), (3, 0),
(0, 1), (1, 1), (2, 1), (3, 1),
(0, 2), (1, 2), (2, 2), (3, 2))):
g1.attach(self.mk_button(i + 1), x, y, 1, 1)
g2 = Gtk.Grid()
for i, (x, y) in enumerate((
(0, 0), (1, 0), (2, 0), (3, 0),
(0, 1), (1, 1), (2, 1), (3, 1),
(0, 2), (1, 2), (2, 2), (3, 2))):
g2.attach(self.mk_button(i + 13), x, y, 1, 1)
self.set_row_spacing(gu.hig.SPACE_MEDIUM)
self.add(g1)
self.add(g2)
self.post_construct(vars_to_watch)
def __create_album_flowboxitem(self, album, image, margin):
label_album = Gtk.Label(f'{album.Name} ({album.Year})', max_width_chars=0,
justify=Gtk.Justification.LEFT, wrap=True,
wrap_mode=Pango.WrapMode.WORD_CHAR, xalign=0, margin_top=5)
label_artist = Gtk.Label(album.Artist, max_width_chars=0, justify=Gtk.Justification.LEFT,
ellipsize=Pango.EllipsizeMode.END, xalign=0, margin_top=5)
label_album.get_style_context().add_class('text110')
label_artist.get_style_context().add_class('dim-label')
flowboxchild = Gtk.FlowBoxChild(halign=Gtk.Align.CENTER)
grid = Gtk.Grid(margin=margin, halign=Gtk.Align.CENTER)
grid.attach(image, 0, 0, 1, 1)
grid.attach(label_album, 0, 1, 1, 1)
grid.attach(label_artist, 0, 2, 1, 1)
flowboxchild.add(grid)
flowboxchild.data = album
return flowboxchild
def __init__(self,main_grid):
Gtk.Grid.__init__(self)
self.maingrid = main_grid
self.n_row = 0
self.set_row_spacing(2)
self.widgetlist = widget_list()
button1 = step_box("browser",self)
self.add(button1)
button2 = step_box("alienarena",self)
self.add(button2)
button3 = step_box("live",self)
self.add(button3)
button4 = step_box("cs-network",self)
self.add(button4)
def __init__(self):
Gtk.Grid.__init__(self)
self.n_col = 2
self.widget_count = 0
self.set_column_spacing(2)
self.set_row_spacing(2)
button1 = toolbutton("browser")
self.add(button1)
button2 = toolbutton("alienarena")
self.add(button2)
button3 = toolbutton("live")
self.add(button3)
button4 = toolbutton("cs-network")
self.add(button4)
def setup_window(self):
self.menubar = controlBar()
self.set_titlebar(self.menubar)
self.connect_control_buttons()
self.edit_menu = dataMenu()
self.add_menu = addMenu()
self.connect_menu_buttons()
main_grid = Gtk.Grid()
self.add(main_grid)
main_grid.attach(self.menubar, 0, 0, 1, 1)
self.interface_switcher = Gtk.Notebook()
self.interface_switcher.set_show_tabs(False)
main_grid.attach(self.interface_switcher, 0, 1, 1, 1)
self.setup_viewer()
self.setup_builder()
def __init__(self, title, priority=ItemsProcessorPriority.NORMAL, default=False):
super().__init__()
self.items = []
self.priority = priority
self.default = default
self.set_valign(Gtk.Align.FILL)
self.set_halign(Gtk.Align.FILL)
self.set_hexpand(True)
self.set_vexpand(True)
self.title = title
self.grid = Gtk.Grid()
self.add(self.grid)
self.show_all()
def make_box(text, length, digit):
label = Gtk.Label()
label.set_markup("<span size='small'>{}</span>".format(text))
label.set_alignment(0.0, 0.5)
label.set_property("margin-top", 10)
label.set_property("margin-bottom", 10)
entry = Gtk.Entry()
if length: entry.set_max_length(length)
if digit:
entry.set_name(str(digit))
entry.connect("changed", digits_only)
grid = Gtk.Grid()
grid.attach(label, 0, 0, 1, 1)
grid.attach(entry, 0, 1, 1, 1)
return grid
def cert(self):
page = self.tabs[self.current_page][0]
reveal(page.cert_revealer, False)
data = page.webview.get_tls_info()
popover = build_scrollable_popover(Gtk.PositionType.BOTTOM, -1, 500)
grid = Gtk.Grid()
grid.set_column_homogeneous(True)
for x in range(0, 14): grid.attach(cert_declarations(data, x+1), 0, x, 1, 1)
for i in popover:
if type(i) == Gtk.ScrolledWindow: i.add(grid)
entry = page.main_url_entry
popover.set_relative_to(entry)
popover.set_pointing_to(entry.get_icon_area(Gtk.EntryIconPosition.SECONDARY))
popover.show_all()
self.update_status()
return True
def __init__(self):
self.placeholder_image = Gtk.Image.new_from_icon_name(
Gtk.STOCK_NEW, Gtk.IconSize.DIALOG)
self.new_feed_button = Gtk.Button("New Feed")
self.new_feed_vbox = Gtk.Box(Gtk.Orientation.VERTICAL)
self.new_feed_vbox.set_halign(Gtk.Align.CENTER)
self.new_feed_vbox.set_valign(Gtk.Align.CENTER)
_pack_widgets(self.new_feed_vbox,
self.placeholder_image,
self.new_feed_button)
self._grid = Gtk.Grid()
self._grid.set_row_homogeneous(True)
self._grid.set_column_homogeneous(True)
self._grid.attach(self.new_feed_vbox, 0, 0, 1, 1)
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG1"), 1, 0, 1, 1) # DEBUG
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG2"), 0, 1, 1, 1) # DEBUG
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG3"), 1, 1, 1, 1) # DEBUG
self._grid.show_all()
self.container = self._grid
def get_grid(self):
"""
@description: get the grid
@return a Gtk.Grid
"""
return self.grid
def __init__(self, store, iter=None):
self.grid = Gtk.Grid()
self.grid.set_border_width(5)
self.grid.set_row_spacing(5)
self.grid.set_vexpand(True)
self.grid.set_hexpand(True)
self.grid.set_column_spacing(2)
self.grid.set_column_homogeneous(False)
self.grid.set_row_homogeneous(False)
label1 = Gtk.Label('key sentence')
label1.set_justify(Gtk.Justification.LEFT)
label1.set_halign(Gtk.Align.START)
label1.set_hexpand(True)
label2 = Gtk.Label('your command')
label2.set_justify(Gtk.Justification.LEFT)
label2.set_halign(Gtk.Align.START)
ll = Gtk.Label()
ll.set_vexpand(True)
self.entry1 = Gtk.Entry()
if iter is not None:
self.entry1.set_text(store[iter][0])
self.combo = self.__get_combobox(store, iter)
button = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
button.connect("clicked", self.button_clicked, store, iter)
button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
button_cancel.connect("clicked", self.do_destroy)
self.grid.attach(label1, 0, 0, 11, 1)
self.grid.attach(self.entry1, 11, 0, 4, 1)
self.grid.attach(label2, 0, 1, 11, 1)
self.grid.attach(self.combo, 11, 1, 4, 1)
self.grid.attach(ll, 0, 2, 15, 1)
self.grid.attach(button_cancel, 13, 3, 1, 1)
self.grid.attach(button, 14, 3, 1, 1)
self.grid.show_all()
def __init__(self, store, iter=None):
self.grid = Gtk.Grid()
self.grid.set_border_width(5)
self.grid.set_row_spacing(5)
self.grid.set_vexpand(True)
self.grid.set_hexpand(True)
self.grid.set_column_spacing(2)
self.grid.set_column_homogeneous(False)
label1 = Gtk.Label('key sentence')
label1.set_hexpand(True)
label1.set_justify(Gtk.Justification.LEFT)
label1.set_halign(Gtk.Align.START)
label2 = Gtk.Label('your command')
label2.set_justify(Gtk.Justification.LEFT)
label2.set_halign(Gtk.Align.START)
ll = Gtk.Label()
ll.set_vexpand(True)
self.entry1 = Gtk.Entry()
self.entry2 = Gtk.Entry()
if iter is not None:
self.entry1.set_text(store[iter][0])
self.entry2.set_text(store[iter][1])
button = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
button.connect("clicked", self.button_clicked, store, iter)
button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
button_cancel.connect("clicked", self.do_destroy)
self.grid.attach(label1, 0, 0, 11, 1)
self.grid.attach(self.entry1, 11, 0, 4, 1)
self.grid.attach(label2, 0, 1, 11, 1)
self.grid.attach(self.entry2, 11, 1, 4, 1)
self.grid.attach(ll, 0, 2, 15, 1)
self.grid.attach(button_cancel, 13, 3, 1, 1)
self.grid.attach(button, 14, 3, 1, 1)
self.grid.show_all()
def create_parent(self):
g = Gtk.Grid()
g.set_name("osd-menu")
return g
def create_parent(self):
g = Gtk.Grid()
g.set_name("osd-menu")
return g
def setup_widgets(self):
self.parent = Gtk.Grid()
self.parent.set_name("osd-gesture")
self._left_draw = GestureDraw(self.SIZE, self._left_detector)
# self._right_draw = GestureDraw(self.SIZE, self._right_detector)
sep = Gtk.VSeparator()
sep.set_name("osd-gesture-separator")
self.parent.attach(self._left_draw, 0, 0, 1, 1)
# self.parent.attach(sep, 1, 0, 1, 1)
# self.parent.attach(self._right_draw, 2, 0, 1, 1)
self.add(self.parent)
def __init__(self, app, name, use_icon, enable_press, widget):
self.pressed = Gtk.Label() if enable_press else None
self.click_button = SCButtons.STICKPRESS
ControllerWidget.__init__(self, app, name, use_icon, widget)
grid = Gtk.Grid()
self.widget.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
self.widget.connect('motion-notify-event', self.on_cursor_motion)
self.label.set_property("vexpand", True)
self.label.set_property("hexpand", True)
if self.pressed:
self.label.set_xalign(0.0); self.label.set_yalign(0.5)
self.pressed.set_property("hexpand", True)
self.pressed.set_xalign(0.0); self.pressed.set_yalign(1.0)
grid.attach(self.pressed, 2, 2, 1, 1)
else:
self.label.set_xalign(0.5); self.label.set_yalign(0.5)
self.pressed = None
if self.icon:
self.icon.set_margin_right(5)
grid.attach(self.icon, 1, 1, 1, 2)
grid.attach(self.label, 2, 1, 1, 1)
self.over_icon = False
self.enable_press = enable_press
self.widget.add(grid)
self.widget.show_all()
def h_spacer(self, addwidth):
# horizontal spacer
spacegrid = Gtk.Grid()
if addwidth:
label1 = Gtk.Label()
label2 = Gtk.Label()
spacegrid.attach(label1, 0, 0, 1, 1)
spacegrid.attach(label2, 1, 0, 1, 1)
spacegrid.set_column_spacing(addwidth)
return spacegrid
def h_spacer(self, addwidth):
# horizontal spacer
spacegrid = Gtk.Grid()
if addwidth:
label1 = Gtk.Label()
label2 = Gtk.Label()
spacegrid.attach(label1, 0, 0, 1, 1)
spacegrid.attach(label2, 1, 0, 1, 1)
spacegrid.set_column_spacing(addwidth)
return spacegrid
def __init__(self, exname, callback, sensicallback):
"""
callback -- the function to call when the user click on a button.
sensicallback -- a function that will return a list of all interval
it will be asked for.
"""
Gtk.Grid.__init__(self)
cfg.ConfigUtils.__init__(self, exname)
self.set_orientation(Gtk.Orientation.VERTICAL)
self.get_sensitive_buttons = sensicallback
self.m_callback = callback
self.m_buttons = {}
def row(self, *data):
row = Gtk.Grid()
row.set_column_homogeneous(True)
self.add(row)
for i in data:
row.add(self.mk_button(i))
def create_grid (self):
self.grid = Gtk.Grid()
def __create_artist_flowboxitem(self, artist, image, margin):
label_album = Gtk.Label(artist.Name, max_width_chars=0, justify=Gtk.Justification.LEFT,
ellipsize=Pango.EllipsizeMode.END, xalign=0, margin_top=5)
label_album.get_style_context().add_class('text110')
flowboxchild = Gtk.FlowBoxChild()
grid = Gtk.Grid(margin=margin, halign=Gtk.Align.CENTER)
grid.attach(image, 0, 0, 1, 1)
grid.attach(label_album, 0, 1, 1, 1)
flowboxchild.add(grid)
flowboxchild.data = artist
return flowboxchild
def __init__(self):
Gtk.Grid.__init__(self)
self.spinner = Gtk.Spinner(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER, expand=True)
self.spinner.start()
self.add(self.spinner)
def rows(grid: Gtk.Grid) -> int:
return max(map(lambda child: grid.child_get_property(child, 'top-attach'), grid.get_children()), default=-1) + 1
def __init__(self, grid: Gtk.Grid):
self.grid = grid
self.base_row = rows(grid)
self.attached = []
def add_to_grid(self, grid: Gtk.Grid):
raise Exception('abstract')
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)