Skip to content

Commit a36adb1

Browse files
authored
Merge pull request #284 from etetoolkit/qt5
add Qt5 support
2 parents 1bb716b + 0d37aff commit a36adb1

23 files changed

Lines changed: 841 additions & 800 deletions

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ python:
55
- "2.7"
66
- "3.4"
77
- "3.5"
8-
8+
- "3.6"
99

1010
cache:
1111
directories:
1212
- test_tmp
1313

1414
install:
15-
- ./run_tests.sh --setup-only -sv "$TRAVIS_PYTHON_VERSION"
15+
- ./run_tests.sh -s --setup-only -v "$TRAVIS_PYTHON_VERSION"
1616

1717
before_script:
1818
# Ensure tags are available on the cloned repository
@@ -24,6 +24,7 @@ before_script:
2424

2525
script:
2626
- ./run_tests.sh --test-only -sv "$TRAVIS_PYTHON_VERSION"
27+
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then ./run_tests.sh --qt4 -sv "$TRAVIS_PYTHON_VERSION" ; fi
2728
#- coverage run -m ete3.test.test_api
2829
#- coverage run -a -m ete3.test.test_ete_evol # too heavy for travis
2930
#- coverage run -a -m ete3.test.test_ete_build # too heavy for travis

ete3/test/test_treeview/item_faces.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
# We will need to create Qt4 items
2-
from PyQt4 import QtCore
3-
from PyQt4.QtGui import QGraphicsRectItem, QGraphicsSimpleTextItem, \
4-
QGraphicsEllipseItem, QColor, QPen, QBrush
5-
6-
from ... import Tree, faces, TreeStyle, NodeStyle
7-
81
# To play with random colors
92
import colorsys
103
import random
114

5+
from ... import Tree, faces, TreeStyle, NodeStyle, Face
6+
7+
# We will need to create Qt4 items
8+
from ...treeview.qt import QtCore, Qt
9+
from ...treeview.qt import QGraphicsRectItem, QGraphicsSimpleTextItem, \
10+
QGraphicsEllipseItem, QColor, QPen, QBrush
11+
1212
class InteractiveItem(QGraphicsRectItem):
1313
def __init__(self, *arg, **karg):
1414
QGraphicsRectItem.__init__(self, *arg, **karg)
1515
self.node = None
1616
self.label = None
1717
self.setCursor(QtCore.Qt.PointingHandCursor)
18-
self.setAcceptsHoverEvents(True)
1918

2019
def hoverEnterEvent (self, e):
2120
# There are many ways of adding interactive elements. With the
@@ -39,6 +38,7 @@ def hoverLeaveEvent(self, e):
3938
if self.label:
4039
self.label.setVisible(False)
4140

41+
4242
def random_color(h=None):
4343
"""Generates a random color in RGB format."""
4444
if not h:
@@ -58,17 +58,19 @@ def ugly_name_face(node, *args, **kargs):
5858

5959
# receive an arbitrary number of arguments, in this case width and
6060
# height of the faces
61-
width = args[0][0]
62-
height = args[0][1]
61+
width = args[0]
62+
height = args[1]
6363

6464
## Creates a main master Item that will contain all other elements
6565
## Items can be standard QGraphicsItem
6666
# masterItem = QGraphicsRectItem(0, 0, width, height)
6767

6868
# Or your custom Items, in which you can re-implement interactive
6969
# functions, etc. Check QGraphicsItem doc for details.
70-
masterItem = InteractiveItem(0, 0, width, height)
7170

71+
masterItem = InteractiveItem(0, 0, width, height)
72+
masterItem.setAcceptHoverEvents(True)
73+
7274
# Keep a link within the item to access node info
7375
masterItem.node = node
7476

ete3/test/test_treeview/new_seq_face.py

Lines changed: 8 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# We will need to create Qt4 items
2-
from PyQt4 import QtCore
3-
from PyQt4.QtGui import QGraphicsRectItem, QColor, QPen, QBrush
4-
from PyQt4.QtGui import QGraphicsSimpleTextItem, QFont
2+
from ...treeview.qt import QtCore
3+
from ...treeview.qt import QGraphicsRectItem, QColor, QPen, QBrush
4+
from ...treeview.qt import QGraphicsSimpleTextItem, QFont
55

6-
from ... import faces, TreeStyle, PhyloTree, TextFace
6+
from ... import faces, TreeStyle, PhyloTree, TextFace, SequenceFace
77
from random import random
88

99
_aafgcolors = {
@@ -87,130 +87,6 @@
8787
}
8888

8989

90-
class MySequenceFace(faces.StaticItemFace):
91-
""" Creates a new molecular sequence face object.
92-
93-
94-
:argument seq: Sequence string to be drawn
95-
:argument seqtype: Type of sequence: "nt" or "aa"
96-
:argument fsize: Font size, (default=10)
97-
98-
You can set custom colors for amino-acids or nucleotides:
99-
100-
:argument None codon : a string that corresponds to the reverse translation of the amino-acid sequence
101-
:argument 11 col_w : width of the column (if col_w is lower than font size, letter wont be displayed)
102-
:argument None fg_colors : dictionary of colors for foreground, with as keys each possible character in sequences, and as value the colors
103-
:argument None bg_colors : dictionary of colors for background, with as keys each possible character in sequences, and as value the colors
104-
:argument 3 alt_col_w : works together with special_col option, defines the width of given columns
105-
:argument None special_col : list of lists containing the bounds of columns to be displayed with alt_col_w as width
106-
:argument False interactive : more info can be displayed when mouse over sequence
107-
108-
"""
109-
def __init__(self, seq, seqtype="aa", fsize=10,
110-
fg_colors=None, bg_colors=None,
111-
codon=None, col_w=11, alt_col_w=3,
112-
special_col=None, interactive=False):
113-
self.seq = seq
114-
self.codon = codon
115-
self.fsize = fsize
116-
self.style = seqtype
117-
self.col_w = float(col_w)
118-
self.alt_col_w = float(alt_col_w)
119-
self.special_col = special_col if special_col else []
120-
self.width = 0 # will store the width of the whole sequence
121-
self.interact = interactive
122-
123-
if self.style == "aa":
124-
if not fg_colors:
125-
fg_colors = _aafgcolors
126-
if not bg_colors:
127-
bg_colors = _aabgcolors
128-
else:
129-
if not fg_colors:
130-
fg_colors = _ntfgcolors
131-
if not bg_colors:
132-
bg_colors = _ntbgcolors
133-
134-
self.fg_col = self.__init_col(fg_colors)
135-
self.bg_col = self.__init_col(bg_colors)
136-
137-
# for future?
138-
self.row_h = 13.0
139-
140-
super(MySequenceFace,
141-
self).__init__(QGraphicsRectItem(0, 0, self.width, self.row_h))
142-
143-
def __init_col(self, color_dic):
144-
"""to speed up the drawing of colored rectangles and characters"""
145-
new_color_dic = {}
146-
for car in color_dic:
147-
new_color_dic[car] = QBrush(QColor(color_dic[car]))
148-
return new_color_dic
149-
150-
def update_items(self):
151-
#self.item = QGraphicsRectItem(0,0,self._total_w, self.row_h)
152-
seq_width = 0
153-
nopen = QPen(QtCore.Qt.NoPen)
154-
font = QFont("Courier", self.fsize)
155-
rect_cls = self.InteractiveLetterItem if self.interact else QGraphicsRectItem
156-
for i, letter in enumerate(self.seq):
157-
width = self.col_w
158-
for m in self.special_col:
159-
if m[0] < i <= m[1]:
160-
width = self.alt_col_w
161-
break
162-
#load interactive item if called correspondingly
163-
rectItem = rect_cls(0, 0, width, self.row_h, parent=self.item)
164-
rectItem.setX(seq_width) # to give correct X to children item
165-
rectItem.setBrush(self.bg_col[letter])
166-
rectItem.setPen(nopen)
167-
if self.interact:
168-
if self.codon:
169-
rectItem.codon = '%s, %d: %s' % (self.seq[i], i,
170-
self.codon[i*3:i*3+3])
171-
else:
172-
rectItem.codon = '%s, %d' % (self.seq[i], i)
173-
# write letter if enough space
174-
if width >= self.fsize:
175-
text = QGraphicsSimpleTextItem(letter, parent=rectItem)
176-
text.setFont(font)
177-
text.setBrush(self.fg_col[letter])
178-
# Center text according to rectItem size
179-
tw = text.boundingRect().width()
180-
th = text.boundingRect().height()
181-
text.setPos((width - tw)/2, (self.row_h - th)/2)
182-
seq_width += width
183-
self.width = seq_width
184-
185-
class InteractiveLetterItem(QGraphicsRectItem):
186-
"""This is a class"""
187-
def __init__(self, *arg, **karg):
188-
QGraphicsRectItem.__init__(self, *arg, **karg)
189-
self.codon = None
190-
self.label = None
191-
self.setAcceptsHoverEvents(True)
192-
193-
def hoverEnterEvent (self, e):
194-
""" when mouse is over"""
195-
if not self.label:
196-
self.label = QGraphicsRectItem(parent=self)
197-
#self.label.setY(-18)
198-
self.label.setX(11)
199-
self.label.setBrush(QBrush(QColor("white")))
200-
self.label.text = QGraphicsSimpleTextItem(parent=self.label)
201-
202-
self.setZValue(1)
203-
self.label.text.setText(self.codon)
204-
self.label.setRect(self.label.text.boundingRect())
205-
self.label.setVisible(True)
206-
207-
def hoverLeaveEvent(self, e):
208-
"""when mouse leaves area"""
209-
if self.label:
210-
self.label.setVisible(False)
211-
self.setZValue(0)
212-
213-
21490

21591
def test_layout_evol(node):
21692
'''
@@ -221,7 +97,7 @@ def test_layout_evol(node):
22197
node.img_style["draw_descendants"]= False
22298
if node.is_leaf():
22399
if hasattr (node, "sequence"):
224-
seqface = MySequenceFace(node.sequence, "aa",
100+
seqface = SequenceFace(node.sequence, "aa",
225101
codon=node.nt_sequence, fsize=10,
226102
col_w=11, interactive=True)
227103
faces.add_face_to_node(seqface, node, 1, aligned=True)
@@ -235,7 +111,7 @@ def test_layout_phylo_aa(node):
235111
node.img_style["draw_descendants"]= False
236112
if node.is_leaf():
237113
if hasattr (node, "sequence"):
238-
seqface = MySequenceFace(node.sequence, "aa",
114+
seqface = SequenceFace(node.sequence, "aa",
239115
fsize=10,
240116
col_w=11, interactive=False)
241117
faces.add_face_to_node(seqface, node, 1, aligned=True)
@@ -251,7 +127,7 @@ def test_layout_phylo_aa_motif(node):
251127
special_col = [[10,100],[150,1000],[1000,2000],[3000,4990]]
252128
if node.is_leaf():
253129
if hasattr (node, "sequence"):
254-
seqface = MySequenceFace(node.sequence, "aa",
130+
seqface = SequenceFace(node.sequence, "aa",
255131
fsize=10,special_col=special_col,
256132
alt_col_w=3,
257133
col_w=11, interactive=True)
@@ -267,7 +143,7 @@ def test_layout_phylo_nt(node):
267143
node.img_style["draw_descendants"]= False
268144
if node.is_leaf():
269145
if hasattr (node, "sequence"):
270-
seqface = MySequenceFace(node.sequence, "nt",
146+
seqface = SequenceFace(node.sequence, "nt",
271147
fsize=10,
272148
col_w=11, interactive=True)
273149
faces.add_face_to_node(seqface, node, 1, aligned=True)

ete3/treeview/_about.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,38 @@
4545
# by: PyQt4 UI code generator 4.7.2
4646
#
4747
# WARNING! All changes made in this file will be lost!
48-
49-
from PyQt4 import QtCore, QtGui
48+
from __future__ import absolute_import
49+
from .qt import *
5050

5151
class Ui_About(object):
5252
def setupUi(self, About):
5353
About.setObjectName("About")
5454
About.resize(462, 249)
55-
self.verticalLayoutWidget = QtGui.QWidget(About)
55+
self.verticalLayoutWidget = QWidget(About)
5656
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 0, 441, 208))
5757
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
58-
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
58+
self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget)
5959
self.verticalLayout.setObjectName("verticalLayout")
60-
self.label = QtGui.QLabel(self.verticalLayoutWidget)
60+
self.label = QLabel(self.verticalLayoutWidget)
6161
self.label.setObjectName("label")
6262
self.verticalLayout.addWidget(self.label)
63-
self.version = QtGui.QLabel(self.verticalLayoutWidget)
63+
self.version = QLabel(self.verticalLayoutWidget)
6464
self.version.setObjectName("version")
6565
self.verticalLayout.addWidget(self.version)
6666

6767
self.retranslateUi(About)
6868
QtCore.QMetaObject.connectSlotsByName(About)
6969

7070
def retranslateUi(self, About):
71-
About.setWindowTitle(QtGui.QApplication.translate("About", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
72-
self.label.setText(QtGui.QApplication.translate("About", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
71+
About.setWindowTitle(QApplication.translate("About", "Dialog", None))
72+
self.label.setText(QApplication.translate("About", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
7373
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
7474
"p, li { white-space: pre-wrap; }\n"
7575
"</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
7676
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><img src=\":/ete icons/ete_logo.png\" /></p>\n"
77-
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;\"><span style=\" font-size:11pt;\">ETE: a python Environment for Tree Exploration</span></p>\n"
77+
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;\"><span style=\" font-size:11pt;\">ETE3: Reconstruction and Analysis Phylogenomics Data</span></p>\n"
7878
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-weight:600;\"><a href=\"http://etetoolkit.org\"><span style=\" text-decoration: underline; color:#0057ae;\">http://etetoolkit.org</span></a></p>\n"
79-
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
80-
self.version.setText(QtGui.QApplication.translate("About", "VERSION", None, QtGui.QApplication.UnicodeUTF8))
79+
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p></body></html>", None))
80+
self.version.setText(QApplication.translate("About", "VERSION", None))
8181

8282
from . import ete_resources_rc

0 commit comments

Comments
 (0)