-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtables.py
executable file
·43 lines (35 loc) · 1.25 KB
/
tables.py
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
# -*- coding: utf-8 -*-
# Copyright © 2011 by Vinay Sajip. All rights reserved. See accompanying LICENSE.txt for details.
from qt import QtCore, QtGui
import logging
logger = logging.getLogger(__name__)
class BaseTable(QtGui.QTableView):
def __init__(self, parent):
super(BaseTable, self).__init__(parent)
self._context_items = []
self.setupUi(self)
def setupUi(self, w):
pass
@property
def context_actions(self):
return self._context_items
def contextMenuEvent(self, event):
actions = list(self.context_actions)
if actions:
menu = QtGui.QMenu(self)
for action_or_menu in actions:
if isinstance(action_or_menu, QtGui.QAction):
menu.addAction(action_or_menu)
else:
menu.addMenu(action_or_menu)
menu.exec_(event.globalPos())
class MasterTable(BaseTable):
def setupUi(self, w):
super(MasterTable, self).setupUi(w)
self.action_cols = action = QtGui.QAction("&Columns", self)
self._context_items.append(action)
class DetailTable(BaseTable):
pass
class LoggerTree(QtGui.QTreeView):
def contextMenuEvent(self, event):
logger.debug('tree context event')