Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit 16da12b

Browse files
committed
code cleanup
1 parent e2a6e8e commit 16da12b

File tree

5 files changed

+41
-53
lines changed

5 files changed

+41
-53
lines changed

pugdebug/gui/documents.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
__author__ = "robertbasic"
1111

12+
from PyQt5.QtCore import Qt, pyqtSignal
13+
from PyQt5.QtWidgets import QTabWidget, QTabBar
1214

13-
from PyQt5.QtWidgets import QTabWidget
14-
from pugdebug.gui.widgets.tabbar import PugdebugTabBar;
1515

1616
class PugdebugDocumentViewer(QTabWidget):
1717

@@ -75,3 +75,40 @@ def get_document_by_path(self, path):
7575
def remove_line_highlights(self):
7676
for index, path in self.tabs.items():
7777
self.widget(index).remove_line_highlights()
78+
79+
80+
class PugdebugTabBar(QTabBar):
81+
"""Adds a signal when the middle button is clicked to the QTabBar widget.
82+
83+
A click is defined as a press event followed by a release event over the
84+
same tab.
85+
86+
Stolen from: http://stackoverflow.com/a/9445581/84245
87+
"""
88+
middle_clicked_signal = pyqtSignal(int)
89+
90+
def __init__(self):
91+
super(QTabBar, self).__init__()
92+
self.previousMiddleIndex = -1
93+
94+
def mousePressEvent(self, mouseEvent):
95+
"""Triggered when a mouse button is pressed.
96+
97+
If it's the middle button, remember which over which tab it
98+
was pressed.
99+
"""
100+
if mouseEvent.button() == Qt.MidButton:
101+
self.previousIndex = self.tabAt(mouseEvent.pos())
102+
QTabBar.mousePressEvent(self, mouseEvent)
103+
104+
def mouseReleaseEvent(self, mouseEvent):
105+
"""Triggered when a mouse button is released.
106+
107+
If a middle button was pressed previously, and if it is released over
108+
the same tab, emit the signal.
109+
"""
110+
if (mouseEvent.button() == Qt.MidButton and
111+
self.previousIndex == self.tabAt(mouseEvent.pos())):
112+
self.middle_clicked_signal.emit(self.previousIndex)
113+
self.previousIndex = -1
114+
QTabBar.mouseReleaseEvent(self, mouseEvent)

pugdebug/gui/expressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def set_variable(self, parent, index, variable):
157157
value = self.decode_value(variable)
158158

159159
item = parent.child(index)
160-
if item == None:
160+
if item is None:
161161
# Item does not exist, create it
162162
item = QTreeWidgetItem([name, type, value])
163163
parent.insertChild(index, item)

pugdebug/gui/stacktraces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__author__ = "robertbasic"
1111

12-
from PyQt5.QtCore import Qt, pyqtSignal
12+
from PyQt5.QtCore import pyqtSignal
1313
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem
1414

1515

pugdebug/gui/widgets/__init__.py

Whitespace-only changes.

pugdebug/gui/widgets/tabbar.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)