示例#1
0
 def test_top_pos(self):
     """TestTreePlotTransform.incPhysicalChildPos(): top, +"""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top',
                                                 sweepDir='+')
     childPhysicalPt = self._pt
     # Starting point
     self.assertEqual(myObj.pt(self._pt), childPhysicalPt)
     # First increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[0])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36, None),
             Coord.Dim(250, None),
         ))
     # Second increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[1])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36 - 101, None),
             Coord.Dim(250, None),
         ))
     # Third increment
     childPhysicalPt = myObj.incPhysicalChildPos(childPhysicalPt,
                                                 self._childIncS[2])
     self.assertEqual(
         childPhysicalPt,
         Coord.Pt(
             Coord.Dim(400 - 36 - 101 - 74, None),
             Coord.Dim(250, None),
         ))
示例#2
0
    def test_07(self):
        """TestSVGlWriter.test_07(): text.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/text.html#TextElement"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort,
                                 {'viewBox': "0 0 1000 300"}) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters("Example text01 - 'Hello, out there' in blue")
            myPt = Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(150))
            with SVGWriter.SVGText(xS, myPt, "Verdans", 55, {'fill': "blue"}):
                xS.characters('Hello, out there')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(998), Coord.baseUnitsDim(298))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
        #print
        #print myF.getvalue()
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" viewBox="0 0 1000 300" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example text01 - &apos;Hello, out there&apos; in blue</desc>
  <text fill="blue" font-family="Verdans" font-size="55" x="250px" y="150px">Hello, out there</text>
  <rect fill="none" height="298px" stroke="blue" stroke-width="2" width="998px" x="1px" y="1px" />
</svg>
""")
示例#3
0
 def test_pcRoll(self):
     #parentChildTakeoffPoint
     #print
     #print 'myObj.parentChildTakeoffPoint[0]:', myObj.parentChildTakeoffPoint(myD, 0)
     self.assertEqual(
         self._pnbcObj.pcRoll(self._logicalDatum, 0),
         Coord.Pt(
             Coord.Dim(158.5, 'mm'),
             Coord.Dim(32, 'mm'),
         ))
     #print
     #print 'myObj.parentChildTakeoffPoint[1]:', myObj.parentChildTakeoffPoint(myD, 1)
     self.assertEqual(
         self._pnbcObj.pcRoll(self._logicalDatum, 1),
         Coord.Pt(
             Coord.Dim(162.5, 'mm'),
             Coord.Dim(32, 'mm'),
         ))
     #print
     #print 'myObj.parentChildTakeoffPoint[2]:', myObj.parentChildTakeoffPoint(myD, 2)
     self.assertEqual(
         self._pnbcObj.pcRoll(self._logicalDatum, 2),
         Coord.Pt(
             Coord.Dim(166.5, 'mm'),
             Coord.Dim(32, 'mm'),
         ))
示例#4
0
 def testCentre_02(self):
     """Tests PlotNode() get the centre point."""
     myObj = PlotNode.PlotNodeBbox()
     myObj.width = Coord.Dim(3, 'in')
     self.assertEqual(myObj.width, Coord.Dim(3, 'in'))
     myObj.depth = Coord.Dim(1, 'in')
     self.assertEqual(myObj.depth, Coord.Dim(1, 'in'))
     myPad = Coord.Pad(
         Coord.Dim(0.1, 'in'),  # prev
         Coord.Dim(0.3, 'in'),  # next
         Coord.Dim(0.5, 'in'),  # parent
         Coord.Dim(0.7, 'in'),  # child
     )
     myObj.bbSelfPadding = myPad
     myObj.bbSpaceChildren = Coord.Dim(0.9, 'in')
     self.assertEqual(
         myObj.plotPointCentre(
             Coord.Pt(
                 Coord.Dim(0.0, 'in'),
                 Coord.Dim(0.0, 'in'),
             ), ),
         Coord.Pt(
             Coord.Dim(1.6, 'in'),
             Coord.Dim(1.0, 'in'),
         ),
     )
示例#5
0
 def testCmp_04(self):
     """Pt() cmp() is +1 for y."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(11, 'pc'),
     )
     self.assertTrue(myPt_0 > myPt_1)
示例#6
0
 def testCmp_01(self):
     """Pt() cmp() is -1 for x."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(73, 'px'),
         Coord.Dim(12, 'pc'),
     )
     self.assertTrue(myPt_0 < myPt_1)
示例#7
0
 def testCmp_00(self):
     """Pt() cmp() is 0."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(12, 'pc'),
     )
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
示例#8
0
    def test_01(self):
        """TestSVGlWriter.test_01(): <desc> and four rectangles.
        From second example in http://www.w3.org/TR/2003/REC-SVG11-20030114/struct.html#NewDocumentOverview"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(5, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters('Four separate rectangles')
            myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(0.5, 'cm'))
            myBx = Coord.Box(Coord.Dim(2.0, 'cm'), Coord.Dim(1.0, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(2.0, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(1.5, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(3.0, 'cm'), Coord.Dim(0.5, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.5, 'cm'), Coord.Dim(2.0, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(3.5, 'cm'), Coord.Dim(3.0, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(0.5, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(0.01, 'cm'), Coord.Dim(0.01, 'cm'))
            myBx = Coord.Box(Coord.Dim(4.98, 'cm'), Coord.Dim(3.98, 'cm'))
            with SVGWriter.SVGRect(xS,
                                   myPt,
                                   myBx,
                                   attrs={
                                       'fill': "none",
                                       'stroke': "blue",
                                       'stroke-width': ".02cm",
                                   }):
                pass
        #print
        #print myF.getvalue()
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" width="5.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Four separate rectangles</desc>
  <rect height="1.00cm" width="2.00cm" x="0.50cm" y="0.50cm" />
  <rect height="1.50cm" width="1.00cm" x="0.50cm" y="2.00cm" />
  <rect height="2.00cm" width="1.50cm" x="3.00cm" y="0.50cm" />
  <rect height="0.50cm" width="1.00cm" x="3.50cm" y="3.00cm" />
  <rect fill="none" height="3.98cm" stroke="blue" stroke-width=".02cm" width="4.98cm" x="0.01cm" y="0.01cm" />
</svg>
""")
示例#9
0
文件: test_Coord.py 项目: cybort/cpip
 def test_convertPt(self):
     myPt = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(36, 'px'),
     )
     myResult = Coord.convertPt(myPt, 'in')
     expected = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(0.5, 'in'),
     )
     # print()
     # print(myResult)
     self.assertEqual(myResult, expected)
示例#10
0
 def testConvert_01(self):
     """Pt() convert() [01]."""
     myPt_0 = Coord.Pt(
         Coord.Dim(20, 'mm'),
         Coord.Dim(10, 'mm'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(20 * 72 / 25.4, 'px'),
         Coord.Dim(10 * 72 / 25.4, 'px'),
     )
     myPt_0 = myPt_0.convert('px')
     #print myPt_1
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
示例#11
0
 def testConvert_00(self):
     """Pt() convert() [00]."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(12, 'pc'),
     )
     myPt_1 = myPt_1.convert('in')
     #print myPt_1
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
示例#12
0
文件: test_Coord.py 项目: cybort/cpip
 def test_scale(self):
     """Pt() scale() [01]."""
     myPt = Coord.Pt(
         Coord.Dim(8, 'mm'),
         Coord.Dim(4, 'mm'),
     )
     expected = Coord.Pt(
         Coord.Dim(4, 'mm'),
         Coord.Dim(2, 'mm'),
     )
     myPt_scaled = myPt.scale(0.5)
     #print myPt_1
     self.assertEqual(myPt_scaled, expected)
     self.assertTrue(myPt_scaled == expected)
示例#13
0
文件: IncGraphSVG.py 项目: csarn/cpip
 def _writeScaleControls(self, theSvg):
     """Write the text elements that control re-scaling."""
     myAttrs = {
         'class': self.CLASS_TEXT_SCALE,
     }
     myPointP = Coord.Pt(
         Coord.Dim(8.0, self.COMMON_UNITS),
         Coord.Dim(4.0, self.COMMON_UNITS),
     )
     with SVGWriter.SVGGroup(theSvg, {'id': 'scaleGroup'}):
         with SVGWriter.SVGText(theSvg, myPointP, None, None, myAttrs):
             theSvg.characters('Select scale (bold selected):')
         myAttrs['text-decoration'] = "underline"
         myPointP = Coord.newPt(myPointP,
                                incX=Coord.Dim(64, 'mm'),
                                incY=None)
         for scale in self.SCALE_FACTORS:
             myAttrs['onclick'] = "scaleGraphic(%s, '%s')" % (scale, scale)
             myAttrs['id'] = str(scale)
             if scale == self._scale:
                 myAttrs['font-weight'] = 'bold'
             else:
                 myAttrs['font-weight'] = 'normal'
             text = '%d%%' % int(scale * 100)
             with SVGWriter.SVGText(theSvg, myPointP, None, None, myAttrs):
                 theSvg.characters(text)
             myPointP = Coord.newPt(myPointP,
                                    incX=Coord.Dim(5 * len(text), 'mm'),
                                    incY=None)
示例#14
0
 def test_pcStop(self):
     """TestPlotNodeBboxRoundy.test_01() - test pcStop()."""
     #print
     #print 'myObj.pcStop', self._pnbcObj.pcStop(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(28, 'mm'), Coord.Dim(189, 'mm')),
         self._pnbcObj.pcStop(self._logicalDatum),
     )
示例#15
0
 def test_cpTo(self):
     """TestPlotNodeBboxRoundy.test_01() - test cpTo()."""
     #print
     #print 'myObj.cpTo', self._pnbcObj.cpTo(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(28.0, 'mm'), Coord.Dim(185.0, 'mm')),
         self._pnbcObj.cpTo(self._logicalDatum),
     )
示例#16
0
 def test_pcTo(self):
     """TestPlotNodeBboxBoxyChildren.test_pcTo() - test pcTo()."""
     self.assertEqual(self._pnbcObj.pcTo(self._logicalDatum, 0),
                      Coord.Pt(
                          Coord.Dim(23, 'mm'),
                          Coord.Dim(195, 'mm'),
                      ))
     self.assertEqual(self._pnbcObj.pcTo(self._logicalDatum, 1),
                      Coord.Pt(
                          Coord.Dim(27, 'mm'),
                          Coord.Dim(195, 'mm'),
                      ))
     self.assertEqual(self._pnbcObj.pcTo(self._logicalDatum, 2),
                      Coord.Pt(
                          Coord.Dim(31, 'mm'),
                          Coord.Dim(195, 'mm'),
                      ))
示例#17
0
 def testStr(self):
     """Pt() __str__()."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(str(myPt), 'Pt(x=Dim(12px), y=Dim(24px))')
示例#18
0
 def test_pcStop(self):
     """TestPlotNodeBboxBoxyChildren.test_01() - test pcStop()."""
     #print
     #print 'myObj.pcStop', self._pnbcObj.pcStop(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(42.5, 'mm'), Coord.Dim(180 + 5, 'mm')),
         self._pnbcObj.pcStop(self._logicalDatum),
     )
示例#19
0
 def test_cpRoll(self):
     """TestPlotNodeBboxBoxy.test__pcRoll() - test cpRoll()."""
     #print
     #print 'myObj.cpStart', self._pnbcObj.cpStart(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(22 + 12, 'mm'), Coord.Dim(180 + 5, 'mm')),
         self._pnbcObj.cpRoll(self._logicalDatum),
     )
示例#20
0
 def test_pcLand(self):
     """TestPlotNodeBboxBoxy.test_pcLand() - test pcLand()."""
     #print
     #print 'myObj.pcLand', self._pnbcObj.pcLand(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(22, 'mm'), Coord.Dim(180, 'mm')),
         self._pnbcObj.pcLand(self._logicalDatum),
     )
示例#21
0
 def test_cpTo(self):
     """TestPlotNodeBboxBoxyChildren.test_01() - test cpTo()."""
     #print
     #print 'myObj.cpTo', self._pnbcObj.cpTo(self._logicalDatum)
     self.assertEqual(
         Coord.Pt(Coord.Dim(42.5 + 12, 'mm'), Coord.Dim(180, 'mm')),
         self._pnbcObj.cpTo(self._logicalDatum),
     )
示例#22
0
 def testIncWD_bottom(self):
     """TreePlotTransform.tdcL()/.tdcP(): bottom."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='bottom')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(49, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(243, None),
             Coord.Dim(451, None),
         ),
     )
示例#23
0
 def testIncWD_right(self):
     """TreePlotTransform.tdcL()/.tdcP(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(461, None),
             Coord.Dim(17, None),
         ),
     )
示例#24
0
 def testIncWD_top(self):
     """TreePlotTransform.tdcL()/.tdcP(): top."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='top')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(29, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(57, None),
             Coord.Dim(29, None),
         ),
     )
示例#25
0
 def testIncWD_left(self):
     """TreePlotTransform.tdcL()/.tdcP(): left."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='left')
     self.assertEqual(
         myObj.tdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(97, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.tdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(39, None),
             Coord.Dim(203, None),
         ),
     )
示例#26
0
 def testConstructor(self):
     """Pt() constructor."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(myPt.x, Coord.Dim(12, 'px'))
     self.assertEqual(myPt.y, Coord.Dim(24, 'px'))
示例#27
0
 def setUp(self):
     self._canvas = Coord.Box(
         Coord.Dim(300, None),
         Coord.Dim(500, None),
     )
     self._pt = Coord.Pt(
         Coord.Dim(17, None),
         Coord.Dim(29, None),
     )
示例#28
0
 def test_bdcL_bdcP_left(self):
     """TreePlotTransform.bdcL()/.bdcP(): left."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='left')
     self.assertEqual(
         myObj.bdcL(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(17, None),
             Coord.Dim(39, None),
         ),
     )
     self.assertEqual(
         myObj.bdcP(self._pt, self._box),
         Coord.Pt(
             Coord.Dim(39, None),
             Coord.Dim(283, None),
         ),
     )
示例#29
0
 def testPt_right(self):
     """TestTreePlotTransformPt.pt(): right."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='right')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(500 - 29, None),
             Coord.Dim(17, None),
         ),
     )
示例#30
0
 def testPt_bottom(self):
     """TestTreePlotTransformPt.pt(): bottom."""
     myObj = TreePlotTransform.TreePlotTransform(self._canvas,
                                                 rootPos='bottom')
     self.assertEqual(
         myObj.pt(self._pt),
         Coord.Pt(
             Coord.Dim(300 - 17, None),
             Coord.Dim(500 - 29, None),
         ),
     )