Skip to content

Commit

Permalink
Merge pull request #284 from etetoolkit/qt5
Browse files Browse the repository at this point in the history
add Qt5 support
  • Loading branch information
jhcepas authored Nov 2, 2017
2 parents 1bb716b + 0d37aff commit a36adb1
Show file tree
Hide file tree
Showing 23 changed files with 841 additions and 800 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ python:
- "2.7"
- "3.4"
- "3.5"

- "3.6"

cache:
directories:
- test_tmp

install:
- ./run_tests.sh --setup-only -sv "$TRAVIS_PYTHON_VERSION"
- ./run_tests.sh -s --setup-only -v "$TRAVIS_PYTHON_VERSION"

before_script:
# Ensure tags are available on the cloned repository
Expand All @@ -24,6 +24,7 @@ before_script:

script:
- ./run_tests.sh --test-only -sv "$TRAVIS_PYTHON_VERSION"
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then ./run_tests.sh --qt4 -sv "$TRAVIS_PYTHON_VERSION" ; fi
#- coverage run -m ete3.test.test_api
#- coverage run -a -m ete3.test.test_ete_evol # too heavy for travis
#- coverage run -a -m ete3.test.test_ete_build # too heavy for travis
Expand Down
24 changes: 13 additions & 11 deletions ete3/test/test_treeview/item_faces.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# We will need to create Qt4 items
from PyQt4 import QtCore
from PyQt4.QtGui import QGraphicsRectItem, QGraphicsSimpleTextItem, \
QGraphicsEllipseItem, QColor, QPen, QBrush

from ... import Tree, faces, TreeStyle, NodeStyle

# To play with random colors
import colorsys
import random

from ... import Tree, faces, TreeStyle, NodeStyle, Face

# We will need to create Qt4 items
from ...treeview.qt import QtCore, Qt
from ...treeview.qt import QGraphicsRectItem, QGraphicsSimpleTextItem, \
QGraphicsEllipseItem, QColor, QPen, QBrush

class InteractiveItem(QGraphicsRectItem):
def __init__(self, *arg, **karg):
QGraphicsRectItem.__init__(self, *arg, **karg)
self.node = None
self.label = None
self.setCursor(QtCore.Qt.PointingHandCursor)
self.setAcceptsHoverEvents(True)

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


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

# receive an arbitrary number of arguments, in this case width and
# height of the faces
width = args[0][0]
height = args[0][1]
width = args[0]
height = args[1]

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

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

masterItem = InteractiveItem(0, 0, width, height)
masterItem.setAcceptHoverEvents(True)

# Keep a link within the item to access node info
masterItem.node = node

Expand Down
140 changes: 8 additions & 132 deletions ete3/test/test_treeview/new_seq_face.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# We will need to create Qt4 items
from PyQt4 import QtCore
from PyQt4.QtGui import QGraphicsRectItem, QColor, QPen, QBrush
from PyQt4.QtGui import QGraphicsSimpleTextItem, QFont
from ...treeview.qt import QtCore
from ...treeview.qt import QGraphicsRectItem, QColor, QPen, QBrush
from ...treeview.qt import QGraphicsSimpleTextItem, QFont

from ... import faces, TreeStyle, PhyloTree, TextFace
from ... import faces, TreeStyle, PhyloTree, TextFace, SequenceFace
from random import random

_aafgcolors = {
Expand Down Expand Up @@ -87,130 +87,6 @@
}


class MySequenceFace(faces.StaticItemFace):
""" Creates a new molecular sequence face object.
:argument seq: Sequence string to be drawn
:argument seqtype: Type of sequence: "nt" or "aa"
:argument fsize: Font size, (default=10)
You can set custom colors for amino-acids or nucleotides:
:argument None codon : a string that corresponds to the reverse translation of the amino-acid sequence
:argument 11 col_w : width of the column (if col_w is lower than font size, letter wont be displayed)
:argument None fg_colors : dictionary of colors for foreground, with as keys each possible character in sequences, and as value the colors
:argument None bg_colors : dictionary of colors for background, with as keys each possible character in sequences, and as value the colors
:argument 3 alt_col_w : works together with special_col option, defines the width of given columns
:argument None special_col : list of lists containing the bounds of columns to be displayed with alt_col_w as width
:argument False interactive : more info can be displayed when mouse over sequence
"""
def __init__(self, seq, seqtype="aa", fsize=10,
fg_colors=None, bg_colors=None,
codon=None, col_w=11, alt_col_w=3,
special_col=None, interactive=False):
self.seq = seq
self.codon = codon
self.fsize = fsize
self.style = seqtype
self.col_w = float(col_w)
self.alt_col_w = float(alt_col_w)
self.special_col = special_col if special_col else []
self.width = 0 # will store the width of the whole sequence
self.interact = interactive

if self.style == "aa":
if not fg_colors:
fg_colors = _aafgcolors
if not bg_colors:
bg_colors = _aabgcolors
else:
if not fg_colors:
fg_colors = _ntfgcolors
if not bg_colors:
bg_colors = _ntbgcolors

self.fg_col = self.__init_col(fg_colors)
self.bg_col = self.__init_col(bg_colors)

# for future?
self.row_h = 13.0

super(MySequenceFace,
self).__init__(QGraphicsRectItem(0, 0, self.width, self.row_h))

def __init_col(self, color_dic):
"""to speed up the drawing of colored rectangles and characters"""
new_color_dic = {}
for car in color_dic:
new_color_dic[car] = QBrush(QColor(color_dic[car]))
return new_color_dic

def update_items(self):
#self.item = QGraphicsRectItem(0,0,self._total_w, self.row_h)
seq_width = 0
nopen = QPen(QtCore.Qt.NoPen)
font = QFont("Courier", self.fsize)
rect_cls = self.InteractiveLetterItem if self.interact else QGraphicsRectItem
for i, letter in enumerate(self.seq):
width = self.col_w
for m in self.special_col:
if m[0] < i <= m[1]:
width = self.alt_col_w
break
#load interactive item if called correspondingly
rectItem = rect_cls(0, 0, width, self.row_h, parent=self.item)
rectItem.setX(seq_width) # to give correct X to children item
rectItem.setBrush(self.bg_col[letter])
rectItem.setPen(nopen)
if self.interact:
if self.codon:
rectItem.codon = '%s, %d: %s' % (self.seq[i], i,
self.codon[i*3:i*3+3])
else:
rectItem.codon = '%s, %d' % (self.seq[i], i)
# write letter if enough space
if width >= self.fsize:
text = QGraphicsSimpleTextItem(letter, parent=rectItem)
text.setFont(font)
text.setBrush(self.fg_col[letter])
# Center text according to rectItem size
tw = text.boundingRect().width()
th = text.boundingRect().height()
text.setPos((width - tw)/2, (self.row_h - th)/2)
seq_width += width
self.width = seq_width

class InteractiveLetterItem(QGraphicsRectItem):
"""This is a class"""
def __init__(self, *arg, **karg):
QGraphicsRectItem.__init__(self, *arg, **karg)
self.codon = None
self.label = None
self.setAcceptsHoverEvents(True)

def hoverEnterEvent (self, e):
""" when mouse is over"""
if not self.label:
self.label = QGraphicsRectItem(parent=self)
#self.label.setY(-18)
self.label.setX(11)
self.label.setBrush(QBrush(QColor("white")))
self.label.text = QGraphicsSimpleTextItem(parent=self.label)

self.setZValue(1)
self.label.text.setText(self.codon)
self.label.setRect(self.label.text.boundingRect())
self.label.setVisible(True)

def hoverLeaveEvent(self, e):
"""when mouse leaves area"""
if self.label:
self.label.setVisible(False)
self.setZValue(0)



def test_layout_evol(node):
'''
Expand All @@ -221,7 +97,7 @@ def test_layout_evol(node):
node.img_style["draw_descendants"]= False
if node.is_leaf():
if hasattr (node, "sequence"):
seqface = MySequenceFace(node.sequence, "aa",
seqface = SequenceFace(node.sequence, "aa",
codon=node.nt_sequence, fsize=10,
col_w=11, interactive=True)
faces.add_face_to_node(seqface, node, 1, aligned=True)
Expand All @@ -235,7 +111,7 @@ def test_layout_phylo_aa(node):
node.img_style["draw_descendants"]= False
if node.is_leaf():
if hasattr (node, "sequence"):
seqface = MySequenceFace(node.sequence, "aa",
seqface = SequenceFace(node.sequence, "aa",
fsize=10,
col_w=11, interactive=False)
faces.add_face_to_node(seqface, node, 1, aligned=True)
Expand All @@ -251,7 +127,7 @@ def test_layout_phylo_aa_motif(node):
special_col = [[10,100],[150,1000],[1000,2000],[3000,4990]]
if node.is_leaf():
if hasattr (node, "sequence"):
seqface = MySequenceFace(node.sequence, "aa",
seqface = SequenceFace(node.sequence, "aa",
fsize=10,special_col=special_col,
alt_col_w=3,
col_w=11, interactive=True)
Expand All @@ -267,7 +143,7 @@ def test_layout_phylo_nt(node):
node.img_style["draw_descendants"]= False
if node.is_leaf():
if hasattr (node, "sequence"):
seqface = MySequenceFace(node.sequence, "nt",
seqface = SequenceFace(node.sequence, "nt",
fsize=10,
col_w=11, interactive=True)
faces.add_face_to_node(seqface, node, 1, aligned=True)
Expand Down
22 changes: 11 additions & 11 deletions ete3/treeview/_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,38 @@
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from __future__ import absolute_import
from .qt import *

class Ui_About(object):
def setupUi(self, About):
About.setObjectName("About")
About.resize(462, 249)
self.verticalLayoutWidget = QtGui.QWidget(About)
self.verticalLayoutWidget = QWidget(About)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 0, 441, 208))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtGui.QLabel(self.verticalLayoutWidget)
self.label = QLabel(self.verticalLayoutWidget)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.version = QtGui.QLabel(self.verticalLayoutWidget)
self.version = QLabel(self.verticalLayoutWidget)
self.version.setObjectName("version")
self.verticalLayout.addWidget(self.version)

self.retranslateUi(About)
QtCore.QMetaObject.connectSlotsByName(About)

def retranslateUi(self, About):
About.setWindowTitle(QtGui.QApplication.translate("About", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
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"
About.setWindowTitle(QApplication.translate("About", "Dialog", None))
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"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<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"
"<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"
"<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"
"<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"
"<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))
self.version.setText(QtGui.QApplication.translate("About", "VERSION", None, QtGui.QApplication.UnicodeUTF8))
"<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))
self.version.setText(QApplication.translate("About", "VERSION", None))

from . import ete_resources_rc
Loading

0 comments on commit a36adb1

Please sign in to comment.