Example #1
0
 def develop(self, parameter_s=''):
     # reload(classes)
     import reimport, os
     mod = reimport.modified()
     reimport.reimport(*mod)
     print 'Done re-importing'
     # reload(periodograms)
     # reload(core)
     os.system('python scons/scons.py --gfortran=/home/joao/Software/mesasdk/bin/gfortran')
    def reloadHardwareObjects(self):
        """
        Reloads all modified modules.
        Package reimport is used to detect modified modules.
        Hardware objects that correspond to these modules:
        1. are disconnected from gui
        2. imported in this module with __import__ and reimport is called
        3. connected back to the gui channels
        """
        # NOTE
        # reimport is supported for python 2.x and not by python 3.x
        # if needed a similar package for 3x could be used. In this case
        # code depends on a platform: platform.python_version()[0] > 2 ...

        import reimport

        modified_modules = reimport.modified()
        for hwr_obj in self.hardwareObjects:
            for item in modified_modules:
                if self.hardwareObjects[hwr_obj].__module__ == item:
                    try:
                        connections = self.hardwareObjects[hwr_obj].connect_dict
                        for sender in connections:
                            self.hardwareObjects[hwr_obj].disconnect(
                                sender,
                                connections[sender]["signal"],
                                connections[sender]["slot"],
                            )
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s disconnected from GUI" % item
                        )
                        self.hardwareObjects[hwr_obj].clear_gevent()
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to disconnect hwobj %s" % item
                        )
                        continue

                    try:
                        __import__(item, globals(), locals(), [], -1)
                        reimport.reimport(item)
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s reloaded" % item
                        )
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to reload module %s" % item
                        )

                    try:
                        for sender in connections:
                            self.hardwareObjects[hwr_obj].connect(
                                sender,
                                connections[sender]["signal"],
                                connections[sender]["slot"],
                            )
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s connected to GUI" % item
                        )
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to connect hwobj %s" % item
                        )
                    try:
                        self.hardwareObjects[hwr_obj].init()
                        self.hardwareObjects[hwr_obj].update_values()
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s initialized and updated" % item
                        )
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to initialize hwobj %s" % item
                        )
    def reloadHardwareObjects(self):
        """
        Reloads all modified modules.
        Package reimport is used to detect modified modules.
        Hardware objects that correspond to these modules:
        1. are disconnected from gui
        2. imported in this module with __import__ and reimport is called
        3. connected back to the gui channels
        """
        # NOTE
        # reimport is supported for python 2.x and not by python 3.x
        # if needed a similar package for 3x could be used. In this case
        # code depends on a platform: platform.python_version()[0] > 2 ...

        # NB reloadHardwareObjects does NOT work with beamline_opbject
        # and other yaml configs

        import reimport

        modified_modules = reimport.modified()
        for hwr_obj in self.hardwareObjects:
            for item in modified_modules:
                if self.hardwareObjects[hwr_obj].__module__ == item:
                    try:
                        connections = self.hardwareObjects[
                            hwr_obj].connect_dict
                        for sender in connections:
                            self.hardwareObjects[hwr_obj].disconnect(
                                sender,
                                connections[sender]["signal"],
                                connections[sender]["slot"],
                            )
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s disconnected from GUI",
                            item)
                        self.hardwareObjects[hwr_obj].clear_gevent()
                    except Exception:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to disconnect hwobj %s",
                            item)
                        continue

                    try:
                        __import__(item, globals(), locals(), [], -1)
                        reimport.reimport(item)
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s reloaded", item)
                    except Exception:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to reload module %s",
                            item)

                    try:
                        for sender in connections:
                            self.hardwareObjects[hwr_obj].connect(
                                sender,
                                connections[sender]["signal"],
                                connections[sender]["slot"],
                            )
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s connected to GUI", item)
                    except Exception:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to connect hwobj %s",
                            item)
                    try:
                        self.hardwareObjects[hwr_obj].init()
                        self.hardwareObjects[hwr_obj].re_emit_values()
                        logging.getLogger("HWR").debug(
                            "HardwareRepository: %s initialized and updated",
                            item)
                    except Exception:
                        logging.getLogger("HWR").exception(
                            "HardwareRepository: Unable to initialize hwobj %s",
                            item)
Example #4
0
from maya import OpenMaya, cmds
import PyGML
import reimport
for module in reimport.modified():
    print module
    reimport.reimport(module)

gmlFile = open('/Users/dkeegan/dev/mercurial/projects/pygml/SampleGML/134.gml', 'r')
gml = PyGML.GML(gmlFile)
gmlFile.close()

#gml = PyGML.GML()
#stroke = PyGML.Stroke()
#stroke.addPoint(0.0, 0.0, 0.0, 0.0)
#stroke.addPoint(0.0, 1.0, 0.0, 0.1)
#stroke.addPoint(0.0, 2.0, 0.0, 0.2)
#gml.addStroke(stroke)

for stroke in gml.iterStrokes():
    meshPoints = OpenMaya.MPointArray()
    meshPolyCounts = OpenMaya.MIntArray()
    meshPolyConnects = OpenMaya.MIntArray()
    
    indices, vertices = stroke.getPolyData(radius=0.04, sides=20, rotZ=False)
    for face in indices:
        meshPolyCounts.append(len(face))
        for index in face:
            meshPolyConnects.append(index)
    for vert in vertices:
        meshPoints.append(OpenMaya.MPoint(*vert.asArray()))