Menu

[r235]: / trunk / QCustomTabWidget.py  Maximize  Restore  History

Download this file

77 lines (70 with data), 3.2 kB

 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
import os, utils, gettext
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from QTextArea import QTextArea
from QCustomTabBar import QCustomTabBar
import globalvars as g
#Locale support
try:
LOCALE_DIR = "locale"
t = gettext.translation("main", LOCALE_DIR)
_ = t.ugettext
except:
_ = utils.fake_locale
class QCustomTabWidget(QTabWidget):
def __init__(self, parent=None):
QTabWidget.__init__(self, parent)
self.parent = parent
self.addTabButton = QPushButton("+")
self.addTabButton.setObjectName("addTabButton")
self.removeTabButton = QPushButton("-")
self.removeTabButton.setObjectName("removeTabButton")
self.setCornerWidget(self.addTabButton, Qt.TopRightCorner)
self.setCornerWidget(self.removeTabButton, Qt.TopLeftCorner)
self.setTabBar(QCustomTabBar(self)) ###TODO http://bugreports.qt.nokia.com/browse/QTBUG-12697
self.setObjectName("mainTabWidget")
self.setMovable(True)
self.setTabsClosable(True)
self.connect(self, QtCore.SIGNAL("tabCloseRequested(int)"), self.tabRemoveRequested)
self.connect(self.addTabButton, QtCore.SIGNAL("clicked()"), self.tabAddRequested)
self.connect(self.removeTabButton, QtCore.SIGNAL("clicked()"), self.tabRemoveRequested)
def tabAddRequested(self):
self.insertTab(self.count(), QTextArea(self), "jake" + str(self.count()+1)) ###TODO move tab prefix to jake plugin maybe?
#
def tabRemoveRequested(self, i=None): #
if self.count() > 1: #
if i == None: #
self.currentWidget().close() #
else: #
self.widget(i).close() #
if self.count() == 1: #
self.setTabText(0, "jake" + str(self.count())) ############################
def cmCCP(self, e):
cmenu = QMenu()
cutAction = cmenu.addAction(_("Cut"))
copyAction = cmenu.addAction(_("Copy"))
pasteAction = cmenu.addAction(_("Paste"))
action = cmenu.exec_(self.mapToGlobal(e.pos()))
if action == cutAction:
self.cmcut()
elif action == copyAction:
self.cmcopy()
elif action == pasteAction:
self.cmpaste()
def cmcut(self):
cursor = self.currentWidget().child().textCursor()
qcursor = self.currentWidget().child().getCursor()
if cursor.selectionStart() > qcursor.lastEnterPos-len(g.cursorChar):
selection = cursor.selection().toPlainText()
cursor.removeSelectedText()
QApplication.clipboard().setText(selection)
def cmcopy(self):
QApplication.clipboard().setText(self.currentWidget().child().textCursor().selection().toPlainText())
def cmpaste(self):
cursor = self.currentWidget().child().getCursor()
s = QApplication.clipboard().text()
cursor.deleteCursorChar()
cursor.insertText(s)
cursor.insertText(g.cursorChar)