~mefrio-g/pybrowser/pybrowser

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.2.4-4/src/menu_setting.py

  • Committer: Mario Guerriero
  • Date: 2011-06-12 13:10:04 UTC
  • Revision ID: mefrio.g@gmail.com-20110612131004-55w85u5lmwhjkh2a
just a revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import gtk
 
2
 
 
3
import code
 
4
 
 
5
class MenuSetting(gtk.Menu):
 
6
        def __init__(self, button, webview):
 
7
                super(MenuSetting, self).__init__()
 
8
                
 
9
                self.btn = btn(button)
 
10
                self.web = web(webview)
 
11
                
 
12
                """add the menu items"""
 
13
                self.append_items()
 
14
                
 
15
        def append_items(self):
 
16
                view = self.web.get_current_view()
 
17
                
 
18
                for item in self.get_children():
 
19
                        self.remove(item)
 
20
                
 
21
                print_cb = gtk.ImageMenuItem(gtk.STOCK_PRINT, "Add page to bookmark")
 
22
                print_cb.connect("activate", lambda w: self.web.print_cb(print_cb, self.web))
 
23
                self.append(print_cb)
 
24
                print_cb.show()
 
25
                
 
26
                if view.get_view_source_mode() == False:
 
27
                        code = gtk.ImageMenuItem("Show page source code")
 
28
                        code.connect("activate", self.web.code_view)
 
29
                        self.append(code)
 
30
                        code.show()
 
31
                else:
 
32
                        code = gtk.ImageMenuItem("Show the web content")
 
33
                        code.connect("activate", self.web.code_view)
 
34
                        self.append(code)
 
35
                        code.show()
 
36
                
 
37
                sep = gtk.SeparatorMenuItem()
 
38
                self.append(sep)
 
39
                sep.show()
 
40
                
 
41
                properties = gtk.ImageMenuItem(gtk.STOCK_PROPERTIES)
 
42
                #properties.connect("activate", self.)
 
43
                self.append(properties)
 
44
                properties.show()
 
45
                
 
46
                self.connect("deactivate", lambda w: self.btn.set_sensitive(True))
 
47
                
 
48
        """general function to get the menu"""
 
49
        def get_menu(self):
 
50
                return self
 
51
                
 
52
        """function to get where the window put the menu"""
 
53
        def menu_position(self, menu, data=None):
 
54
                widget = menu.get_attach_widget()
 
55
                allocation = widget.get_allocation()
 
56
                window_pos = widget.window.get_position()
 
57
                x = window_pos[0] + allocation.x
 
58
                y = window_pos[1] + allocation.y + allocation.height
 
59
                return (x, y, True)
 
60
                
 
61
        """show the menu"""
 
62
        def show(self):
 
63
                if not self.get_attach_widget():
 
64
                        self.attach_to_widget(self.btn, None)
 
65
                self.popup(None, None, self.menu_position, 1, gtk.get_current_event_time())
 
66
                self.select_first(True)
 
67
                self.btn.set_sensitive(False)
 
68
                self.append_items()
 
69
                self.show_all()
 
70
 
 
71
def btn(btn):
 
72
        return btn
 
73
        
 
74
def web(web):
 
75
        return web