def __init__(self, parent):
Gtk.Dialog.__init__(self, "Enter API Key", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(150, 100)
api_key_field = Gtk.Entry()
api_key_field.set_placeholder_text("API Key")
self.api_key_field = api_key_field
box = self.get_content_area()
box.set_margin_top(10)
box.set_margin_bottom(10)
box.set_margin_left(10)
box.set_margin_right(10)
box.set_spacing(10)
box.add(api_key_field)
self.show_all()
python类STOCK_OK的实例源码
def show_pieces_dialog(self, gtkaction):
dialog = Gtk.Dialog(
_("Select Pieces"), gv.gui.get_window(), 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
rb1 = Gtk.RadioButton.new_with_label(None, "Pieceset 1")
dialog.vbox.pack_start(rb1, False, True, 5)
rb2 = Gtk.RadioButton.new_with_label_from_widget(rb1, "Pieceset 2")
dialog.vbox.pack_start(rb2, False, True, 5)
dialog.show_all()
dialog.set_default_response(Gtk.ResponseType.OK)
if self.pieceset == 0:
rb1.set_active(True)
elif self.pieceset == 1:
rb2.set_active(True)
else:
rb1.set_active()
response = dialog.run()
if response == Gtk.ResponseType.OK:
if rb1.get_active():
self.pieceset = 0
elif rb2.get_active():
self.pieceset = 1
dialog.destroy()
return
def __init__(self, oldname):
Gtk.Dialog.__init__(self, _(u"_Rename profile\u2026").replace("_", "").replace(u"\u2026", ""))
self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
vbox = gu.hig_dlg_vbox()
self.vbox.pack_start(vbox, True, True, 0)
label = Gtk.Label(label=_(u"Rename the profile «%s» to:") % oldname)
label.set_alignment(0.0, 0.5)
vbox.pack_start(label, False, False, 0)
self.g_entry = Gtk.Entry()
self.g_entry.set_text(oldname)
self.g_entry.set_activates_default(True)
self.g_entry.connect('changed', self.on_entry_changed)
vbox.pack_start(self.g_entry, False, False, 0)
self.g_info = Gtk.Label()
self.g_info.set_no_show_all(True)
vbox.pack_start(self.g_info, False, False, 0)
self.set_default_response(Gtk.ResponseType.ACCEPT)
def add_file_task(self, dir_name=None):
'''??????, ?????????????'''
file_dialog = Gtk.FileChooserDialog(_('Choose Files..'),
self.app.window, Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
file_dialog.set_modal(True)
file_dialog.set_select_multiple(True)
file_dialog.set_default_response(Gtk.ResponseType.OK)
response = file_dialog.run()
if response != Gtk.ResponseType.OK:
file_dialog.destroy()
return
source_paths = file_dialog.get_filenames()
file_dialog.destroy()
if source_paths:
self.upload_files(source_paths, dir_name)
def add_folder_task(self, dir_name=None):
'''??????, ??????????????'''
folder_dialog = Gtk.FileChooserDialog(_('Choose Folders..'),
self.app.window, Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
folder_dialog.set_modal(True)
folder_dialog.set_select_multiple(True)
folder_dialog.set_default_response(Gtk.ResponseType.OK)
folder_dialog.set_current_folder(Config.HOME_DIR)
response = folder_dialog.run()
if response != Gtk.ResponseType.OK:
folder_dialog.destroy()
return
source_paths = folder_dialog.get_filenames()
folder_dialog.destroy()
if source_paths:
self.upload_files(source_paths, dir_name)
def on_download_to_activated(self, menu_item):
'''????/??????????.'''
tree_paths = self.iconview.get_selected_items()
if not tree_paths:
return
dialog = Gtk.FileChooserDialog(_('Save to...'), self.app.window,
Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
response = dialog.run()
if response != Gtk.ResponseType.OK:
dialog.destroy()
return
dirname = dialog.get_filename()
dialog.destroy()
pcs_files = [self.get_pcs_file(p) for p in tree_paths]
self.app.blink_page(self.app.download_page)
self.app.download_page.add_tasks(pcs_files, dirname)
def __init__(self, parent, title, text):
Gtk.Dialog.__init__(self, title, parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(350, 0)
self.set_default_response(Gtk.ResponseType.OK)
self.label = Gtk.Label(text)
self.label.set_margin_start(5)
self.label.set_margin_top(5)
self.label.set_margin_bottom(5)
self.label.set_margin_end(5)
self.entry = Gtk.Entry()
self.entry.set_margin_start(5)
self.entry.set_margin_top(5)
self.entry.set_margin_bottom(5)
self.entry.set_margin_end(5)
self.entry.connect('activate', lambda widget: self.response(Gtk.ResponseType.OK))
self.get_content_area().add(self.label)
self.get_content_area().add(self.entry)
def on_delete_learned_data_clicked(self, dummy_widget):
'''
The button requesting to delete all data learned from
user input or text files has been clicked.
'''
SETUP_UI.delete_learned_data_button.set_sensitive(False)
confirm_question = Gtk.Dialog(
title=_('Are you sure?'),
parent=SETUP_UI.builder.get_object('main_dialog'),
buttons=(
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
box = confirm_question.get_content_area()
box.add(Gtk.Label(
_('Do you really want to delete all language \n'
+ 'data learned from typing or reading files?')))
confirm_question.show_all()
response = confirm_question.run()
confirm_question.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
SETUP_UI.tabsqlitedb.remove_all_phrases()
SETUP_UI.delete_learned_data_button.set_sensitive(True)
def confirm(parent=None, title="", text=""):
dialog = Gtk.Dialog(title, parent, 0)
dialog.set_default_size(150, 100)
dialog.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("white"))
label = Gtk.Label()
label.set_markup('<span foreground="#494941" face="sans">' + text + '</span>')
box = dialog.get_content_area()
box.add(label)
box.show_all()
btn1 = dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
btn1.set_relief(2)
btn2 = dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
btn2.set_relief(2)
result = False
response = dialog.run()
dialog.destroy()
if response == Gtk.ResponseType.OK:
result = True
elif response == Gtk.ResponseType.CANCEL:
result = False
return result
def __init__(self, root: Gtk.Window, text: str,
ok_button_text: str = Gtk.STOCK_OK,
cancel_button_text: str = Gtk.STOCK_CANCEL,
header: str = '',
message_type: Gtk.MessageType = Gtk.MessageType.WARNING):
Gtk.MessageDialog.__init__(self, root, 0, message_type=message_type)
self.set_title(header)
self.icon = Gtk.Image()
self.icon.set_from_icon_name(appropriate_icon(message_type), Gtk.IconSize.LARGE_TOOLBAR)
self.text = Gtk.Label(text)
heading = Gtk.Box()
heading.add(self.icon)
heading.add(self.text)
self.get_message_area().add(heading)
self.get_message_area().set_spacing(0)
self.add_button(cancel_button_text, Gtk.ResponseType.CANCEL)
self.add_button(ok_button_text, Gtk.ResponseType.OK)
self.show_all()
def __init__(self, root: Gtk.Window, text: str,
ok_button_text: str = Gtk.STOCK_OK,
header: str = '',
message_type: Gtk.MessageType = Gtk.MessageType.ERROR):
Gtk.MessageDialog.__init__(self, root, 0, message_type=message_type)
self.set_title(header)
self.icon = Gtk.Image()
self.icon.set_from_icon_name(appropriate_icon(message_type), Gtk.IconSize.LARGE_TOOLBAR)
self.text = Gtk.Label(text)
heading = Gtk.Box()
heading.add(self.icon)
heading.add(self.text)
self.get_message_area().add(heading)
self.get_message_area().set_spacing(0)
self.add_button(ok_button_text, Gtk.ResponseType.OK)
self.show_all()
def save_html(self, data):
html = data
chooser = Gtk.FileChooserDialog("Export HTML", None, Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
html_filter = Gtk.FileFilter()
html_filter.set_name("HTML Files")
html_filter.add_pattern("*.html")
html_filter.add_pattern("*.htm")
chooser.set_do_overwrite_confirmation(True)
chooser.add_filter(html_filter)
response = chooser.run()
if response == Gtk.ResponseType.OK:
file_name = chooser.get_filename()
if not file_name.endswith(".html"):
file_name += ".html"
file = open(file_name, 'w')
soup = BeautifulSoup(html, "lxml")
file.write(soup.prettify())
file.close()
elif response == Gtk.ResponseType.CANCEL:
pass
chooser.destroy()
self.window.set_sensitive(True)
def build_confirm_dialog(self, message_type, message_label,
on_signal=None, callback=None):
"""
Create a :class:`Gtk.MessageDialog` asking user for confirmation.
:param message_type: :class:`Gtk.MessageType`
:param message_label: text displayed to user as :class`str`
:param on_signal: Gtk signal as :class:`str`
:param callback: callback to connect to ``signal``
"""
confirm_dialog = Gtk.MessageDialog(
message_type=message_type, message_format=message_label)
confirm_dialog.set_icon_from_file(self.images.logo_favicon_path)
confirm_dialog.set_title("Confirmation")
confirm_dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
confirm_dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
confirm_dialog.set_modal(True)
if on_signal and callback:
confirm_dialog.connect(on_signal, callback)
confirm_dialog.run()
def __init__(self, parent):
Gtk.Dialog.__init__(self, "Enter Credentials", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(150, 100)
username_field = Gtk.Entry()
username_field.set_placeholder_text("Username")
password_field = Gtk.Entry()
password_field.set_placeholder_text("Password")
password_field.set_visibility(False)
password_field.set_invisible_char('*')
self.username_field = username_field
self.password_field = password_field
box = self.get_content_area()
box.set_margin_top(10)
box.set_margin_bottom(10)
box.set_margin_left(10)
box.set_margin_right(10)
box.set_spacing(10)
box.add(username_field)
box.add(password_field)
self.show_all()
def __init__(self, app):
Gtk.Window.__init__(self, title="Mama Manager", application=app)
self.set_default_size(800, 400)
self.set_resizable(True)
self.set_border_width(0)
self.get_focus()
self.set_position(Gtk.WindowPosition.CENTER)
path = os.path.dirname(os.path.abspath(__file__)).strip('librairy')
self.icon_path = path + 'resources/icons/'
self.set_default_icon_from_file(path + '/resources/icons.png')
# get two button to switch between view
setup_icon = Gtk.Image()
setup_icon.set_from_file(self.icon_path + 'setup.png')
button_config = Gtk.ToolButton(icon_widget=setup_icon)
button_config.set_label("Setup")
button_config.set_is_important(True)
button_config.set_tooltip_text('Open setup window')
button_config.show()
button_config.connect("clicked", self.change_page, 1)
button_back = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
button_back.connect("clicked", self.change_page, 0)
button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
button_cancel.connect("clicked", self.change_page, 0)
# get the main view
content = AddWindow(button_config)
label_main = Gtk.Label("main")
config = SetupWindow(button_back, button_cancel)
label_config = Gtk.Label("config")
# create a Gtk.Notebook to store both page
self.notebook = Gtk.Notebook.new()
self.notebook.set_show_tabs(False)
self.notebook.append_page(content.get_grid(), label_main)
self.notebook.append_page(config.getGrid(), label_config)
# show
self.add(self.notebook)
self.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)
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 __init__(self, parent, message=""):
Gtk.Dialog.__init__(self, "Confirmation", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_resizable(False)
self.get_content_area().add(Gtk.Label(message))
self.show_all()
def __init__(self):
Gtk.Dialog.__init__(self, 'File Downloader',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.set_size_request(400, 100)
self.set_title('? ubi site file downloader')
self.connect('destroy', self.close_application)
#
vbox0 = Gtk.VBox(spacing = 10)
vbox0.set_border_width(5)
self.get_content_area().add(vbox0)
#
table1 = Gtk.Table(3,2,False)
vbox0.add(table1)
label10 = Gtk.Label('Extension:')
label10.set_alignment(0, 0.5)
table1.attach(label10,0,1,0,1)
#
self.entry10 = Gtk.Entry()
table1.attach(self.entry10,1,2,0,1)
#
label11 = Gtk.Label('Url:')
label11.set_alignment(0, 0.5)
table1.attach(label11,0,1,1,2)
#
self.entry11 = Gtk.Entry()
table1.attach(self.entry11,1,2,1,2)
#
#self.button = Gtk.Button('Select folder')
#self.button.connect('clicked',self.on_button_clicked)
#table1.attach(self.button,0,2,2,3)
#
self.show_all()
def on_button_clicked(self,widget):
dialog =Gtk.FileChooserDialog("Select folder",None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
filter = Gtk.FileFilter()
filter.set_name("Folder")
filter.add_pattern("*") # whats the pattern for a folder
dialog.add_filter(filter)
if dialog.run() == Gtk.ResponseType.ACCEPT:
dialog.hide()
print(dialog.get_filename())
self.button.set_label(dialog.get_filename())
dialog.destroy()
def __init__(self):
Gtk.Dialog.__init__(self, 'File Downloader',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.set_size_request(400, 100)
self.set_title('? ubi site file downloader')
self.connect('destroy', self.close_application)
#
vbox0 = Gtk.VBox(spacing = 10)
vbox0.set_border_width(5)
self.get_content_area().add(vbox0)
#
table1 = Gtk.Table(3,2,False)
vbox0.add(table1)
label10 = Gtk.Label('Extension:')
label10.set_alignment(0, 0.5)
table1.attach(label10,0,1,0,1)
#
self.entry10 = Gtk.Entry()
table1.attach(self.entry10,1,2,0,1)
#
label11 = Gtk.Label('Url:')
label11.set_alignment(0, 0.5)
table1.attach(label11,0,1,1,2)
#
self.entry11 = Gtk.Entry()
table1.attach(self.entry11,1,2,1,2)
#
#self.button = Gtk.Button('Select folder')
#self.button.connect('clicked',self.on_button_clicked)
#table1.attach(self.button,0,2,2,3)
#
self.show_all()
def on_button_clicked(self,widget):
dialog =Gtk.FileChooserDialog("Select folder",None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
filter = Gtk.FileFilter()
filter.set_name("Folder")
filter.add_pattern("*") # whats the pattern for a folder
dialog.add_filter(filter)
if dialog.run() == Gtk.ResponseType.ACCEPT:
dialog.hide()
print(dialog.get_filename())
self.button.set_label(dialog.get_filename())
dialog.destroy()
def show_dialog(self, gtkaction):
dialog = Gtk.Dialog(
_("Select Colour Scheme"), gv.gui.get_window(), 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
rb1 = Gtk.RadioButton.new_with_label(None, "Brown")
dialog.vbox.pack_start(rb1, False, True, 5)
rb2 = Gtk.RadioButton.new_with_label_from_widget(rb1, "Blue")
dialog.vbox.pack_start(rb2, False, True, 5)
rb3 = Gtk.RadioButton.new_with_label_from_widget(rb1, "Green")
dialog.vbox.pack_start(rb3, False, True, 5)
dialog.show_all()
dialog.set_default_response(Gtk.ResponseType.OK)
if self.colour_scheme == 0:
rb1.set_active(True)
elif self.colour_scheme == 1:
rb2.set_active(True)
elif self.colour_scheme == 2:
rb3.set_active(True)
else:
rb1.set_active()
response = dialog.run()
if response == Gtk.ResponseType.OK:
if rb1.get_active():
self.colour_scheme = 0
elif rb2.get_active():
self.colour_scheme = 1
elif rb3.get_active():
self.colour_scheme = 2
dialog.destroy()
return
def __init__(self, parent):
Gtk.Dialog.__init__(self, "Enter Password", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(150, 100)
self.input = Gtk.Entry()
self.input.set_max_length(8)
box = self.get_content_area()
box.add(self.input)
self.show_all()
def __init__(self, parent):
Gtk.Dialog.__init__(self, "File Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(500, 550)
box = self.get_content_area()
self.verticalbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
box.add(self.verticalbox)
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
from_file = Gtk.Button("From File")
from_file.connect("clicked", self.on_file)
from_clipboard = Gtk.Button("Clipboard")
from_clipboard.connect("clicked", self.on_clipboard)
hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True)
hbox1.pack_start(from_file, True, True, 0)
hbox1.pack_start(from_clipboard, True, True, 0)
self.verticalbox.pack_start(hbox1, False, False, 0)
# Just holding the Place for real treeview widget
self.scrollable_treelist = Gtk.Label()
self.verticalbox.pack_start(self.scrollable_treelist, True, True, 0)
self.show_all()
def on_open(self, widget):
"""
Open a FileChooserDialog and select a file.
Load into this editor window if it is empty and unused,
if not load into a new one.
This method will catch exceptions raised while loading the file
and display a dialog. Then it will destroy any newly created
dialog.
"""
dialog = Gtk.FileChooserDialog(None, self,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
dialog.set_current_folder(self.savedir)
ret = dialog.run()
if ret == Gtk.ResponseType.OK:
try:
new_file = decode_filename(dialog.get_filename())
assert new_file not in self.instance_dict
win = self.__class__(new_file)
win.show_all()
win.set_title(new_file)
if (not self.m_filename) and (not self.m_changed):
del self.instance_dict[self.get_idict_key()]
self.destroy()
except Exception, e:
# Since we catch all sorts of exceptions here, we don't have
# to do handle string to int conversion in
# PractiseSheet.parse_file. Just let int() raise ValueException
# if the string in not an integer.
if 'msg1' in dir(e):
solfege.win.display_error_message2(getattr(e, 'msg1', ''),
getattr(e, 'msg2', ''))
else:
display_exception_message(e)
dialog.destroy()
def get_save_as_dialog(self):
dialog = Gtk.FileChooserDialog(_("Save As..."), self,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
dialog.set_default_response(Gtk.ResponseType.OK)
return dialog
def select_empty_directory(self, title):
msg = _("Select an empty directory, since we want to fill it with files.")
dialog = Gtk.FileChooserDialog(title,
self, Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
label = Gtk.Label(label=msg)
label.show()
dialog.vbox.pack_start(label, False, False, padding=0)
while 1:
res = dialog.run()
if res in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT):
dialog.destroy()
return
elif res == Gtk.ResponseType.OK:
if os.listdir(decode_filename(dialog.get_filename())):
msg_dlg = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
Gtk.MessageType.INFO, Gtk.ButtonsType.OK, msg)
msg_dlg.run()
msg_dlg.destroy()
else:
break
ret = decode_filename(dialog.get_filename())
dialog.destroy()
return ret
def __init__(self):
Gtk.Dialog.__init__(self, _(u"_Create profile\u2026").replace(u"\u2026", "").replace("_", ""))
self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
vbox = gu.hig_dlg_vbox()
self.vbox.pack_start(vbox, True, True, 0)
#
label = Gtk.Label(label=_("Enter the name of the new folder:"))
label.set_alignment(0.0, 0.5)
vbox.pack_start(label, False, False, 0)
#
self.g_entry = Gtk.Entry()
self.g_entry.connect('changed', self.on_entry_changed)
self.g_entry.set_activates_default(True)
vbox.pack_start(self.g_entry, False, False, 0)
#
label = Gtk.Label(label=_("Your profile data will be stored in:"))
label.set_alignment(0.0, 0.5)
vbox.pack_start(label, False, False, 0)
#
self.g_profile_location = Gtk.Label()
vbox.pack_start(self.g_profile_location, False, False, 0)
#
self.g_statusbox = Gtk.HBox()
self.g_statusbox.set_no_show_all(True)
vbox.pack_start(self.g_statusbox, False, False, 0)
im = Gtk.Image()
im.set_from_stock(Gtk.STOCK_DIALOG_WARNING, Gtk.IconSize.MENU)
self.g_statusbox.pack_start(im, False, False, 0)
im.show()
self.g_status = Gtk.Label()
self.g_status.show()
self.g_statusbox.pack_start(self.g_status, False, False, 0)
self.g_entry.set_text(_("New Profile"))
self.set_default_response(Gtk.ResponseType.ACCEPT)
def show_path_info(self, w):
if not self.g_path_info_dlg:
self.g_path_info_dlg = Gtk.Dialog(_("_File locations").replace("_", ""), self,
buttons=(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
sc = Gtk.ScrolledWindow()
sc.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
self.g_path_info_dlg.vbox.pack_start(sc, True, True, 0)
#
vbox = gu.hig_dlg_vbox()
sc.add_with_viewport(vbox)
box1, box2 = gu.hig_category_vbox(_("_File locations").replace("_", ""))
vbox.pack_start(box1, True, True, 0)
sizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
# statistics.sqlite
# win32 solfegerc
# win32 langenviron.txt
box2.pack_start(gu.hig_label_widget(_("Solfege application data:"), Gtk.Label(label=filesystem.app_data()), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget(_("Solfege user data:"), Gtk.Label(label=filesystem.user_data()), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget(_("Solfege config file:"), Gtk.Label(label=filesystem.rcfile()), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget(_("Solfege installation directory:"), Gtk.Label(label=os.getcwdu()), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget(_("User manual in HTML format:"), Gtk.Label(label=os.path.join(os.getcwdu(), "help")), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget("gtk:", Gtk.Label(label=str(Gtk)), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget("pyalsa:", Gtk.Label(label=str(alsaseq)), sizegroup), False, False, 0)
box2.pack_start(gu.hig_label_widget("PYTHONHOME", Gtk.Label(os.environ.get('PYTHONHOME', 'Not defined')), sizegroup), False, False, 0)
self.g_path_info_dlg.show_all()
def f(*w):
self.g_path_info_dlg.hide()
return True
self.g_path_info_dlg.connect('response', f)
self.g_path_info_dlg.connect('delete-event', f)
sc.set_size_request(min(vbox.size_request().width + gu.hig.SPACE_LARGE * 2,
Gdk.Screen.width() * 0.9),
vbox.size_request().height)