def insert_image(self, widget):
self.insert_window_image = Gtk.Window()
self.insert_window_image.set_title("Insert Image")
self.insert_window_image.set_resizable(True)
self.insert_window_image.set_border_width(6)
self.insert_window_image.set_default_size(300, 250)
self.insert_window_image.set_position(Gtk.WindowPosition.CENTER)
vbox = Gtk.VBox()
label_alt_text = Gtk.Label("Alt Text:")
self.entry_alt_text_i = Gtk.Entry()
label_title = Gtk.Label("Title:")
self.entry_title_i = Gtk.Entry()
label_url = Gtk.Label("Path/Url:")
self.entry_url_i = Gtk.Entry()
vbox.pack_start(label_alt_text, self, False, False)
vbox.pack_start(self.entry_alt_text_i, self, False, False)
vbox.pack_start(label_title, self, False, False)
vbox.pack_start(self.entry_title_i, self, False, False)
vbox.pack_start(label_url, self, False, False)
self.hbox_url = Gtk.HBox()
self.hbox_url.pack_start(self.entry_url_i, self, True, False)
self.path_file_button = Gtk.FileChooserButton(title= "Select an image")
self.path_file_button.connect("file-set", self.file_chooser_button_clicked)
self.hbox_url.pack_start(self.path_file_button, self, False, False)
vbox.pack_start(self.hbox_url, self, False, False)
button = Gtk.Button("Insert Image")
vbox.pack_end(button, self, False, False)
self.insert_window_image.add(vbox)
self.insert_window_image.show_all()
button.connect("clicked", self.insert_image_cmd, self.insert_window_image)
python类FileChooserButton()的实例源码
def __init__(self, main_view: 'MainView', core: ApartCore, z_options: List[str]):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, expand=True, halign=Gtk.Align.CENTER)
self.main_view = main_view
self.core = core
self.z_options = z_options
self.title = Gtk.Label('', xalign=0.5)
self.title.get_style_context().add_class('dim-label')
self.image_label = Gtk.Label("Image File", xalign=1.0)
self.image_label.get_style_context().add_class('dim-label')
self.image_entry = Gtk.FileChooserButton(title='Select Image File')
image_file_filter = Gtk.FileFilter()
image_file_filter.set_name('Apart Image files')
for z_option in z_options:
image_file_filter.add_pattern('*.apt.*.{}'.format(z_option))
if z_option == 'zst': # also support .zstd from v0.14
image_file_filter.add_pattern('*.apt.*.zstd')
self.image_entry.add_filter(image_file_filter)
self.image_entry.connect('selection-changed', lambda v: self.on_image_select())
self.options = Gtk.Grid(row_spacing=6)
self.options.get_style_context().add_class('new-clone-options')
self.options.attach(self.title, left=0, top=0, width=2, height=1)
self.options.attach(self.image_label, left=0, top=1, width=1, height=1)
self.options.attach(self.image_entry, left=1, top=1, width=1, height=1)
self.cancel_btn = Gtk.Button('Cancel')
self.cancel_btn.connect('clicked', lambda v: self.main_view.show_progress())
self.start_btn = Gtk.Button('Restore Partition')
self.start_btn.set_sensitive(False)
self.start_btn.connect('clicked', lambda v: self.user_confirm())
self.buttons = Gtk.Box(halign=Gtk.Align.END)
self.buttons.get_style_context().add_class('new-clone-buttons')
self.buttons.add(self.cancel_btn)
self.buttons.add(self.start_btn)
self.add(self.options)
self.options.attach_next_to(self.buttons, sibling=self.image_label,
side=Gtk.PositionType.BOTTOM, width=2, height=1)
self.last_part_info = None
def _build_newfile_vbox(self):
"""
"""
self.folder_chooser_button = Gtk.FileChooserButton(
action=Gtk.FileChooserAction.SELECT_FOLDER)
self.folder_chooser_button.set_title("Select a folder")
self.folder_chooser_button.connect("file-set", self.on_folder_selected)
self.folder_chooser_button.set_margin_top(6)
name_label = Gtk.Label("Name ")
self.name_entry = Gtk.Entry()
self.name_entry.set_width_chars(25)
self.name_entry.set_input_purpose(Gtk.InputPurpose.ALPHA)
self.name_entry.set_placeholder_text("Type a filename")
self.name_entry.connect("changed", self.on_entry_change)
name_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
_pack_widgets(name_hbox, name_label, self.name_entry)
self.automatic_naming_checkbutton = Gtk.CheckButton()
self.automatic_naming_checkbutton.set_active(True)
self.automatic_naming_checkbutton.set_sensitive(False) # DEV
automatic_naming_label = Gtk.Label("Make Unique filename")
automatic_naming_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
_pack_widgets(automatic_naming_hbox,
self.automatic_naming_checkbutton,
automatic_naming_label)
radiobutton_hbox = self._build_format_group()
self.store_confirm_button = self._build_confirm_changes_button(
callback=self.on_confirm_clicked)
# Label only used at initialization
self.store_confirm_button.set_label("Create")
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
_pack_widgets(vbox,
self.folder_chooser_button,
name_hbox,
automatic_naming_hbox,
radiobutton_hbox,
self._audiovideo_format_hbox,
self.store_confirm_button)
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