1# Orca 2# 3# Copyright 2010 Consorcio Fernando de los Rios. 4# Author: Javier Hernandez Antunez <jhernandez@emergya.es> 5# Author: Alejandro Leiva <aleiva@emergya.es> 6# 7# This library is free software; you can redistribute it and/or 8# modify it under the terms of the GNU Lesser General Public 9# License as published by the Free Software Foundation; either 10# version 2.1 of the License, or (at your option) any later version. 11# 12# This library is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# Lesser General Public License for more details. 16# 17# You should have received a copy of the GNU Lesser General Public 18# License along with this library; if not, write to the 19# Free Software Foundation, Inc., Franklin Street, Fifth Floor, 20# Boston MA 02110-1301 USA. 21 22"""Displays the Save Profile As dialog.""" 23 24__id__ = "$Id$" 25__version__ = "$Revision$" 26__date__ = "$Date$" 27__copyright__ = "Copyright (c) 2010 Consorcio Fernando de los Rios." 28__license__ = "LGPL" 29 30import locale 31import sys 32from gi.repository import Gtk 33 34from . import guilabels 35from . import orca_state 36 37OS = None 38newProfile = None 39 40class OrcaProfileGUI(Gtk.Dialog): 41 42 def __init__(self): 43 """Initialize the Orca profile configuration GUI.""" 44 45 Gtk.Dialog.__init__(self) 46 self.set_title(guilabels.PROFILE_SAVE_AS_TITLE) 47 self.set_has_resize_grip(False) 48 49 self.add_button('gtk-cancel', Gtk.ResponseType.CANCEL) 50 self.add_button('gtk-save', Gtk.ResponseType.ACCEPT) 51 52 grid = Gtk.Grid() 53 grid.set_property('margin', 12) 54 grid.set_row_spacing(10) 55 grid.set_column_spacing(10) 56 57 # Right now the content area is a GtkBox. We'll need to update 58 # this once GtkBox is fully deprecated. 59 contentArea = self.get_content_area() 60 contentArea.pack_start(grid, True, True, 0) 61 62 self.profileEntry = Gtk.Entry() 63 self.profileEntry.set_property('hexpand', True) 64 self.profileEntry.set_activates_default(True) 65 grid.attach(self.profileEntry, 1, 0, 1, 1) 66 67 label = Gtk.Label(guilabels.PROFILE_NAME_LABEL) 68 label.set_use_underline(True) 69 label.set_mnemonic_widget(self.profileEntry) 70 grid.attach(label, 0, 0, 1, 1) 71 72 defaultButton = self.get_widget_for_response(Gtk.ResponseType.ACCEPT) 73 defaultButton.set_property('can-default', True) 74 defaultButton.set_property('has-default', True) 75 76 self.connect('response', self.onResponse) 77 self.connect('destroy', self.onDestroy) 78 79 self.searchString = None 80 self.profileString = None 81 self.prefsDialog = None 82 83 def init(self): 84 self.profileString = '' 85 86 def showGUI(self, prefsDialog): 87 """Show the Save Profile As dialog.""" 88 89 self.show_all() 90 self.prefsDialog = prefsDialog 91 self.profileEntry.set_text(self.profileString) 92 93 ts = orca_state.lastInputEvent.timestamp 94 if ts == 0: 95 ts = Gtk.get_current_event_time() 96 self.present_with_time(ts) 97 98 def onResponse(self, widget, response): 99 """Signal handler for the responses emitted by the dialog.""" 100 101 if response in [Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT]: 102 self.hide() 103 return 104 105 if response == Gtk.ResponseType.ACCEPT: 106 global newProfile 107 108 newProfile = self.profileEntry.get_text() 109 if newProfile: 110 self.destroy() 111 if self.prefsDialog: 112 self.prefsDialog.saveProfile(newProfile) 113 114 def onDestroy(self, widget): 115 """Signal handler for the 'destroy' signal of the dialog.""" 116 117 global OS 118 119 OS = None 120 121def showProfileUI(prefsDialog=None): 122 global OS 123 global newProfile 124 125 newProfile = None 126 127 if not OS: 128 OS = OrcaProfileGUI() 129 OS.init() 130 131 OS.showGUI(prefsDialog) 132 133def main(): 134 locale.setlocale(locale.LC_ALL, '') 135 136 showProfileUI() 137 138 Gtk.main() 139 sys.exit(0) 140 141if __name__ == "__main__": 142 main() 143