del net-oscar
[learning-git.git] / pgworksheet_yvesf / pgw / UI.py
blob2b09702feb08b57f3d37a0c41388c863313f9dc3
1 # -*- coding: utf-8; -*-
3 # PgWorksheet - PostgreSQL Front End
4 # http://pgworksheet.projects.postgresql.org/
6 # Copyright © 2004-2005 Henri Michelon & CML http://www.e-cml.org/
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details (read LICENSE.txt).
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # $Id: UI.py,v 1.23 2005/06/10 14:22:37 hmichelon Exp $
24 import os
25 import sys
26 import ConfigParser
27 import pygtk
28 import gtk
29 import gettext; _ = gettext.gettext
31 import pgw
32 import pgw.Syntax
33 import pgw.Undo
34 import pgw.Plugin
35 import pgw.ResultView
36 import pgw.DBConnection;
37 import pgw.QueryView;
38 import pgw.ConnectDialog
39 import pgw.Widgets
42 PGW_CONNECT = 'pgw-connect'
43 PGW_CONNECTNOW = 'pgw-connectnow'
44 PGW_DISCONNECT = 'pwg-disconnect'
45 PGW_SELECTALL = 'pwg-selectall'
46 PGW_ENCODING = 'pwg-encoding'
47 PGW_ABOUT = 'pwg-about'
50 class UI(gtk.Window):
51 """UI Construction and management"""
53 def __init__(self, app, pixmap_path):
54 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
56 self.sidebar_plugins = []
57 self.db = pgw.DBConnection.DBConnection()
59 self.pixmap_path = pixmap_path
60 self.register_stock_items()
61 self.file_dialog_path = None
62 self.define_ui(app)
64 self.load_user_parameters()
65 self.show_all()
69 def on_state(self, widget, event):
70 cp = ConfigParser.ConfigParser()
71 try:
72 cp.readfp(open(pgw.get_config_path(), 'r'))
73 except IOError:
74 pass
75 if (not cp.has_section("window")):
76 cp.add_section("window")
77 if (event.new_window_state == gtk.gdk.WINDOW_STATE_MAXIMIZED):
78 cp.set("window", "maximized", "1")
79 else:
80 cp.set("window", "maximized", "0")
81 self.write_config(cp)
84 def on_configure(self, widget, event):
85 cp = ConfigParser.ConfigParser()
86 try:
87 cp.readfp(open(pgw.get_config_path(), 'r'))
88 except IOError:
89 pass
90 if (not cp.has_section("window")):
91 cp.add_section("window")
92 x, y = widget.get_position()
93 cp.set("window", "x", x)
94 cp.set("window", "y", y)
95 width, height = widget.get_size()
96 cp.set("window", "width", width)
97 cp.set("window", "height", height)
98 self.write_config(cp)
100 def on_delete(self, widget=None, event=None):
101 return False
104 def on_destroy(self, widget=None):
105 self.db.disconnect()
106 #XXX self.save_history()
107 gtk.main_quit()
108 sys.exit()
110 #####Menu
111 def on_menu_connect(self, widget):
112 """Called when the user want the connection dialog box"""
113 dlg = pgw.ConnectDialog.ConnectDialog()
114 dlg.connect("clicked-ok", self.connect_db)
115 dlg.show()
117 def connect_db(self, dialog, connectionParameter):
118 cp = connectionParameter
119 if self.db.is_connected():
120 dialog.set_error('<span foreground="#EE2222">' + _('Doing disconnect...')+'</span>')
121 self.db.disconnect()
122 dialog.set_error("")
124 try:
125 self.db.connect(cp)
126 except pgw.DBConnection.DatabaseError, errstr:
127 dialog.set_error('<span foreground="#EE2222">' + _('Connection Failed:') + "%s</span>"%errstr)
128 return False
130 if self.db.is_connected():
131 self.enable_disconnect(True)
132 return True
133 else:
134 dialog.set_error('<span foreground="#EE2222">'+_("Connection Failed")+"</span>")
135 print "Connection Failed"
136 return False
138 def on_menu_disconnect(self, widget):
139 self.db.disconnect()
140 self.enable_disconnect(False)
142 def load_user_parameters(self):
143 cp = ConfigParser.ConfigParser()
144 try:
145 cp.readfp(open(pgw.get_config_path(), 'r'))
146 maximized = 0
147 try:
148 maximized = int(cp.get("window", "maximized"))
149 except:
150 pass
151 if (maximized):
152 self.maximize()
153 else:
154 width, height = self.get_size()
155 try:
156 width = int(cp.get("window", "width"))
157 except:
158 pass
159 try:
160 height = int(cp.get("window", "height"))
161 except:
162 pass
163 self.resize(width, height)
164 x, y = self.get_position()
165 try:
166 x = int(cp.get("window", "x"))
167 except:
168 pass
169 try:
170 y = int(cp.get("window", "y"))
171 except:
172 pass
173 self.move(x, y)
174 try:
175 self.vmain.set_position(int(cp.get("window", "divider")))
176 except:
177 pass
178 except IOError:
179 pass
180 return cp
183 def message_dialog(self, msg, type, buttons = gtk.BUTTONS_OK):
184 dialog = gtk.MessageDialog(self,
185 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
186 type, buttons, msg)
187 result = dialog.run()
188 dialog.destroy()
189 return result
192 def message_box(self, msg):
193 self.message_dialog(msg, gtk.MESSAGE_INFO)
196 def error_box(self, msg):
197 self.message_dialog(msg, gtk.MESSAGE_ERROR)
200 def yesno_box(self, msg):
201 return self.message_dialog(msg, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO)
204 def file_dialog(self, msg, action = gtk.FILE_CHOOSER_ACTION_OPEN,
205 button = gtk.STOCK_OPEN):
206 fb = gtk.FileChooserDialog(msg, self,
207 action,
208 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
209 button, gtk.RESPONSE_OK))
210 if (self.file_dialog_path is not None):
211 fb.set_current_folder_uri(self.file_dialog_path)
212 fb.show_all()
213 result = fb.run()
214 if (result == gtk.RESPONSE_OK):
215 filename = fb.get_filename()
216 else:
217 filename = None
218 self.file_dialog_path = fb.get_current_folder_uri()
219 fb.destroy()
220 return filename
223 def register_stock_items(self):
224 gtk.stock_add([
225 (PGW_CONNECT, _('_Connect Server...'), gtk.gdk.CONTROL_MASK,
226 gtk.gdk.keyval_from_name('N'), None),
227 (PGW_DISCONNECT, _('_Disconnect'), 0, -1, None),
228 (PGW_SELECTALL, _('Select _All'), gtk.gdk.CONTROL_MASK,
229 gtk.gdk.keyval_from_name('A'), None),
230 (PGW_ENCODING, _('Character _Encoding'), 0, -1, None),
231 (PGW_ABOUT, _('_About...'), 0, -1, None),
232 (PGW_CONNECTNOW, _('_Connect'), 0, -1, None),
234 self.factory = gtk.IconFactory()
235 self.factory.add_default()
236 self.factory.add(PGW_CONNECTNOW, gtk.IconSet(gtk.gdk.pixbuf_new_from_file(
237 os.path.join(self.pixmap_path, "connect.png"))))
238 self.factory.add(PGW_CONNECT, gtk.IconSet(gtk.gdk.pixbuf_new_from_file(
239 os.path.join(self.pixmap_path, "connect.png"))))
240 self.factory.add(PGW_DISCONNECT, gtk.IconSet(gtk.gdk.pixbuf_new_from_file(
241 os.path.join(self.pixmap_path, "disconnect.png"))))
242 self.factory.add(PGW_ABOUT, gtk.IconSet(gtk.gdk.pixbuf_new_from_file(
243 os.path.join(self.pixmap_path, "about.png"))))
246 def define_ui(self, app):
247 self.ui = '''<ui>
248 <menubar name="MenuBar">
249 <menu action="File">
250 <menuitem action="Connect"/>
251 <menuitem action="Disconnect"/>
252 <separator/>
253 <menuitem action="Quit"/>
254 </menu>
255 <menu action="Tools">
256 <menuitem action="Run SQL"/>
257 </menu>
258 <menu action="History">
259 <menuitem action="Prev Statement"/>
260 <menuitem action="Next Statement"/>
261 </menu>
262 <menu action="Help">
263 <menuitem action="About"/>
264 </menu>
265 </menubar>
266 </ui>'''
268 self.undo = pgw.Undo.Undo()
269 self.uimanager = gtk.UIManager()
270 self.accelgroup = self.uimanager.get_accel_group()
271 self.actiongroup = gtk.ActionGroup('UIManagerMenuBar')
272 self.actiongroup.add_actions([
273 ('File', None, _('_File')),
274 ('Connect', PGW_CONNECT, None, None,
275 _('Connect to a database'), self.on_menu_connect),
276 ('Disconnect', PGW_DISCONNECT, None, '',
277 _('Disconnect from the database'), self.on_menu_disconnect),
278 ('Quit', gtk.STOCK_QUIT, None, None,
279 _('Quit the Program'), self.on_destroy),
281 self.uimanager.insert_action_group(self.actiongroup, 0)
282 self.uimanager.add_ui_from_string(self.ui)
283 # self.uimanager.get_widget('/MenuBar/Help').set_right_justified(True)
284 self.create_vpaned(app)
285 self.create_statusbar()
286 self.enable_disconnect(False)
287 # self.uimanager.get_widget('/ToolBar').set_style(gtk.TOOLBAR_ICONS)
289 self.set_title(_('PgWorksheet - PostgreSQL SQL Tool'))
290 self.set_icon_from_file(os.path.join("pixmaps/pgworksheet", "pgworksheet-32.png"))
291 self.add_accel_group(self.accelgroup)
292 self.set_default_size(640, 480)
293 self.connect('window-state-event', self.on_state)
294 self.connect('configure-event', self.on_configure)
295 self.connect('destroy', self.on_destroy)
296 self.connect('delete_event',self.on_delete)
298 hbox = gtk.VBox(False)
299 hbox.pack_start(self.uimanager.get_widget('/MenuBar'), False)
300 #hbox.pack_start(self.uimanager.get_widget('/ToolBar'), False)
301 hbox.pack_start(self.vmain, True, True)
302 hbox.pack_start(self.statusbar, False, False)
303 self.add(hbox)
306 def create_vpaned(self, app):
307 self.vmain = gtk.VPaned()
308 self.vmain.connect("event", self.on_vpaned_accept)
309 self.hmain = gtk.HPaned();
310 self.hmain.set_property("height-request", 350);
312 # scroll = gtk.ScrolledWindow()
313 # scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
314 # scroll.set_property("height-request", 150)
315 # scroll.set_shadow_type(gtk.SHADOW_NONE)
316 # self.sqlbuffer = gtk.TextBuffer()
317 # self.sqlbuffer.connect('delete-range', self.undo.text_deleted)
318 # self.sqlbuffer.connect('insert-text', self.undo.text_inserted)
319 # self.syntax = pgw.Syntax.Syntax(self.sqlbuffer)
320 # self.buffer_handlers = []
321 #XXX
322 # self.buffer_handlers.append(self.sqlbuffer.connect('delete-range',
323 # self.syntax.text_deleted))
324 # self.buffer_handlers.append(self.sqlbuffer.connect('insert-text',
325 # self.syntax.text_inserted))
326 # self.buffer_handlers.append(self.sqlbuffer.connect('changed',
327 # self.syntax.text_changed))
328 # self.buffer_handlers.append(self.sqlbuffer.connect('changed',
329 # app.on_text_change))
330 # self.sqlview = gtk.TextView(self.sqlbuffer)
331 # self.sqlview.connect('focus-in-event', app.on_sqlview_focus_in)
332 # self.sqlview.connect('focus-out-event', app.on_sqlview_focus_out)
333 # self.sqlview.connect('key-press-event', app.on_sqlview_keypress)
334 # scroll.add(self.sqlview)
335 # scroll.set_property("width-request", 380);
336 # self.hmain.pack1(scroll, resize=True, shrink=False)
337 self.resulttab = pgw.ResultView.ResultView(app)
338 self.resulttab.set_tab_pos(gtk.POS_BOTTOM)
339 self.resulttab.set_scrollable(True)
340 self.vmain.pack2(self.resulttab, resize=True, shrink=False)
344 self.sidebar = gtk.Notebook();
345 self.sidebar.set_property("width-request", 200)
346 for plugin_class in pgw.Plugin.fromPath(sys.path[0] + "/plugins/", pgw.Plugin.SidebarPlugin):
347 try:
348 child = plugin_class(self)
349 self.sidebar.add(child);
350 self.sidebar.set_tab_label(child, gtk.Label(child.name))
351 self.sidebar_plugins.append(child);
352 except Exception, errstr:
353 print child, errstr
355 self.queryview = pgw.QueryView.QueryView(self.db, self.resulttab)
356 self.queryview.set_property("width-request", 500)
357 self.hmain.pack1(self.queryview, resize=True, shrink=True)
359 self.hmain.pack2(self.sidebar, resize=True, shrink=True);
361 self.hmain.set_position(-1) #reccalculate by widget propertys
363 self.vmain.pack1(self.hmain, resize=True, shrink=False)
366 def create_statusbar(self):
367 self.statusbar = gtk.Statusbar()
368 self.statusbar.set_border_width(0)
370 f = self.statusbar.get_children()[0]
371 f.set_shadow_type(gtk.SHADOW_IN)
372 self.statusbar.set_child_packing(f, True, True, 0, gtk.PACK_START)
374 self.status_connect = gtk.Label();
375 self.status_connect.set_justify(gtk.JUSTIFY_LEFT)
376 f = gtk.Frame()
377 f.set_shadow_type(gtk.SHADOW_IN)
378 f.add(self.status_connect)
379 self.statusbar.pack_start(f, False, False)
381 f = gtk.Label(' ')
382 self.statusbar.pack_start(f, False, False)
384 self.traffic_light = pgw.Widgets.TrafficLight(False)
385 self.traffic_light.set_property("height-request", 20)
386 self.traffic_light.set_property("width-request", 14)
387 self.statusbar.pack_start(self.traffic_light, False, False)
390 def status(self, message):
391 """Update the status bar text"""
392 self.status_connect.set_markup(" " + connect + " ")
395 def setfocus_sqlbuffer(self):
396 self.sqlview.grab_focus()
399 def enable_disconnect(self, state = True):
400 self.uimanager.get_widget('/MenuBar/File/Disconnect').\
401 set_sensitive(state)
403 self.traffic_light.set(state)
405 if state == True: #that should mean we are connected now
406 for plugin in self.sidebar_plugins:
407 try:
408 plugin.on_connection()
409 except Exception, ersstr:
410 print "Exception in plugin %s"%plugin
411 print ersstr
413 def get_text(self, buffer):
414 """Return the text of a widget"""
415 c1 = buffer.get_start_iter()
416 c2 = buffer.get_end_iter()
417 return buffer.get_slice(c1, c2, True)
420 def get_sqlbuffer_text(self):
421 return self.get_text(self.sqlbuffer)
424 def set_sqlbuffer_text(self, text):
425 self.sqlbuffer.set_text(text)
428 def on_connect_event(self, widget, event):
429 if ((not self.entry_password.is_focus()) and
430 self.viewconn.is_focus()):
431 self.entry_password.grab_focus()
434 def connect_dialog(self):
435 dlg = gtk.Dialog(_('Database connection'),
436 self,
437 gtk.DIALOG_MODAL or gtk.DIALOG_DESTROY_WITH_PARENT,
438 ((gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
439 PGW_CONNECTNOW, gtk.RESPONSE_OK)))
440 dlg.set_resizable(False)
442 mbox = gtk.HBox()
443 box = gtk.Frame()
444 self.storeconn = gtk.ListStore(str, str)
445 self.viewconn = gtk.TreeView(self.storeconn)
446 cell = gtk.CellRendererText()
447 column = gtk.TreeViewColumn(_('5 Previous connections'))
448 column.pack_start(cell, True)
449 column.add_attribute(cell, 'text', 0)
450 column.set_sort_column_id(0)
451 self.viewconn.append_column(column)
452 self.viewconn.connect('cursor-changed', self.on_dlgconnect_change)
453 box.add(self.viewconn)
454 mbox.pack_start(box, True, True)
456 hbox = gtk.HBox(False)
457 hbox.set_border_width(10)
458 hbox.set_spacing(10)
460 box = gtk.VBox(True)
461 box.set_spacing(10)
462 lbl = gtk.Label(_('Host'))
463 lbl.set_alignment(0, 0.1)
464 box.pack_start(lbl, True, True)
465 lbl = gtk.Label(_('Port'))
466 lbl.set_alignment(0, 0.1)
467 box.pack_start(lbl, True, True)
468 lbl = gtk.Label(_('User'))
469 lbl.set_alignment(0, 0.1)
470 box.pack_start(lbl, True, True)
471 lbl = gtk.Label(_('Password'))
472 lbl.set_alignment(0, 0.1)
473 box.pack_start(lbl, True, True)
474 lbl = gtk.Label(_('Database'))
475 lbl.set_alignment(0, 0.1)
476 box.pack_start(lbl, True, True)
477 hbox.pack_start(box, False, False)
479 box = gtk.VBox(False)
480 box.set_spacing(10)
481 self.entry_host = gtk.Entry()
482 self.entry_host.connect('activate', lambda w: dlg.response(gtk.RESPONSE_OK))
483 box.pack_start(self.entry_host, True, True)
484 self.entry_port = gtk.Entry()
485 self.entry_port.connect('activate', lambda w: dlg.response(gtk.RESPONSE_OK))
486 box.pack_start(self.entry_port, True, True)
487 self.entry_user = gtk.Entry()
488 self.entry_user.connect('activate', lambda w: dlg.response(gtk.RESPONSE_OK))
489 box.pack_start(self.entry_user, True, True)
490 self.entry_password = gtk.Entry()
491 self.entry_password.set_visibility(False)
492 self.entry_password.connect('activate', lambda w: dlg.response(gtk.RESPONSE_OK))
493 box.pack_start(self.entry_password, True, True)
494 self.entry_database = gtk.Entry()
495 self.entry_database.connect('activate', lambda w: dlg.response(gtk.RESPONSE_OK))
496 box.pack_start(self.entry_database, True, True)
497 hbox.pack_start(box, True, True)
499 mbox.pack_start(hbox, True, True)
501 dlg.vbox.pack_start(mbox, True, True, 0)
502 app.on_dlgconnect_map(None)
503 if (overwrite_entry or (not self.storeconn.iter_n_children(None))):
504 self.entry_host.set_text(host)
505 self.entry_port.set_text(str(port))
506 self.entry_user.set_text(user)
507 self.entry_database.set_text(database)
508 dlg.set_default_response(gtk.RESPONSE_OK)
509 dlg.connect('event-after', self.on_connect_event)
510 dlg.vbox.show_all()
511 self.entry_password.grab_focus()
512 result = None
513 if (dlg.run() == gtk.RESPONSE_OK):
514 result = (self.entry_host.get_text(),
515 self.entry_port.get_text(),
516 self.entry_user.get_text(),
517 self.entry_password.get_text(),
518 self.entry_database.get_text())
519 dlg.destroy()
520 return result
523 def write_config(self, cp):
524 try:
525 cp.write(open(pgw.get_config_path(), 'w'))
526 except IOError:
527 pass
530 def on_vpaned_accept(self, widget, event):
531 cp = ConfigParser.ConfigParser()
532 try:
533 cp.readfp(open(pgw.get_config_path(), 'r'))
534 except IOError:
535 pass
536 if (not cp.has_section("window")):
537 cp.add_section("window")
538 cp.set("window", "divider", str(widget.get_position()))
539 self.write_config(cp)
542 def about_dialog(self):
543 dlg = gtk.Dialog(_('About PgWorksheet'),
544 self,
545 gtk.DIALOG_MODAL or gtk.DIALOG_DESTROY_WITH_PARENT,
546 ((gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)))
547 nbk = gtk.Notebook()
549 box = gtk.VBox(False)
551 lbl = gtk.Label()
552 lbl.set_markup('''
553 <b>PgWorksheet - PostgreSQL Front End</b>
554 Version ''' + """self.app_version""" + '''
555 <u>http://pgworksheet.projects.postgresql.org/</u>
557 Copyright © 2004-2005, Henri Michelon and CML
558 <u>http://www.e-cml.org/</u>
559 ''')
560 lbl.set_justify(gtk.JUSTIFY_CENTER)
561 lbl.set_padding(10, 10)
562 box.pack_start(lbl, True)
563 lbl = gtk.Label()
564 lbl.set_markup('''
565 <b>Internationalization:</b>
566 French : Henri Michelon &lt;hmichelon@e-cml.org&gt;
567 Japanese : Tadashi Jokagi &lt;elf2000@users.sourceforge.net&gt;
568 ''')
569 lbl.set_padding(10, 0)
570 box.pack_start(lbl, True)
571 pix = gtk.Image()
572 pix.set_from_file(os.path.join(self.pixmap_path, "pgworksheet.png"))
573 pix.set_padding(10, 10)
574 box.pack_start(pix, False)
575 nbk.append_page(box, gtk.Label(_('About')))
577 txt = gtk.TextBuffer()
578 txt.set_text('''
579 GNU GENERAL PUBLIC LICENSE
580 Version 2, June 1991
582 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
583 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
584 Everyone is permitted to copy and distribute verbatim copies
585 of this license document, but changing it is not allowed.
587 Preamble
589 The licenses for most software are designed to take away your
590 freedom to share and change it. By contrast, the GNU General Public
591 License is intended to guarantee your freedom to share and change free
592 software--to make sure the software is free for all its users. This
593 General Public License applies to most of the Free Software
594 Foundation's software and to any other program whose authors commit to
595 using it. (Some other Free Software Foundation software is covered by
596 the GNU Library General Public License instead.) You can apply it to
597 your programs, too.
599 When we speak of free software, we are referring to freedom, not
600 price. Our General Public Licenses are designed to make sure that you
601 have the freedom to distribute copies of free software (and charge for
602 this service if you wish), that you receive source code or can get it
603 if you want it, that you can change the software or use pieces of it
604 in new free programs; and that you know you can do these things.
606 To protect your rights, we need to make restrictions that forbid
607 anyone to deny you these rights or to ask you to surrender the rights.
608 These restrictions translate to certain responsibilities for you if you
609 distribute copies of the software, or if you modify it.
611 For example, if you distribute copies of such a program, whether
612 gratis or for a fee, you must give the recipients all the rights that
613 you have. You must make sure that they, too, receive or can get the
614 source code. And you must show them these terms so they know their
615 rights.
617 We protect your rights with two steps: (1) copyright the software, and
618 (2) offer you this license which gives you legal permission to copy,
619 distribute and/or modify the software.
621 Also, for each author's protection and ours, we want to make certain
622 that everyone understands that there is no warranty for this free
623 software. If the software is modified by someone else and passed on, we
624 want its recipients to know that what they have is not the original, so
625 that any problems introduced by others will not reflect on the original
626 authors' reputations.
628 Finally, any free program is threatened constantly by software
629 patents. We wish to avoid the danger that redistributors of a free
630 program will individually obtain patent licenses, in effect making the
631 program proprietary. To prevent this, we have made it clear that any
632 patent must be licensed for everyone's free use or not licensed at all.
634 The precise terms and conditions for copying, distribution and
635 modification follow.
637 GNU GENERAL PUBLIC LICENSE
638 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
640 0. This License applies to any program or other work which contains
641 a notice placed by the copyright holder saying it may be distributed
642 under the terms of this General Public License. The "Program", below,
643 refers to any such program or work, and a "work based on the Program"
644 means either the Program or any derivative work under copyright law:
645 that is to say, a work containing the Program or a portion of it,
646 either verbatim or with modifications and/or translated into another
647 language. (Hereinafter, translation is included without limitation in
648 the term "modification".) Each licensee is addressed as "you".
650 Activities other than copying, distribution and modification are not
651 covered by this License; they are outside its scope. The act of
652 running the Program is not restricted, and the output from the Program
653 is covered only if its contents constitute a work based on the
654 Program (independent of having been made by running the Program).
655 Whether that is true depends on what the Program does.
657 1. You may copy and distribute verbatim copies of the Program's
658 source code as you receive it, in any medium, provided that you
659 conspicuously and appropriately publish on each copy an appropriate
660 copyright notice and disclaimer of warranty; keep intact all the
661 notices that refer to this License and to the absence of any warranty;
662 and give any other recipients of the Program a copy of this License
663 along with the Program.
665 You may charge a fee for the physical act of transferring a copy, and
666 you may at your option offer warranty protection in exchange for a fee.
668 2. You may modify your copy or copies of the Program or any portion
669 of it, thus forming a work based on the Program, and copy and
670 distribute such modifications or work under the terms of Section 1
671 above, provided that you also meet all of these conditions:
673 a) You must cause the modified files to carry prominent notices
674 stating that you changed the files and the date of any change.
676 b) You must cause any work that you distribute or publish, that in
677 whole or in part contains or is derived from the Program or any
678 part thereof, to be licensed as a whole at no charge to all third
679 parties under the terms of this License.
681 c) If the modified program normally reads commands interactively
682 when run, you must cause it, when started running for such
683 interactive use in the most ordinary way, to print or display an
684 announcement including an appropriate copyright notice and a
685 notice that there is no warranty (or else, saying that you provide
686 a warranty) and that users may redistribute the program under
687 these conditions, and telling the user how to view a copy of this
688 License. (Exception: if the Program itself is interactive but
689 does not normally print such an announcement, your work based on
690 the Program is not required to print an announcement.)
692 These requirements apply to the modified work as a whole. If
693 identifiable sections of that work are not derived from the Program,
694 and can be reasonably considered independent and separate works in
695 themselves, then this License, and its terms, do not apply to those
696 sections when you distribute them as separate works. But when you
697 distribute the same sections as part of a whole which is a work based
698 on the Program, the distribution of the whole must be on the terms of
699 this License, whose permissions for other licensees extend to the
700 entire whole, and thus to each and every part regardless of who wrote it.
702 Thus, it is not the intent of this section to claim rights or contest
703 your rights to work written entirely by you; rather, the intent is to
704 exercise the right to control the distribution of derivative or
705 collective works based on the Program.
707 In addition, mere aggregation of another work not based on the Program
708 with the Program (or with a work based on the Program) on a volume of
709 a storage or distribution medium does not bring the other work under
710 the scope of this License.
712 3. You may copy and distribute the Program (or a work based on it,
713 under Section 2) in object code or executable form under the terms of
714 Sections 1 and 2 above provided that you also do one of the following:
716 a) Accompany it with the complete corresponding machine-readable
717 source code, which must be distributed under the terms of Sections
718 1 and 2 above on a medium customarily used for software interchange; or,
720 b) Accompany it with a written offer, valid for at least three
721 years, to give any third party, for a charge no more than your
722 cost of physically performing source distribution, a complete
723 machine-readable copy of the corresponding source code, to be
724 distributed under the terms of Sections 1 and 2 above on a medium
725 customarily used for software interchange; or,
727 c) Accompany it with the information you received as to the offer
728 to distribute corresponding source code. (This alternative is
729 allowed only for noncommercial distribution and only if you
730 received the program in object code or executable form with such
731 an offer, in accord with Subsection b above.)
733 The source code for a work means the preferred form of the work for
734 making modifications to it. For an executable work, complete source
735 code means all the source code for all modules it contains, plus any
736 associated interface definition files, plus the scripts used to
737 control compilation and installation of the executable. However, as a
738 special exception, the source code distributed need not include
739 anything that is normally distributed (in either source or binary
740 form) with the major components (compiler, kernel, and so on) of the
741 operating system on which the executable runs, unless that component
742 itself accompanies the executable.
744 If distribution of executable or object code is made by offering
745 access to copy from a designated place, then offering equivalent
746 access to copy the source code from the same place counts as
747 distribution of the source code, even though third parties are not
748 compelled to copy the source along with the object code.
750 4. You may not copy, modify, sublicense, or distribute the Program
751 except as expressly provided under this License. Any attempt
752 otherwise to copy, modify, sublicense or distribute the Program is
753 void, and will automatically terminate your rights under this License.
754 However, parties who have received copies, or rights, from you under
755 this License will not have their licenses terminated so long as such
756 parties remain in full compliance.
758 5. You are not required to accept this License, since you have not
759 signed it. However, nothing else grants you permission to modify or
760 distribute the Program or its derivative works. These actions are
761 prohibited by law if you do not accept this License. Therefore, by
762 modifying or distributing the Program (or any work based on the
763 Program), you indicate your acceptance of this License to do so, and
764 all its terms and conditions for copying, distributing or modifying
765 the Program or works based on it.
767 6. Each time you redistribute the Program (or any work based on the
768 Program), the recipient automatically receives a license from the
769 original licensor to copy, distribute or modify the Program subject to
770 these terms and conditions. You may not impose any further
771 restrictions on the recipients' exercise of the rights granted herein.
772 You are not responsible for enforcing compliance by third parties to
773 this License.
775 7. If, as a consequence of a court judgment or allegation of patent
776 infringement or for any other reason (not limited to patent issues),
777 conditions are imposed on you (whether by court order, agreement or
778 otherwise) that contradict the conditions of this License, they do not
779 excuse you from the conditions of this License. If you cannot
780 distribute so as to satisfy simultaneously your obligations under this
781 License and any other pertinent obligations, then as a consequence you
782 may not distribute the Program at all. For example, if a patent
783 license would not permit royalty-free redistribution of the Program by
784 all those who receive copies directly or indirectly through you, then
785 the only way you could satisfy both it and this License would be to
786 refrain entirely from distribution of the Program.
788 If any portion of this section is held invalid or unenforceable under
789 any particular circumstance, the balance of the section is intended to
790 apply and the section as a whole is intended to apply in other
791 circumstances.
793 It is not the purpose of this section to induce you to infringe any
794 patents or other property right claims or to contest validity of any
795 such claims; this section has the sole purpose of protecting the
796 integrity of the free software distribution system, which is
797 implemented by public license practices. Many people have made
798 generous contributions to the wide range of software distributed
799 through that system in reliance on consistent application of that
800 system; it is up to the author/donor to decide if he or she is willing
801 to distribute software through any other system and a licensee cannot
802 impose that choice.
804 This section is intended to make thoroughly clear what is believed to
805 be a consequence of the rest of this License.
807 8. If the distribution and/or use of the Program is restricted in
808 certain countries either by patents or by copyrighted interfaces, the
809 original copyright holder who places the Program under this License
810 may add an explicit geographical distribution limitation excluding
811 those countries, so that distribution is permitted only in or among
812 countries not thus excluded. In such case, this License incorporates
813 the limitation as if written in the body of this License.
815 9. The Free Software Foundation may publish revised and/or new versions
816 of the General Public License from time to time. Such new versions will
817 be similar in spirit to the present version, but may differ in detail to
818 address new problems or concerns.
820 Each version is given a distinguishing version number. If the Program
821 specifies a version number of this License which applies to it and "any
822 later version", you have the option of following the terms and conditions
823 either of that version or of any later version published by the Free
824 Software Foundation. If the Program does not specify a version number of
825 this License, you may choose any version ever published by the Free Software
826 Foundation.
828 10. If you wish to incorporate parts of the Program into other free
829 programs whose distribution conditions are different, write to the author
830 to ask for permission. For software which is copyrighted by the Free
831 Software Foundation, write to the Free Software Foundation; we sometimes
832 make exceptions for this. Our decision will be guided by the two goals
833 of preserving the free status of all derivatives of our free software and
834 of promoting the sharing and reuse of software generally.
836 NO WARRANTY
838 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
839 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
840 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
841 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
842 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
843 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
844 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
845 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
846 REPAIR OR CORRECTION.
848 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
849 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
850 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
851 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
852 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
853 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
854 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
855 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
856 POSSIBILITY OF SUCH DAMAGES.
858 END OF TERMS AND CONDITIONS
860 How to Apply These Terms to Your New Programs
862 If you develop a new program, and you want it to be of the greatest
863 possible use to the public, the best way to achieve this is to make it
864 free software which everyone can redistribute and change under these terms.
866 To do so, attach the following notices to the program. It is safest
867 to attach them to the start of each source file to most effectively
868 convey the exclusion of warranty; and each file should have at least
869 the "copyright" line and a pointer to where the full notice is found.
871 <one line to give the program's name and a brief idea of what it does.>
872 Copyright (C) <year> <name of author>
874 This program is free software; you can redistribute it and/or modify
875 it under the terms of the GNU General Public License as published by
876 the Free Software Foundation; either version 2 of the License, or
877 (at your option) any later version.
879 This program is distributed in the hope that it will be useful,
880 but WITHOUT ANY WARRANTY; without even the implied warranty of
881 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
882 GNU General Public License for more details.
884 You should have received a copy of the GNU General Public License
885 along with this program; if not, write to the Free Software
886 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
889 Also add information on how to contact you by electronic and paper mail.
891 If the program is interactive, make it output a short notice like this
892 when it starts in an interactive mode:
894 Gnomovision version 69, Copyright (C) year name of author
895 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
896 This is free software, and you are welcome to redistribute it
897 under certain conditions; type `show c' for details.
899 The hypothetical commands `show w' and `show c' should show the appropriate
900 parts of the General Public License. Of course, the commands you use may
901 be called something other than `show w' and `show c'; they could even be
902 mouse-clicks or menu items--whatever suits your program.
904 You should also get your employer (if you work as a programmer) or your
905 school, if any, to sign a "copyright disclaimer" for the program, if
906 necessary. Here is a sample; alter the names:
908 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
909 `Gnomovision' (which makes passes at compilers) written by James Hacker.
911 <signature of Ty Coon>, 1 April 1989
912 Ty Coon, President of Vice
914 This General Public License does not permit incorporating your program into
915 proprietary programs. If your program is a subroutine library, you may
916 consider it more useful to permit linking proprietary applications with the
917 library. If this is what you want to do, use the GNU Library General
918 Public License instead of this License.
919 ''')
920 scroll = gtk.ScrolledWindow()
921 scroll.add(gtk.TextView(txt))
922 nbk.append_page(scroll, gtk.Label(_('License')))
924 dlg.vbox.pack_start(nbk, True, True, 0)
925 nbk.show_all()
926 dlg.run()
927 dlg.destroy()
931 if __name__ == "__main__":
932 window = UI.new()
933 window.show_all()
934 gtk.main()