def summaryln(self): """Return a very brief summary of the job as a list of strings.""" numcabs = self.cabs.num_cabinets cabwidth = self.cabs.cabinet_width summary = (str(numcabs) + (' cabinet' if numcabs == 1 else ' cabinets') + ' measuring ' + dimstr(cabwidth) + '" ' + 'totalling ' + dimstr(cabwidth * numcabs) + '"') if self.cabs.fillers is Ends.NEITHER: summary += (', with finished end panels on left and right.' ' No filler panels required.') elif self.cabs.fillers is Ends.LEFT: summary += (', with a ' + dimstr(self.cabs.filler_width) + '" filler on the left.') elif self.cabs.fillers is Ends.RIGHT: summary += (', with a ' + dimstr(self.cabs.filler_width) + '" filler on the right.') elif self.cabs.fillers is Ends.BOTH: summary += (', with two (2) ' + dimstr(self.cabs.filler_width) + '" fillers.') else: raise TypeError('fillers is not Ends.NEITHER, .LEFT, .RIGHT,' ' or .BOTH') if self.cabs.has_legs: summary += (' To be mounted on legs.') return [summary]
def cabinfo(self): """Return number of cabinets needed and cabinet width as list of strings.""" result = [] result.append('Number of cabinets needed: ' + str(self.cabs.num_cabinets)) result.append('Single cabinet width: ' + dimstr(self.cabs.cabinet_width) + '"') return result
def add_hdimstr_beside(arrow, dim, x, y): """Add a dim label to the given horiz dim arrow, outside the bounds.""" dim_str = String(x - 11 - 2, y - 3, dimstr(dim) + '"', textAnchor='end', fontSize=9) arrow.add(dim_str) return arrow
def get_dimstr_bounds(dim, scale, x, y): """Return the bounds rect of the string for the given dimension.""" dim_scaled = dim * inch * scale dim_str = String(x + dim_scaled / 2, y - 3, dimstr(dim) + '"', textAnchor='middle', fontSize=9) result = dim_str.getBounds() return result
def add_vdimstr(arrow, dim, scale, x, y, boundsln_len): """Add a measurement label to the given vertical dimension arrow.""" dim_scaled = dim * inch * scale dim_str = String(x + boundsln_len / 2 + 2, y + dim_scaled / 2 - 4, dimstr(dim) + '"', textAnchor='end', fontSize=9) bnds = dim_str.getBounds() whiteout_r = Rect(bnds[0], bnds[1], bnds[2] - bnds[0], dim_str.fontSize, fillColor=colors.white, strokeColor=colors.white) arrow.add(whiteout_r) arrow.add(dim_str) return arrow
def add_hdimstr(arrow, dim, scale, x, y): """Add a measurement label to the given horizontal dimension arrow.""" dim_scaled = dim * inch * scale dim_str = String(x + dim_scaled / 2, y - 3, dimstr(dim) + '"', textAnchor='middle', fontSize=9) bounds_rect = dim_str.getBounds() whiteout_rect = Rect(bounds_rect[0], bounds_rect[1], bounds_rect[2] - bounds_rect[0], bounds_rect[3] - bounds_rect[1], fillColor=colors.white, strokeColor=colors.white) arrow.add(whiteout_rect) arrow.add(dim_str) return arrow
def add_vdimstr_iso(arrow, dim, scale, x, y, boundsln_len): """Add a measurement label to the given isometric vert dimension arrow.""" dim_scaled = dim * inch * scale off = math.sqrt((boundsln_len / 2)**2 / 2) dim_str = String(x - off - 2, y + dim_scaled / 2 - 4, dimstr(dim) + '"', textAnchor='start', fontSize=9) bnds = dim_str.getBounds() whiteout_r = Rect(bnds[0], bnds[1], bnds[2] - bnds[0], dim_str.fontSize, fillColor=colors.white, strokeColor=colors.white) arrow.add(whiteout_r) arrow.add(dim_str) return arrow
def add_ddimstr_iso(arrow, dim, scale, x, y, boundsln_len): """Add a measurement label to the given isometric depth dimension arrow.""" dim_scaled = dim * inch * scale # `iso45' is divided by 2 below because that is how it's calculated # in the isometric_view, above. iso45 = math.sin(math.radians(45)) * dim_scaled / 2 xmid, ymid = x + iso45 / 2, y + iso45 / 2 dim_str = String(xmid - boundsln_len / 2 - 4, ymid - 4, dimstr(dim) + '"', textAnchor='start', fontSize=9) bnds = dim_str.getBounds() whiteout_r = Rect(bnds[0], bnds[1], bnds[2] - bnds[0], dim_str.fontSize, fillColor=colors.white, strokeColor=colors.white) arrow.add(whiteout_r) arrow.add(dim_str) return arrow
def test_zero(self): assert DS.dimstr(0) == '0'
def test_eleven_and_two_sevenths(self): # We need the `.' in `2./7' for this not to fail on Python 2.7. # Do we care about supporting Python 2.7, since it's EOL? assert DS.dimstr(11 + 2./7) == '11 5/16-'
def test_one_eighth(self): assert DS.dimstr(0.125) == '1/8'
def test_one_fourth(self): assert DS.dimstr(0.25) == '1/4'