示例#1
0
 def readfile(self, fpath):
     furno, fixed, comment = 0, True, ''
     with open(fpath) as f:
         for l in f.readlines():
             l = l.strip('\t \r\n')
             if not l:
                 pass
             elif l.startswith('#'):
                 if fixed:
                     self.content.append(l[1:].strip())
                 else:
                     comment += l+'\n'
             elif l.startswith('$'):
                 fixed = False
             else:
                 if furno:
                     if fixed:
                         self.content.append(Contour(l).getPoints())
                     else:
                         self.buff.append((Contour(l), comment))
                         comment = ''
                 else:
                     self.contour = Contour(l)
                     self.autofit()
                 furno += 1
示例#2
0
 def writefile(self, fpath):
     with open(fpath,'w+') as f:
         f.write(self.contour.getInstruct())
         f.write('\n')
         for c in self.content:
             if type(c) is str:
                 f.write("# "+c)
             else:
                 cnt = Contour()
                 cnt.points = c
                 cnt.origin = c[0]
                 f.write(cnt.getInstruct())
             f.write('\n')
         f.write('$ fixed components end and drag ones begin\n')
         for b in self.buff:
             f.write(b[1])
             f.write(b[0].getInstruct(False))
             f.write('\n')
示例#3
0
 def dragFixedStaff(self, *pos):
     if self.contentIdxLocked:
         self.dragStaff.origin = self.rossecorp(Point(*pos))
         self.content[self.contentIdx] = self.dragStaff.getPoints()
         self.dragStaff = None
         self.contentIdx = -1
         self.contentIdxLocked = False
     elif self.content and 0<=self.contentIdx<len(self.content) and type(self.content[self.contentIdx]) is list:
         cnt = Contour()
         cnt.points = self.content[self.contentIdx]
         cnt.setInstruct(cnt.getInstruct())
         self.dragStaff = cnt
         self.content[self.contentIdx] = None
         self.contentIdxLocked = True
示例#4
0
class Application(Adaptor):
    def __init__(self, w, h):
        Adaptor.__init__(self, w, h)
        self.content = []
        self.buff = []
        self.dragStaff = None
        self.rulerPoint = None
        self.buffIdx = 0
        self.contentIdx = -1
        self.contentIdxLocked = False
        
        # xxxxxxx
        PYG.init()
        self.font = PYG.font.Font(None, 20)
        self.screen = PYG.display.set_mode(self.size(), 0, 32) 
        self.screen.fill(0xffffff00)
        
    def draw(self):
        self.screen.fill(0xffffff00)
        PYG.draw.lines(self.screen, 0, True, self.points(), 1)
        n = 0
        for c in self.content: 
            if type(c) is list: 
                PYG.draw.lines(self.screen, 0xff00 if n==self.contentIdx else 0, True, self.points(c), 1)
            n += 1
            
        if self.dragStaff:
            pos = PYG.mouse.get_pos()
            PYG.draw.lines(self.screen, 0xff000000, True, self.points(self.dragStaff.points, *pos), 1)
        if self.rulerPoint:
            pos = PYG.mouse.get_pos()
            PYG.draw.lines(self.screen, 0x0000ff00, True, (self.rulerPoint, pos), 1)
            dis = self.distanceBetween(self.rulerPoint, pos)
            self.screen.blit(self.font.render("%f"%dis, True, (255,0,0)), (pos[0]+20,pos[1]))

    def readfile(self, fpath):
        furno, fixed, comment = 0, True, ''
        with open(fpath) as f:
            for l in f.readlines():
                l = l.strip('\t \r\n')
                if not l:
                    pass
                elif l.startswith('#'):
                    if fixed:
                        self.content.append(l[1:].strip())
                    else:
                        comment += l+'\n'
                elif l.startswith('$'):
                    fixed = False
                else:
                    if furno:
                        if fixed:
                            self.content.append(Contour(l).getPoints())
                        else:
                            self.buff.append((Contour(l), comment))
                            comment = ''
                    else:
                        self.contour = Contour(l)
                        self.autofit()
                    furno += 1
    def writefile(self, fpath):
        with open(fpath,'w+') as f:
            f.write(self.contour.getInstruct())
            f.write('\n')
            for c in self.content:
                if type(c) is str:
                    f.write("# "+c)
                else:
                    cnt = Contour()
                    cnt.points = c
                    cnt.origin = c[0]
                    f.write(cnt.getInstruct())
                f.write('\n')
            f.write('$ fixed components end and drag ones begin\n')
            for b in self.buff:
                f.write(b[1])
                f.write(b[0].getInstruct(False))
                f.write('\n')
            
    def setDragStaff(self, *pos):
        if self.contentIdxLocked:
            self.dragFixedStaff(*pos)
            return
        self.dragStaff.origin = self.rossecorp(Point(*pos))
        self.content.append(self.dragStaff.getPoints())
        self.dragStaff = None
    def changeDragStaff(self):
        if self.buff:
            self.dragStaff = self.buff[self.buffIdx][0]
            self.buffIdx += 1
            if len(self.buff) <= self.buffIdx: self.buffIdx = 0
    def changeFixedStaff(self, drt):
        if self.content and not self.contentIdxLocked:
            loop = 0
            if drt > 0:
                while True:
                    self.contentIdx += 1
                    if self.contentIdx >= len(self.content):
                        self.contentIdx = 0
                        if loop==2:
                            self.contentIdx = -1
                            break
                        loop += 1
                    if type(self.content[self.contentIdx]) is list:
                        break
            else:
                while True:
                    self.contentIdx -= 1
                    if self.contentIdx < 0:
                        self.contentIdx = len(self.content)-1
                        if loop==2:
                            self.contentIdx = -1
                            break
                        loop += 1
                    if type(self.content[self.contentIdx]) is list:
                        break
    def deleteFixedStaff(self):
        if self.contentIdxLocked: return
        if self.content and 0<=self.contentIdx<len(self.content) and type(self.content[self.contentIdx]) is list:
            del self.content[self.contentIdx]
            self.contentIdx -= 1
    def dragFixedStaff(self, *pos):
        if self.contentIdxLocked:
            self.dragStaff.origin = self.rossecorp(Point(*pos))
            self.content[self.contentIdx] = self.dragStaff.getPoints()
            self.dragStaff = None
            self.contentIdx = -1
            self.contentIdxLocked = False
        elif self.content and 0<=self.contentIdx<len(self.content) and type(self.content[self.contentIdx]) is list:
            cnt = Contour()
            cnt.points = self.content[self.contentIdx]
            cnt.setInstruct(cnt.getInstruct())
            self.dragStaff = cnt
            self.content[self.contentIdx] = None
            self.contentIdxLocked = True
    def transZoom(self, func):
        if self.rulerPoint:
            p = self.rossecorp(Point(*self.rulerPoint))
        func()
        if self.rulerPoint:
            p = self.processor(p)
            self.rulerPoint = (p.x, p.y)