File: MetaDataDialog.py

package info (click to toggle)
lodju 2.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 456 kB
  • ctags: 814
  • sloc: python: 4,698; ansic: 139; makefile: 64; sh: 21
file content (57 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gtk
import MetaDataEditor


class View:

    def __init__(self, dummy, title):
	self.title = title
    	self.controller = Controller(self)
    	self.widget = None
	self.editor = None

    def show(self, attrlist, metadata):
	self.widget = gtk.Dialog()
	self.widget.set_default_size(300, 300)
	self.widget.set_title(self.title)
	self.widget.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
	self.widget.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
	self.widget.connect("response", self.controller.response)
	
    	table = gtk.Table()
	self.editor = MetaDataEditor.View(table, self.controller.ok)
    	self.editor.setup(attrlist, [metadata])

    	scrolled = gtk.ScrolledWindow()
	scrolled.add_with_viewport(table)
	scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
	self.widget.vbox.pack_start(scrolled, gtk.TRUE, gtk.TRUE)

    	self.widget.show_all()

    def hide(self):
    	self.widget.destroy()


class Controller:

    def __init__(self, view):
    	self.view = view

    def ok(self):
    	self.view.hide()

    def response(self, *args):
	id = args[1]
	if id in [gtk.RESPONSE_OK, 
	    	  gtk.RESPONSE_CLOSE, 
		  gtk.RESPONSE_DELETE_EVENT]:
	    self.view.hide()
	elif id == gtk.RESPONSE_CANCEL:
	    self.view.hide()
	    if self.view.editor:
		self.view.editor.controller.restore()
    	else:
	    # Unknown response, shouldn't be possible.
	    print "other", id
	    self.view.hide()