Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lowrie committed Dec 31, 2015
1 parent bbe6e42 commit e96a3e5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 50 deletions.
10 changes: 6 additions & 4 deletions config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import os, imp, shutil
import utils

_CONFIG_INIT ='''
_CONFIG_INIT = r'''
######################################################################
# Options for pyRouterJig. Be careful editing this file. Any errors
# that occur will not be friendly.
Expand Down Expand Up @@ -148,8 +148,10 @@ def read_config(min_version_number):
shutil.move(filename, backup)
create_config(filename)
config = imp.load_source('', filename)
msg = 'Your configuration file %s was outdated and has been moved to %s. A new configuration file'\
' has been created. Any changes you made to the old file will need to be migrated to the new file.'\
' Unfortunately, we are unable to automatically migrate your old settings.' % (filename, backup)
msg = 'Your configuration file %s was outdated and has been moved to %s.'\
' A new configuration file has been created. Any changes you made'\
' to the old file will need to be migrated to the new file.'\
' Unfortunately, we are unable to automatically migrate your old'\
' settings.' % (filename, backup)

return (config, msg, msg_level)
36 changes: 18 additions & 18 deletions qt_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ def create_widgets(self):
self.le_bit_angle.editingFinished.connect(self._on_bit_angle)

# Board M thicknesses
self.le_boardm_label = [0]*2
self.le_boardm = [0]*2
self.le_boardm_label = []
self.le_boardm = []
for i in lrange(2):
self.le_boardm_label[i] = QtGui.QLabel('Thickness')
self.le_boardm[i] = QtGui.QLineEdit(self.main_frame)
self.le_boardm_label.append(QtGui.QLabel('Thickness'))
self.le_boardm.append(QtGui.QLineEdit(self.main_frame))
self.le_boardm[i].setFixedWidth(lineEditWidth)
self.le_boardm[i].setText(self.units.increments_to_string(self.m_thickness[i]))
self.le_boardm[0].editingFinished.connect(self._on_boardm0)
Expand All @@ -329,16 +329,16 @@ def create_widgets(self):
self.woods = copy.deepcopy(woods)
self.woods.update(patterns)
# ... create the combo boxes and their labels
self.cb_wood = [0]*4
self.cb_wood[0] = self.create_wood_combo_box(woods, patterns)
self.cb_wood[1] = self.create_wood_combo_box(woods, patterns)
self.cb_wood[2] = self.create_wood_combo_box(woods, patterns, True)
self.cb_wood[3] = self.create_wood_combo_box(woods, patterns, True)
self.cb_wood_label = [0]*4
self.cb_wood_label[0] = QtGui.QLabel('Top Board')
self.cb_wood_label[1] = QtGui.QLabel('Bottom Board')
self.cb_wood_label[2] = QtGui.QLabel('Double Board')
self.cb_wood_label[3] = QtGui.QLabel('Double-Double Board')
self.cb_wood = []
self.cb_wood.append(self.create_wood_combo_box(woods, patterns))
self.cb_wood.append(self.create_wood_combo_box(woods, patterns))
self.cb_wood.append(self.create_wood_combo_box(woods, patterns, True))
self.cb_wood.append(self.create_wood_combo_box(woods, patterns, True))
self.cb_wood_label = []
self.cb_wood_label.append(QtGui.QLabel('Top Board'))
self.cb_wood_label.append(QtGui.QLabel('Bottom Board'))
self.cb_wood_label.append(QtGui.QLabel('Double Board'))
self.cb_wood_label.append(QtGui.QLabel('Double-Double Board'))
self.cb_wood[0].activated.connect(self._on_wood0)
self.cb_wood[1].activated.connect(self._on_wood1)
self.cb_wood[2].activated.connect(self._on_wood2)
Expand Down Expand Up @@ -503,7 +503,6 @@ def create_widgets(self):
grid.addWidget(create_vline(), 0, 2, 9, 1)

# Add the bit width label and its line edit
vbox_bit_width = QtGui.QVBoxLayout()
grid.addWidget(self.le_bit_width_label, 1, 3)
grid.addWidget(self.le_bit_width, 2, 3)
grid.addWidget(create_vline(), 0, 4, 9, 1)
Expand Down Expand Up @@ -980,7 +979,7 @@ def _on_save(self, do_screenshot=False):
if self.screenshot_index is None:
self.screenshot_index = utils.get_file_index(self.working_dir, prefix, postfix)

fname = prefix + `self.screenshot_index` + postfix
fname = prefix + `self.screenshot_index` + postfix

# Get the file name. The default name is indexed on the number of
# times this function is called. If a screenshot, don't prompt for
Expand All @@ -992,7 +991,7 @@ def _on_save(self, do_screenshot=False):
# This is the simple approach to set the filename, but doesn't allow
# us to update the working_dir, if the user changes it.
#filename = QtGui.QFileDialog.getSaveFileName(self, 'Save file', \
# defname, 'Portable Network Graphics (*.png)')
# defname, 'Portable Network Graphics (*.png)')
# ... so here is now we do it:
dialog = QtGui.QFileDialog(self, 'Save file', defname, \
'Portable Network Graphics (*.png)')
Expand Down Expand Up @@ -1108,7 +1107,7 @@ def _on_open(self):
elif sp_type == 'Edit':
self.edit_spacing = sp
self.spacing_index = self.edit_spacing_id

self.spacing = sp
self.tabs_spacing.blockSignals(True)
self.tabs_spacing.setCurrentIndex(self.spacing_index)
Expand Down Expand Up @@ -1454,6 +1453,7 @@ def _on_caul(self):
else:
self.do_caul = True
self.status_message('Turned on caul template.')
self.file_saved = False
self.draw()

def status_message(self, msg, flash_len_ms=None):
Expand Down
36 changes: 23 additions & 13 deletions qt_fig.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import division
from future.utils import lrange

import copy
import router
import utils

Expand Down Expand Up @@ -271,8 +270,11 @@ def paintEvent(self, event):
self.draw_active_cuts(painter)
painter.end()

def set_font_size(self, painter, size):
font_inches = self.font_size[size] / 32.0 * self.geom.bit.units.increments_per_inch
def set_font_size(self, painter, param):
'''
Sets the font size for type param
'''
font_inches = self.font_size[param] / 32.0 * self.geom.bit.units.increments_per_inch
font = painter.font()
xx = self.transform.map(font_inches, 0)[0] - self.transform.dx()
font.setPixelSize(utils.my_round(xx))
Expand Down Expand Up @@ -322,6 +324,9 @@ def paint_all(self, painter, dpi=None):
return (window_width, window_height)

def draw_passes(self, painter, blabel, cuts, y1, y2, flags):
'''
Draws and labels the router passes on a template or board.
'''
board_T = self.geom.board_T
# brush = QtGui.QBrush(QtCore.Qt.white)
brush = None
Expand All @@ -341,6 +346,9 @@ def draw_passes(self, painter, blabel, cuts, y1, y2, flags):
paint_text(painter, label, (xp, y1), flags, shift, -90, fill=brush)

def draw_template_rectangle(self, painter, r, b):
'''
Draws the geometry of a template
'''
# Fill the entire template as white
painter.fillRect(r.xL(), r.yB(), r.width, r.height, QtCore.Qt.white)

Expand Down Expand Up @@ -387,7 +395,7 @@ def draw_alignment(self, painter):
y1 = b.yB()
y2 = b.yT()
painter.drawLine(x, y1, x, y2)
paint_text(painter, label, (x, (y1 + y2) // 2), flags, (0,0), -90)
paint_text(painter, label, (x, (y1 + y2) // 2), flags, (0, 0), -90)

def draw_template(self, painter):
'''
Expand All @@ -414,7 +422,8 @@ def draw_template(self, painter):
# ... do the top board passes
y1 = boards[0].yB()
y2 = y1 + frac_depth
self.draw_passes(painter, 'A', boards[0].bottom_cuts, rect_top.yMid(), rect_top.yT(), flagsR)
self.draw_passes(painter, 'A', boards[0].bottom_cuts, rect_top.yMid(),\
rect_top.yT(), flagsR)
self.draw_passes(painter, 'A', boards[0].bottom_cuts, y1, y2, flagsR)
label_bottom = 'A,B'
label_top = None
Expand Down Expand Up @@ -470,18 +479,19 @@ def draw_template(self, painter):
bottom = self.geom.caul_bottom
self.draw_template_rectangle(painter, rect_caul, board_caul)
self.draw_passes(painter, 'A', top, rect_caul.yMid(), rect_caul.yT(), flagsR)
self.draw_passes(painter, self.labels[i], bottom, rect_caul.yMid(), rect_caul.yB(), flagsL)
self.draw_passes(painter, self.labels[i], bottom, rect_caul.yMid(),\
rect_caul.yB(), flagsL)
self.set_font_size(painter, 'boards')
paint_text(painter, 'Cauls', (rect_caul.xL(), rect_caul.yMid()), flagsL, (5,0))
paint_text(painter, 'Cauls', (rect_caul.xR(), rect_caul.yMid()), flagsR, (-5,0))
paint_text(painter, 'Cauls', (rect_caul.xL(), rect_caul.yMid()), flagsL, (5, 0))
paint_text(painter, 'Cauls', (rect_caul.xR(), rect_caul.yMid()), flagsR, (-5, 0))

# Label the templates
self.set_font_size(painter, 'boards')
paint_text(painter, label_bottom, (rect_T.xL(), rect_T.yMid()), flagsL, (5,0))
paint_text(painter, label_bottom, (rect_T.xR(), rect_T.yMid()), flagsR, (-5,0))
paint_text(painter, label_bottom, (rect_T.xL(), rect_T.yMid()), flagsL, (5, 0))
paint_text(painter, label_bottom, (rect_T.xR(), rect_T.yMid()), flagsR, (-5, 0))
if label_top is not None:
paint_text(painter, label_top, (rect_TDD.xL(), rect_TDD.yMid()), flagsL, (5,0))
paint_text(painter, label_top, (rect_TDD.xR(), rect_TDD.yMid()), flagsR, (-5,0))
paint_text(painter, label_top, (rect_TDD.xL(), rect_TDD.yMid()), flagsL, (5, 0))
paint_text(painter, label_top, (rect_TDD.xR(), rect_TDD.yMid()), flagsR, (-5, 0))

def draw_one_board(self, painter, board, bit):
'''
Expand All @@ -495,7 +505,7 @@ def draw_one_board(self, painter, board, bit):
pen.setWidthF(0)
painter.setPen(pen)
icon = self.woods[board.wood]
if type(icon) == type('a string'):
if isinstance(icon, str):
brush = QtGui.QBrush(QtGui.QPixmap(icon))
else:
brush = QtGui.QBrush(QtCore.Qt.black, icon)
Expand Down
12 changes: 7 additions & 5 deletions qt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

import sys
import unittest
import utils
from qt_driver import Driver
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtTest import QTest

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

class Driver_Test(unittest.TestCase):
'''
Expand All @@ -59,6 +57,10 @@ def test_screenshots(self):
# default
self.d._on_fullscreen()
self.screenshot()
# default with caul
self.d._on_caul()
self.screenshot()
self.d._on_caul()
# dovetail
self.d.le_bit_angle.clear()
QTest.keyClicks(self.d.le_bit_angle, '7')
Expand All @@ -70,13 +72,13 @@ def test_screenshots(self):
self.d._on_bit_angle()
self.assertEqual(str(self.d.le_bit_angle.text()), '0')
# Wood selection
for w in [0,1]:
for w in [0, 1]:
i = self.d.cb_wood[w].findText('hard-maple')
self.assertTrue(i >= 0)
self.d.cb_wood[w].setCurrentIndex(i)
self.d._on_wood(w)
self.screenshot()
for w in [0,1]:
for w in [0, 1]:
i = self.d.cb_wood[w].findText('DiagCrossPattern')
self.assertTrue(i >= 0)
self.d.cb_wood[w].setCurrentIndex(i)
Expand Down Expand Up @@ -121,7 +123,7 @@ def test_screenshots(self):
self.screenshot()
# double
self.d.tabs_spacing.setCurrentIndex(self.d.equal_spacing_id)
for w in [0,1]:
for w in [0, 1]:
i = self.d.cb_wood[w].findText('hard-maple')
self.assertTrue(i >= 0)
self.d.cb_wood[w].setCurrentIndex(i)
Expand Down
17 changes: 10 additions & 7 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from future.utils import lrange

import math
import copy
from utils import my_round

class Router_Exception(Exception):
Expand All @@ -50,7 +49,7 @@ class Incra_Template(object):
length: total length of template
do_caul: If true, create the caul template
'''
def __init__(self, units, boards, do_caul = False, margin=None, length=None):
def __init__(self, units, boards, do_caul=False, margin=None, length=None):
# incra uses 1/2" high templates
self.height = units.inches_to_increments(0.5)
self.do_caul = do_caul
Expand Down Expand Up @@ -240,8 +239,10 @@ def __init__(self, bit, width, thickness=32):
self.bottom_cuts = None
self.top_cuts = None
def set_wood(self, wood):
'''Sets attribute wood'''
self.wood = wood
def set_active(self, active=True):
'''Sets attribute active'''
self.active = active
def set_width_from_string(self, s):
'''
Expand Down Expand Up @@ -306,14 +307,17 @@ def change_units(self, new_units):
self.thickness = my_round(self.thickness * s)
self.units = new_units
def set_bottom_cuts(self, cuts, bit):
'''Sets the bottom cuts for the board'''
for c in cuts:
c.make_router_passes(bit, self)
self.bottom_cuts = cuts
def set_top_cuts(self, cuts, bit):
'''Sets the top cuts for the board'''
for c in cuts:
c.make_router_passes(bit, self)
self.top_cuts = cuts
def _do_cuts(self, bit, cuts, y_nocut, y_cut):
'''Creates the perimeter coordinates for the given cuts'''
x = [self.xL()]
if cuts[0].xmin > 0:
y = [y_nocut]
Expand Down Expand Up @@ -494,15 +498,14 @@ def caul_cuts(cuts, bit, board, trim):
Returns an array of Cut objects
'''
nc = len(cuts)
caul_cuts = []
new_cuts = []
for c in cuts:
xmin = max(0, c.xmin - trim)
xmax = min(board.width, c.xmax + trim)
cut = Cut(xmin, xmax)
cut.make_router_passes(bit, board)
caul_cuts.append(cut)
return caul_cuts
new_cuts.append(cut)
return new_cuts

class Joint_Geometry(object):
'''
Expand All @@ -529,7 +532,7 @@ def __init__(self, template, boards, bit, spacing, margins, caul_trim):
self.boards[2].set_top_cuts(top, bit)
last = adjoining_cuts(top, bit, boards[2])
self.boards[2].set_bottom_cuts(last, bit)

# make the top cuts on the bottom board
top = adjoining_cuts(last, bit, boards[1])
self.boards[1].set_top_cuts(top, bit)
Expand Down
7 changes: 4 additions & 3 deletions spacing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import utils

def dump_cuts(cuts):
'''Dumps the cuts to the screen...this is for debugging.'''
for c in cuts:
print(c.xmin, c.xmax)

Expand Down Expand Up @@ -175,7 +176,7 @@ def set_cuts(self):
i = right + neck_width
while i < board_width:
ri = min(i + width, board_width)
if ri - i > self.config.min_finger_width and board_width - i > min_interior:
if ri - i > self.config.min_finger_width and board_width - i > min_interior:
self.cuts.append(router.Cut(i, ri))
i = ri + neck_width
# If we have only one cut the entire width of the board, then
Expand Down Expand Up @@ -362,7 +363,7 @@ def cut_move_left(self):
op.append(f)
if len(noop) > 0:
self.cuts = cuts_save
return 'No cuts moved: unable to move indices ' + `noop`
return 'No cuts moved: unable to move indices ' + `noop`
if len(op) > 0 or delete_cut:
self.undo_cuts.append(cuts_save)
if len(op) > 0:
Expand Down Expand Up @@ -405,7 +406,7 @@ def cut_move_right(self):
op.append(f)
if len(noop) > 0:
self.cuts = cuts_save
return 'No cuts moved: unable to move indices ' + `noop`
return 'No cuts moved: unable to move indices ' + `noop`
if len(op) > 0 or delete_cut:
self.undo_cuts.append(cuts_save)
if len(op) > 0:
Expand Down

0 comments on commit e96a3e5

Please sign in to comment.