Ejemplo n.º 1
0
    def run(self, string, cmd=None):
        ''' parse the configuration string and execute the resulting tree'''

        debug = False
        if debug:
            sayW("parse2 ....")
        self.parse2(string)
        if debug:
            sayW("build ...#")
        rca = self.build()

        if debug:
            sayW("showSo ...")
        self.showSo()
        if cmd != None:
            say("CMD ...")
            say(cmd)
            rca = cmd()
            say(("rc run...", rca))
        return rca
Ejemplo n.º 2
0
def getData(fn, pb=None):

    if pb == None:
        pb = QtGui.QProgressBar()
        pb.show()

    stack = [0, 0] * 4
    stackpointer = -1

    objs = []

    say("Read data from cache file ...")
    say(fn)
    f = open(fn, "r")  #, encoding="utf8")
    content = f.readlines()

    c2 = []
    cl = len(content)

    # FreeCAD File hack
    if content[2].startswith(
            " FreeCAD Document, see http://www.freecadweb.org"):
        content = content[4:]

    cl = len(content)
    say(cl)

    i = -1
    pb.setMaximum(cl)
    while i < cl - 1:
        pb.setValue(i)
        i += 1

        line = content[i].strip()
        j = 0
        while re.search(r">\s*$", line) == None and j < 60:
            i += 1
            j += 1
            line += content[i]

        c2 += [line]
        line = ''

    content = c2
    pb.setMaximum(len(content))

    for lc, line in enumerate(content):

        if "<TextureHexString>" in line:
            say("break A")
            continue

        pb.setValue(lc)

        #		if lc%100 == 0:
        #			say(lc)
        #			Gui.updateGui()

        #		if stackpointer != -1:
        #			print (res.groups())
        #			print (stackpointer)

        #		print ("\n-------------NEXT:")
        #		print(line)
        #		print ("--- PARSE IT------------------------")

        if re.search(r"^\s*$", line):
            continue

        # ein satz
        res = re.search(r"^\s*<(\S+)\s+([^<]*)/>\s*$", line)
        if res != None:
            #			print ("complete! ",res.groups())
            assert len(res.groups()) == 2
            typ = res.group(1)
            obj = node(typ)
            paramstring = res.group(2)
            obj.params = parseParams(paramstring)
            objs += [obj]
            if stackpointer != -1:
                stack[stackpointer].content += [obj]
    #			print stack[stackpointer]
    #			for c in stack[stackpointer].content:
    #				print c,",",
    #			print
            continue

        res = re.search(r"^\s*<(\S+)\s+([^<]*)>\s*$", line)
        if res != None:
            #			print ("!start! ",res.groups())
            assert len(res.groups()) == 2
            typ = res.group(1)
            obj = node(typ)
            paramstring = res.group(2)
            obj.params = parseParams(paramstring)
            objs += [obj]

            if stackpointer != -1:
                stack[stackpointer].content += [obj]
    #			for c in stack[stackpointer].content:
    #				print c,
            stackpointer += 1
            stack[stackpointer] = obj
            continue

        res = re.search(r"^\s*</([^<]*)>\s*$", line)
        if res != None:
            #			print ("!ende---------STACKPOINTER down! ",res.groups())
            assert len(res.groups()) == 1
            stackpointer -= 1
            continue

        res = re.search(r"^\s*<([^<\s]*)>\s*$", line)
        if res != None:
            #			print ("!simple start! ",res.groups())
            assert len(res.groups()) == 1
            typ = res.group(1)
            obj = node(typ)

            if stackpointer != -1:
                stack[stackpointer].content += [obj]

            stackpointer += 1
            stack[stackpointer] = obj

            continue

        #auf und zu
        res = re.search(r"^\s*<(\S+)\s*([^<]*)>(.*)</([^<]+)>\s*$", line)
        if res != None:
            #			print ("!alles! ",res.groups())
            assert len(res.groups()) == 4
            typ = res.group(1)
            obj = node(typ)
            paramstring = res.group(2)
            obj.params = parseParams(paramstring)
            obj.text = res.group(3)
            objs += [obj]

            if stackpointer != -1:
                stack[stackpointer].content += [obj]
    #			for c in stack[stackpointer].content:
    #				print c,
    #		stackpointer += 1
    #		stack[stackpointer]=obj

            continue

        raise Exception("unerwartet :" + line + ":")
    #	x = re.findall('<([^<]*)>', line)
    #	for xl in x:
    #		print(xl)


#	say("done getit--------")

    FreeCAD.stackpointer = stackpointer
    FreeCAD.stack = stack
    FreeCAD.objs = objs

    return stack[0]
Ejemplo n.º 3
0
    pb = QtGui.QProgressBar()
    pb.show()
    #	progressbar.setValue(0)

    #import geodat.my_xmlparser
    #reload (geodat.my_xmlparser)

    from say import *

    # tree=geodat.my_xmlparser.getData(fn)

    tree = getData(fn)
    # tree=FreeCAD.stack[0]

    say("import done")

    Gui.updateGui()
    Ps = {}
    pnodes = tree.getiterator('P')
    pb.setMaximum(len(pnodes))

    for i, element in enumerate(pnodes):
        pb.setValue(i)
        #		say((element.params,element.text))
        _coords = element.text.split(' ')
        Ps[element.params['id']] = FreeCAD.Vector(float(_coords[0]),
                                                  float(_coords[1]),
                                                  float(_coords[2]))

    import Points
Ejemplo n.º 4
0
    def report(self, results=None):
        '''some debug information about objects, anchors, roots'''
        say("Results ...")
        if results == None:
            results = []
        for r in results:
            say(r)
            if r.__class__.__name__.startswith('So'):
                sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
                sg.addChild(r)

        say("Data ...")
        for ob in self.objects:
            say(ob)

        say(self.anchors)

        for r in self.roots():
            say(r)
Ejemplo n.º 5
0
    def addChild(self, parent, child):
        ''' add the child to the parent during the build'''

        p = parent
        c = child
        cc = c.__class__.__name__
        if 0:
            say(p)
            say(p.__class__)
            say('--')
            say(c)
            say(c.__class__)
            say(cc)


#		if str(c.__class__).startswith("<type 'PySide.QtGui.") or  str(c.__class__).startswith("<class 'nurbswb.miki"):
        if str(c.__class__).startswith("<class 'PySide2.QtWidgets.") or \
         str(c.__class__).startswith("<type 'PySide.QtGui.") or  str(c.__class__).startswith("<class 'nurbswb.miki"):

            if p.__class__.__name__ == '_MyTabWidget':
                p.addWidget(c)
            else:
                p.layout.addWidget(c)
            return

        if cc.startswith('So'):
            p.addChild(c)
            return

        if p.__class__.__name__ == 'object' or \
         str(p.__class__).startswith("<class 'geodat.miki."):
            # "Add children to object"
            try:
                p.children.append(c)
            except:
                p.children = [c]
            return
        try:
            if str(p.TypeId) == 'Part::MultiFuse':
                z = p.Shapes
                z.append(c)
                p.Shapes = z
            elif str(p.TypeId) == 'Part::Compound':
                z = p.Links
                z.append(c)
                p.Links = z
            else:
                try:
                    p.addObject(c)
                except:
                    try:
                        if c.startswith('__MAGIC_'):
                            run_magic(p, c)
                    except:
                        FreeCAD.Console.PrintError(
                            "\naddObject funktioniert nicht A")
                        FreeCAD.Console.PrintError([p, c])
        except:
            try:
                print("TRy to add", c)
                p.addObject(c)
            except:
                try:
                    if c.startswith('__MAGIC_'):
                        run_magic(p, c)
                except:
                    FreeCAD.Console.PrintError(
                        "\naddObject funktioniert nicht BBB")
                    FreeCAD.Console.PrintError([p, c])
Ejemplo n.º 6
0
    def build(self):
        '''execute the parsed data (expected in self.lines)'''
        ##\cond
        self.widget = None
        ##\endcond
        #		from pivy import coin
        #		from pivy.coin import *

        for l in self.lines:

            if l[3] == 'cmd':
                try:
                    exec(l[4])
                except:
                    sayexc(str(["Error exec:", l[4]]))
                continue
            if l[3] == 'obj' or l[3] == 'anchor' or l[3] == 'local class':
                name = l[4]
                try:
                    f = name + "()"
                    f2 = name
                except:
                    f = creatorFunction(l[4])

                f = creatorFunction(l[4])

                if len(l) < 7:  # no name for object
                    l.append('')

                if l[3] == 'local class':
                    exec("class " + name + "(object):pass")
                    h = eval(f2)
                else:
                    h = eval(f)
                if len(l) < 7:
                    l.append(None)
                l.append(h)
                self.objects.append(h)
                ##\cond
                if self.widget == None:
                    self.widget = h
                ##\endcond
            if l[2] != 0:
                if l[4] == 'Name':
                    continue
                if l[3] == 'obj' or l[3] == 'anchor':
                    parent = self.lines[l[2]][7]
                    self.addChild(parent, l[7])
                if l[3] == 'link':
                    parent = self.lines[l[2]][7]
                    try:
                        child = self.lines[l[6]][7]
                        self.addChild(parent, child)
                    except:
                        # link eines attribs
                        method = l[4]
                        v = self.lines[l[6]][6]
                        kk = eval("parent." + l[4])
                        cnkk = kk.__class__.__name__

                        if cnkk.startswith('So'):
                            ex = "parent." + method + ".setValue(" + str(
                                v) + ")"
                            exec(ex)
                            continue
                        if cnkk == 'builtin_function_or_method':
                            kk(v)
                            continue

                        cn = v.__class__.__name__
                        if cn == 'int' or cn == 'float':
                            ex = "parent." + l[4] + "=" + str(v)
                        elif cn == 'str':
                            ex = "parent." + l[4] + "='" + v + "'"
                        else:
                            sayW("nicht implementierter typ")
                            sayW([v, cn])
                            sayW(l)
                            ex = ''
                        exec(ex)

            if l[3] == 'att val' or l[3] == 'anchor attr':

                method = l[4]
                parent = self.lines[l[2]][7]

                if l[3] == 'att val':
                    v = l[5]
                else:
                    v = l[6]
                if method == 'id':
                    self.ids[v] = parent
                    continue

                try:
                    kk = eval("parent." + l[4])
                except:

                    cn = v.__class__.__name__
                    if cn == 'int' or cn == 'float':
                        ex = "parent." + l[4] + "=" + str(v)
                    elif cn == 'str':
                        ex = "parent." + l[4] + "='" + v + "'"
                    elif cn == 'Vector':
                        sayW("nicht implementierter typ  Ax")
                        sayW([v, cn])
                        sayW(l)
                        sayW(parent)
                        ex = "parent." + l[4] + "(FreeCAD." + str(v) + ")"
                        sayW("*** " + ex)
                    elif l[4] == 'setValue':
                        parent.setValue(v)
                        continue
                    else:
                        sayW("nicht implementierter typ  Ayy")
                        sayW([v, cn])
                        sayW(l)
                        ex = ''

                    exec(ex)
                    continue

                kk = eval("parent." + l[4])
                cnkk = kk.__class__.__name__
                if cnkk.startswith('So'):
                    if v.__class__.__name__.startswith('Sb'):
                        aaa = v
                        ex = "parent." + method + ".setValue(aaa)"
                    else:
                        ex = "parent." + method + ".setValue(" + str(v) + ")"
                    exec(ex)
                    continue

                if cnkk == 'builtin_function_or_method':
                    kk(v)
                    continue

                cn = v.__class__.__name__
                if cn == 'int' or cn == 'float':
                    ex = "parent." + l[4] + "=" + str(v)
                elif cn == 'str':
                    if l[4].startswith("run"):
                        ex = "parent." + l[4] + "('" + v + "')"
                    else:
                        ex = "parent." + l[4] + "='" + v + "'"
                elif cn == 'Vector':
                    ex = "parent." + l[4] + "(FreeCAD." + str(v) + ")"
                else:
                    sayW("nicht implementierter typ B")
                    sayW([v, cn])
                    sayW(l)
                    aaa = v
                    ex = "parent." + l[4] + "(aaa)"
                say("//*** " + ex)
                exec(ex)

        return self.widget
Ejemplo n.º 7
0
    def parse2(self, configurationString):
        '''parse the configuration string'''

        ls = configurationString.splitlines()

        # pylint: disable=unused-variable
        app = self.app
        line = 0
        depth = 0
        d = [0] * 30
        ln = [0] * 30
        refs = {}
        rs = []
        r = None
        r = [-1, 0, 0, '']
        for l in ls:
            ltxt = l

            if r:
                rs.append(r)
                r = [-1, 0, 0, '']
            line += 1

            if l.startswith('#:'):
                res = re.search(r"#:\s*(\S.*)", l)
                r = [l, line, -1, 'cmd', res.group(1)]
                continue

            if re.search(r"^\W*#", l):
                continue

            res = re.search(r"\<(\S.*)\>:", l)
            if res:
                parent = 0
                ln[0] = line
                depth = 0
                r = [l, line, parent, "local class", res.group(1)]
                self.classes[res.group(1)] = line
                continue

            res = re.search(r"(\s*)(\S.*)", l)
            if res:
                l = len(res.group(1))

                if l == 0:
                    depth = 0
                if d[depth] < l:
                    depth += 1
                elif d[depth] > l:
                    depth -= 1
                try:
                    d[depth] = l
                except:
                    sayexc(str([l, ltxt]))

                parent = ln[l - 1]
                ln[l] = line

                r = [l, line, parent, res.group(2), depth, ln]
                st = res.group(2)

                res = re.search(r"(\S+):\s*\*(\S+)", st)
                if res:
                    r = [
                        l, line, parent, 'link',
                        res.group(1),
                        res.group(2), refs[res.group(2)]
                    ]
                    continue

                res = re.search(r"(\S+):\s*&(\S+)\s+(\S.*)", st)
                if res:
                    r = [
                        l, line, parent, "anchor attr",
                        res.group(1),
                        res.group(2),
                        res.group(3)
                    ]
                    refs[res.group(2)] = line
                    continue

                res = re.search(r"(\S+):\s*&(\S+)", st)
                if res:
                    r = [l, line, parent, "anchor", res.group(1), res.group(2)]
                    refs[res.group(2)] = line
                    continue

                res = re.search(r"(\S+[^:]):\s*([^:]\S.*)", st)
                if res:
                    r = [
                        l, line, parent, "att val",
                        res.group(1),
                        eval(res.group(2))
                    ]
                    if res.group(1) == 'Name':
                        rs[parent].append(res.group(2))
                    continue

                res = re.search(r"\s*(\S):\s*([^:]\S.*)", st)
                if res:
                    r = [
                        l, line, parent, "att val",
                        res.group(1),
                        eval(res.group(2))
                    ]
                    if res.group(1) == 'Name':
                        rs[parent].append(res.group(2))
                    continue
                else:
                    res = re.search(r"(\S+):", st)
                    if res:
                        r = [l, line, parent, "obj", res.group(1), 'no anchor']
        ##\cond
        self.anchors = refs
        self.lines = rs
        ##\endcond

        #debug = getcb("mikidebug")
        debug = 0
        #debug = 1
        if debug:
            say("lines parsed ...")
            for r in rs:
                say(r)
            if len(self.anchors.keys()) > 0:
                say("Anchors ....")
                say(self.anchors)
Ejemplo n.º 8
0
 def itemClicked(self, item):
     '''example for item clicked'''
     say(item)
     say(item.text())
Ejemplo n.º 9
0
 def run(self):
     '''example button clicked method'''
     say("Button clicked")
     say(self.root)
     say(self.root.widget)
Ejemplo n.º 10
0
	setSpacer:
	'''

    if mode == 'VerticalLayoutTab':
        layout = layoutVT
    elif mode == 'MainWindow':
        layout = layoutMW
    elif mode == 'DockWidget':
        layout = layoutDW

    mikigui = createMikiGui(layout, MikiApp)
    return mikigui


if __name__ == '__main__':
    say("miki transport ...")
    testme()


def testDialogMainWindow():
    return testme("MainWindow")


def testDialogTab():
    return testme('VerticalLayoutTab')


def testDialogDockWidget():
    return testme("DockWidget")