Skip to content

Commit

Permalink
Add "Show caul template" to the preferences.
Browse files Browse the repository at this point in the history
Add status update when exiting preferences.
  • Loading branch information
lowrie committed Mar 15, 2016
1 parent 5b4201f commit 34ebfe8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
5 changes: 5 additions & 0 deletions config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
# "Router Passes", and selecting "Locations"
show_router_pass_locations = {show_router_pass_locations}
# If true, then show the caul template. This option may also be turned on and
# off under the menu "View" and selecting "Caul Template"
show_caul = {show_caul}
# Initial board width [inches|mm]
board_width = {board_width}
Expand Down Expand Up @@ -171,6 +175,7 @@
'show_finger_widths':True,
'show_router_pass_identifiers':True,
'show_router_pass_locations':False,
'show_caul':False,
'bit_angle':0,
'min_image_width':1440,
'max_image_width':'min_image_width',
Expand Down
16 changes: 16 additions & 0 deletions qt_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ def create_output(self):
w = QtGui.QWidget()
vbox = QtGui.QVBoxLayout()

self.cb_show_caul = QtGui.QCheckBox('Show Caul Template', w)
self.cb_show_caul.stateChanged.connect(self._on_show_caul)
self.cb_show_caul.setToolTip('Display the template for clamping cauls')
vbox.addWidget(self.cb_show_caul)

self.cb_show_finger_widths = QtGui.QCheckBox('Show Finger Widths', w)
self.cb_show_finger_widths.stateChanged.connect(self._on_show_finger_widths)
self.cb_show_finger_widths.setToolTip('Display the width of each finger')
Expand All @@ -275,6 +280,7 @@ def create_output(self):

self.le_printsf_label = QtGui.QLabel('Print Scale Factor:')
self.le_printsf = QtGui.QLineEdit(w)
self.le_printsf.setFocusPolicy(QtCore.Qt.ClickFocus)
self.le_printsf.setFixedWidth(self.line_edit_width)
self.le_printsf.editingFinished.connect(self._on_printsf)
tt = 'Scale output by this factor when printing.'
Expand Down Expand Up @@ -357,6 +363,7 @@ def initialize(self):
self.le_num_incr.setText(str(self.config.num_increments))
self.le_wood_images.setText(str(self.config.wood_images))
self.cb_show_finger_widths.setChecked(self.config.show_finger_widths)
self.cb_show_caul.setChecked(self.config.show_caul)
self.cb_rpid.setChecked(self.config.show_router_pass_identifiers)
self.cb_rploc.setChecked(self.config.show_router_pass_locations)
self.le_printsf.setText(str(self.config.print_scale_factor))
Expand Down Expand Up @@ -395,6 +402,7 @@ def _on_cancel(self):
'''
if self.config.debug:
print('qt_config:_on_cancel')
self.setResult(0)
self.close()

@QtCore.pyqtSlot()
Expand Down Expand Up @@ -439,6 +447,7 @@ def _on_save(self):
c.write_config(self.new_config)
if do_restart:
os.execv(sys.argv[0], sys.argv)
self.setResult(1)
self.close()

@QtCore.pyqtSlot(int)
Expand Down Expand Up @@ -541,6 +550,13 @@ def _on_show_finger_widths(self):
self.new_config['show_finger_widths'] = self.cb_show_finger_widths.isChecked()
self.update_state('show_finger_widths')

@QtCore.pyqtSlot()
def _on_show_caul(self):
if self.config.debug:
print('qt_config:_on_show_caul')
self.new_config['show_caul'] = self.cb_show_caul.isChecked()
self.update_state('show_caul')

@QtCore.pyqtSlot()
def _on_rpid(self):
if self.config.debug:
Expand Down
36 changes: 20 additions & 16 deletions qt_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def __init__(self, parent=None):
dbt = self.units.abstract_to_increments(self.config.double_board_thickness)
self.boards[2].set_height(self.bit, dbt)
self.boards[3].set_height(self.bit, dbt)
self.do_caul = False # if true, do caul template
self.template = router.Incra_Template(self.units, self.boards, self.do_caul)
self.template = router.Incra_Template(self.units, self.boards)
self.equal_spacing = spacing.Equally_Spaced(self.bit, self.boards, self.config)
self.equal_spacing.set_cuts()
self.var_spacing = spacing.Variable_Spaced(self.bit, self.boards, self.config)
Expand Down Expand Up @@ -297,10 +296,11 @@ def create_menu(self):
fullscreen_action.triggered.connect(self._on_fullscreen)
view_menu.addAction(fullscreen_action)

caul_action = QtGui.QAction('Caul Template', self, checkable=True)
caul_action.setStatusTip('Toggle caul template')
caul_action.triggered.connect(self._on_caul)
view_menu.addAction(caul_action)
self.caul_action = QtGui.QAction('Caul Template', self, checkable=True)
self.caul_action.setStatusTip('Toggle caul template')
self.caul_action.triggered.connect(self._on_caul)
view_menu.addAction(self.caul_action)
self.caul_action.setChecked(self.config.show_caul)

self.finger_size_action = QtGui.QAction('Finger Widths', self, checkable=True)
self.finger_size_action.setStatusTip('Toggle viewing finger sizes')
Expand Down Expand Up @@ -811,7 +811,7 @@ def draw(self):
'''(Re)draws the template and boards'''
if self.config.debug:
print('draw')
self.template = router.Incra_Template(self.units, self.boards, self.do_caul)
self.template = router.Incra_Template(self.units, self.boards)
self.fig.draw(self.template, self.boards, self.bit, self.spacing, self.woods)

def reinit_spacing(self):
Expand Down Expand Up @@ -1169,7 +1169,7 @@ def _on_open(self):
# Reset the dependent data
self.units = self.bit.units
self.doc = doc.Doc(self.units)
self.template = router.Incra_Template(self.units, self.boards, self.do_caul)
self.template = router.Incra_Template(self.units, self.boards)

# ... set the wood selection for each board. If the wood does not
# exist, set to a wood we know exists. This can happen if the wood
Expand Down Expand Up @@ -1317,9 +1317,14 @@ def _on_preferences(self):
if self.config_window is None:
self.config_window = qt_config.Config_Window(self.config, self.units, self)
self.config_window.initialize()
self.config_window.exec_()
r = self.config_window.exec_()
if r == 0:
self.status_message('No changes made to configuration file.')
else:
self.status_message('Preference changes saved in configuration file.')
# Update widgets that may have changed
self.finger_size_action.setChecked(self.config.show_finger_widths)
self.caul_action.setChecked(self.config.show_caul)
self.pass_id_action.setChecked(self.config.show_router_pass_identifiers)
self.pass_location_action.setChecked(self.config.show_router_pass_locations)
(woods, patterns) = qt_utils.create_wood_dict(self.config.wood_images)
Expand Down Expand Up @@ -1611,14 +1616,13 @@ def _on_fullscreen(self):
@QtCore.pyqtSlot()
def _on_caul(self):
'''Handles toggling showing caul template'''
if self.config.debug:
print('_on_caul')
if self.do_caul:
self.do_caul = False
self.status_message('Turned off caul template.')
else:
self.do_caul = True
self.config.show_caul = self.caul_action.isChecked()
if self.config_window is not None:
self.config_window.update_state('show_caul')
if self.config.show_caul:
self.status_message('Turned on caul template.')
else:
self.status_message('Turned off caul template.')
self.file_saved = False
self.draw()

Expand Down
19 changes: 8 additions & 11 deletions qt_fig.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def set_fig_dimensions(self, template, boards):
if boards[3].active:
fig_height += template.height + self.margins.sep

if template.do_caul:
if self.config.show_caul:
fig_height += template.height + self.margins.sep

min_width = 64
Expand Down Expand Up @@ -171,9 +171,8 @@ def draw(self, template, boards, bit, spacing, woods):
# Generate the new geometry layout
self.set_fig_dimensions(template, boards)
self.woods = woods
caul_trim = max(1, bit.units.abstract_to_increments(self.config.caul_trim))
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,\
caul_trim)
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,
self.config)
self.current_background = self.background
self.update()

Expand All @@ -186,9 +185,8 @@ def print(self, template, boards, bit, spacing, woods):

# Generate the new geometry layout
self.set_fig_dimensions(template, boards)
caul_trim = max(1, bit.units.abstract_to_increments(self.config.caul_trim))
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,\
caul_trim)
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,
self.config)

# Print through the preview dialog
printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
Expand All @@ -205,9 +203,8 @@ def image(self, template, boards, bit, spacing, woods):
'''
self.woods = woods
self.set_fig_dimensions(template, boards)
caul_trim = max(1, bit.units.abstract_to_increments(self.config.caul_trim))
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,\
caul_trim)
self.geom = router.Joint_Geometry(template, boards, bit, spacing, self.margins,
self.config)
self.current_background = self.background

s = self.size()
Expand Down Expand Up @@ -549,7 +546,7 @@ def draw_template(self, painter):
flagsRC = QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter

# ... draw the caul template and do its passes
if self.geom.template.do_caul:
if self.config.show_caul:
rect_caul = self.geom.rect_caul
board_caul = self.geom.board_caul
top = self.geom.caul_top
Expand Down
9 changes: 4 additions & 5 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ class Incra_Template(object):
height: Dimension in y-coordinate
margin: Dimension in x-coordinate placed on each end of template
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, margin=None, length=None):
# incra uses 1/2" high templates
self.height = units.inches_to_increments(0.5)
self.do_caul = do_caul
if margin is None:
self.margin = units.inches_to_increments(1.0)
else:
Expand Down Expand Up @@ -620,7 +618,7 @@ class Joint_Geometry(object):
'''
Computes and stores all of the geometry attributes of the joint.
'''
def __init__(self, template, boards, bit, spacing, margins, caul_trim):
def __init__(self, template, boards, bit, spacing, margins, config):
self.template = template
self.boards = boards
self.bit = bit
Expand Down Expand Up @@ -668,7 +666,8 @@ def __init__(self, template, boards, bit, spacing, margins, caul_trim):
self.board_TDD = None

# Caul template
if self.template.do_caul:
if config.show_caul:
caul_trim = max(1, bit.units.abstract_to_increments(config.caul_trim))
self.rect_caul = My_Rectangle(margins.left, y,
template.length, template.height)
self.board_caul = My_Rectangle(self.rect_caul.xL() + template.margin, y, \
Expand Down

0 comments on commit 34ebfe8

Please sign in to comment.