Skip to content

Commit

Permalink
Merge pull request #2 from Valdas2000/py3_qt5
Browse files Browse the repository at this point in the history
Py3 qt5
  • Loading branch information
Valdas2000 authored Feb 8, 2018
2 parents a179286 + ad49a35 commit 7a520aa
Show file tree
Hide file tree
Showing 11 changed files with 1,439 additions and 1,243 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,26 @@ joints.

For more information, [see the pyRouterJig website](http://lowrie.github.io/pyRouterJig/)

The commitment introducethe following major changes:
1- the project migrated on python3
2- the project migrated to QT5

Enhansments:
-------------
1 - Templates got Align line on contrast background
2 - Thin markers in editor
3 - Updated PNG

Known Issues:
--------------
1 - Export 3DS does not work propertly

Installetion:
--------------
1. Download fresh python setup from https://www.python.org/downloads/ (now it is 3.6.4)
do not forget instaletion path
2. Setup libraries
pip install pyQT5
pip install future
pip install Pillow

4 changes: 2 additions & 2 deletions mac.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ a = Analysis(['pyRouterJig.py'],
cipher=block_cipher)

# Explicitly add libraries that pyinstaller misses
a.binaries += [('libQtCore.4.dylib', '/anaconda/lib/libQtCore.4.dylib', 'BINARY') ]
a.binaries += [('libQtGui.4.dylib', '/anaconda/lib/libQtGui.4.dylib', 'BINARY') ]
a.binaries += [('libQtCore.5.dylib', '/anaconda/lib/libQtCore.5.dylib', 'BINARY') ]
a.binaries += [('libQtGui.5.dylib', '/anaconda/lib/libQtGui.5.dylib', 'BINARY') ]
a.binaries += [('libpng16.16.dylib', '/anaconda/lib/libpng16.16.dylib', 'BINARY') ]

# Remove various unused files from distribution
Expand Down
186 changes: 94 additions & 92 deletions qt_config.py

Large diffs are not rendered by default.

310 changes: 177 additions & 133 deletions qt_driver.py

Large diffs are not rendered by default.

92 changes: 64 additions & 28 deletions qt_fig.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
'''
from __future__ import print_function
from __future__ import division
from decimal import Decimal
from future.utils import lrange

import time

import router
import utils

from PyQt4 import QtCore, QtGui
from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport

def paint_text(painter, text, coord, flags, shift=(0, 0), angle=0, fill_color=None):
'''
Expand Down Expand Up @@ -82,14 +83,14 @@ def paint_text(painter, text, coord, flags, shift=(0, 0), angle=0, fill_color=No
painter.setTransform(transform)
return rect

class Qt_Fig(QtGui.QWidget):
class Qt_Fig(QtWidgets.QWidget):
'''
Interface to the qt_driver, using Qt to draw the boards and template.
The attribute "canvas" is self, to mimic the old interface to matplotlib,
which this class replaced.
'''
def __init__(self, template, boards, config):
QtGui.QWidget.__init__(self)
QtWidgets.QWidget.__init__(self)
self.canvas = self
self.config = config
self.fig_width = -1
Expand Down Expand Up @@ -233,10 +234,10 @@ def print(self, template, boards, bit, spacing, woods, description):
self.config)

# Print through the preview dialog
printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
printer.setOrientation(QtGui.QPrinter.Landscape)
printer.setPageMargins(0, 0, 0, 0, QtGui.QPrinter.Inch)
pdialog = QtGui.QPrintPreviewDialog(printer)
printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
printer.setOrientation(QtPrintSupport.QPrinter.Landscape)
printer.setPageMargins(0, 0, 0, 0, QtPrintSupport.QPrinter.Inch)
pdialog = QtPrintSupport.QPrintPreviewDialog(printer)
pdialog.setModal(True)
pdialog.paintRequested.connect(self.preview_requested)
return pdialog.exec_()
Expand Down Expand Up @@ -358,10 +359,12 @@ def paint_all(self, painter, dpi=None):
painter.translate(x, y)
self.transform = painter.transform()


# draw the objects
self.draw_boards(painter)
self.draw_template(painter)
self.draw_title(painter)
#self.draw_finger_sizes(painter)
if self.config.show_finger_widths:
self.draw_finger_sizes(painter)

Expand Down Expand Up @@ -474,18 +477,28 @@ def draw_alignment(self, painter):

# draw the alignment lines on both templates
x = board_T.xR() + self.geom.bit.width // 2

pen = QtGui.QPen(QtCore.Qt.SolidLine)
pen.setColor(self.colors['template_margin_foreground'])
painter.setPen(pen)
pen.setWidthF(0)

bg_pen=QtGui.QPen(QtCore.Qt.SolidLine)
bg_pen.setColor(QtGui.QColor('White'))
bg_pen.setWidthF(0)

self.set_font_size(painter, 'template')
label = 'ALIGN'
flags = QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter
for b in [board_T, board_TDD, board_caul]:
if b is not None:
y1 = b.yB()
y2 = b.yT()
painter.setPen(pen)
painter.drawLine(x, y1, x, y2)
paint_text(painter, label, (x, (y1 + y2) // 2), flags, (0, 0), -90)
painter.setPen(bg_pen)
painter.drawLine(QtCore.QPointF(x-0.5, y1+0.5),QtCore.QPointF( x-0.5, y2-0.5) )
painter.drawLine(QtCore.QPointF(x+0.5, y1+0.5),QtCore.QPointF(x+0.5, y2-0.5) )

def draw_template_rectangle(self, painter, r, b):
'''
Expand Down Expand Up @@ -527,12 +540,17 @@ def draw_template(self, painter):

pen_canvas = QtGui.QPen(QtCore.Qt.SolidLine)
pen_canvas.setColor(self.colors['canvas_foreground'])
pen_canvas.setWidthF(0)
penA = QtGui.QPen(QtCore.Qt.SolidLine)
penA.setColor(self.colors['pass_color'])
penA.setWidthF(0)
penB = QtGui.QPen(QtCore.Qt.DashLine)
penB.setColor(self.colors['pass_alt_color'])
penB.setWidthF(0)

painter.setPen(pen_canvas)
self.draw_template_rectangle(painter, rect_T, board_T)

if boards[3].active:
rect_TDD = self.geom.rect_TDD
board_TDD = self.geom.board_TDD
Expand Down Expand Up @@ -670,6 +688,7 @@ def draw_template(self, painter):
else:
pen = QtGui.QPen(QtCore.Qt.DashLine)
pen.setColor(self.colors['center_color'])
pen.setWidthF(0)
painter.setPen(pen)
painter.drawLine(xMid, rect_caul.yB(), xMid, rect_caul.yT())
painter.setPen(self.colors['template_margin_foreground'])
Expand All @@ -679,6 +698,7 @@ def draw_template(self, painter):
# Label the templates
pen = QtGui.QPen(QtCore.Qt.DashLine)
pen.setColor(self.colors['center_color'])
pen.setWidthF(0)
self.set_font_size(painter, 'template_labels')
if len(centerline) > 0:
label_bottom += '\nCenter: ' + centerline[0]
Expand Down Expand Up @@ -735,7 +755,9 @@ def draw_one_board(self, painter, board, bit, fill_color):
color = self.colors['board_foreground']
brush = QtGui.QBrush(color, icon)
(inverted, invertable) = self.transform.inverted()
brush.setMatrix(inverted.toAffine())
#setMatrix is not offered anymore
#brush.setMatrix(inverted.toAffine())
brush.setTransform(inverted)
painter.setBrush(brush)
painter.drawPolygon(poly)
painter.restore()
Expand All @@ -755,6 +777,7 @@ def draw_boards(self, painter):
self.set_font_size(painter, 'boards')
pen = QtGui.QPen(QtCore.Qt.SolidLine)
pen.setColor(self.colors['canvas_foreground'])
pen.setWidthF(0)
painter.setPen(pen)

x1 = self.geom.boards[0].xL() - self.geom.bit.width // 2
Expand Down Expand Up @@ -804,9 +827,9 @@ def cut_polygon(self, c):
xLB = xLT
xRB = xRT
if c.xmin > 0:
xLB += self.geom.bit.offset
xLB += self.geom.bit.overhang
if c.xmax < self.geom.boards[0].width:
xRB -= self.geom.bit.offset
xRB -= self.geom.bit.overhang
yB = boards[0].yB()
yT = yB + self.geom.bit.depth
poly = QtGui.QPolygonF()
Expand All @@ -822,17 +845,17 @@ def draw_active_cuts(self, painter):
If the spacing supports it, highlight the active cuts and
draw their limits
'''
# draw the perimeter of the cursor cut

f = self.geom.spacing.cursor_cut
if f is None:
return
poly = self.cut_polygon(self.geom.boards[0].bottom_cuts[f])
painter.save()
pen = QtGui.QPen(QtCore.Qt.blue)
pen.setWidth(1)
painter.setPen(pen)
painter.drawPolyline(poly)
painter.restore()

pen = QtGui.QPen()
pen.setWidthF(0)

# get the perimeter of the cursor
cursor_poly = self.cut_polygon(self.geom.boards[0].bottom_cuts[f])


# initialize limits
xminG = self.geom.boards[0].width
Expand All @@ -842,7 +865,7 @@ def draw_active_cuts(self, painter):
painter.save()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 75))
painter.setBrush(brush)
pen = QtGui.QPen(QtCore.Qt.red)
pen.setColor(QtCore.Qt.red)
painter.setPen(pen)
fcolor = QtGui.QColor(self.colors['board_background'])
fcolor.setAlphaF(1.0)
Expand All @@ -863,16 +886,27 @@ def draw_active_cuts(self, painter):
painter.restore()

# draw the limits
# using QPointF to avoid border marks overlap with cursor
painter.save()
xminG += self.geom.boards[0].xL()
xmaxG += self.geom.boards[0].xL()
yB = self.geom.boards[0].yB()
yT = self.geom.boards[0].yT()
painter.setPen(QtCore.Qt.green)
painter.drawLine(xminG, yB, xminG, yT)
painter.drawLine(xmaxG, yB, xmaxG, yT)
pen.setColor(QtCore.Qt.green)
painter.setPen(pen)
half = Decimal(0.5)
painter.drawLine(QtCore.QPointF(xminG - half, yB), QtCore.QPointF(xminG - half, yT) )
painter.drawLine(QtCore.QPointF(xmaxG + half, yB), QtCore.QPointF(xmaxG + half, yT) )
painter.restore()

# draw the perimeter of the cursor cut at the end to get it always visible
painter.save()
pen.setColor(QtCore.Qt.blue)
painter.setPen(pen)
painter.drawPolyline(cursor_poly)
painter.restore()


def draw_title(self, painter):
'''
Draws the title
Expand All @@ -887,6 +921,7 @@ def draw_title(self, painter):
def draw_finger_sizes(self, painter):
'''
Annotates the finger sizes on each board
with 3 digit precision
'''
units = self.geom.bit.units
self.set_font_size(painter, 'template')
Expand All @@ -909,7 +944,7 @@ def draw_finger_sizes(self, painter):
for c in bcuts:
x = self.geom.boards[1].xL() + (c.xmin + c.xmax) // 2
y = self.geom.boards[1].yT()
label = units.increments_to_string(c.xmax - c.xmin)
label = units.increments_to_string( round(c.xmax - c.xmin, 3) )
p = (x, y)
paint_text(painter, label, p, flags, shift, fill_color=fcolor)
# ... do the A cuts
Expand All @@ -918,7 +953,7 @@ def draw_finger_sizes(self, painter):
for c in acuts:
x = self.geom.boards[0].xL() + (c.xmin + c.xmax) // 2
y = self.geom.boards[0].yB()
label = units.increments_to_string(c.xmax - c.xmin)
label = units.increments_to_string( round(c.xmax - c.xmin, 3) )
p = (x, y)
paint_text(painter, label, p, flags, shift, fill_color=fcolor)

Expand Down Expand Up @@ -984,8 +1019,9 @@ def wheelEvent(self, event):
return

if self.config.debug:
print('qt_fig.wheelEvent', event.delta())
self.scaling *= 1 + 0.05 * event.delta() / 120
print('qt_fig.wheelEvent', event.angleDelta())
ppp = event.angleDelta() / 120
self.scaling *= 1 + 0.05 * ppp.y()
self.update()

def mousePressEvent(self, event):
Expand Down Expand Up @@ -1033,7 +1069,7 @@ def mouseMoveEvent(self, event):
event.ignore()
return

pos = self.base_transform.map(event.posF())
pos = self.base_transform.map(event.localPos())
if self.config.debug:
print('mouse moved here: {} {}'.format(pos.x(), pos.y()))
diffx = (pos.x() - self.mouse_pos.x())
Expand Down
13 changes: 7 additions & 6 deletions qt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import unittest
from qt_driver import Driver
import utils
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtTest import QTest
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5.QtTest import QTest

app = QtGui.QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv)

class Case(object):
def __init__(self, angle, width, depth, spacing, board_width=7):
Expand Down Expand Up @@ -66,7 +67,7 @@ def setUp(self):
self.d.show()
self.d.raise_()
self.debug = self.d.config.debug
QTest.qWaitForWindowShown(self.d)
QTest.qWaitForWindowExposed(self.d)
if not utils.isMac():
self.d.working_dir = 'Z:\Windows\pyRouterJig\images'
def test_options(self):
Expand All @@ -77,7 +78,7 @@ def test_defaults(self):
self.assertEqual(str(self.d.le_bit_depth.text()), '3/4')
self.assertEqual(str(self.d.le_bit_angle.text()), '0')
def screenshot(self, do_screenshot=True):
QTest.qWaitForWindowShown(self.d)
QTest.qWaitForWindowExposed(self.d)
QTest.qWait(100)
self.d._on_save(do_screenshot)
def test_screenshots(self):
Expand Down
Loading

0 comments on commit 7a520aa

Please sign in to comment.