Exemple #1
0
    def setUpClass(cls):
        cls.hub = samp.SAMPHubServer()
        cls.hub.start()

        time.sleep(5)

        thread.start_new_thread(mtypes.main, ())
        cls.cli = samp.SAMPIntegratedClient()
        cls.cli.connect()

        time.sleep(5)
Exemple #2
0
    def __init__(self, addr='localhost', hub=True):
        # Before we start, let's kill off any zombies
        if hub:
            # sampy seems to fall over sometimes if 'localhost' isn't specified
            # even though it shouldn't
            self.hub = sampy.SAMPHubServer(addr=addr)
            self.hub.start()
        else:
            self.hub = None

        self.metadata = {
            'samp.name': 'Python Session',
            'samp.icon.url':
            'http://docs.scipy.org/doc/_static/img/scipyshiny_small.png',
            'samp.description.text': 'Python Samp Module',
            'client.version': '0.1a'
        }

        self.client = sampy.SAMPIntegratedClient(metadata=self.metadata,
                                                 addr=addr)
        self.client.connect()
        atexit.register(self.client.disconnect)

        # Bind interaction functions - we will register that we want to listen
        # for table.highlight.row (the SAMP highlight protocol), and all the
        # typical SAMP-stuff We could include this to listen for other sorts of
        # subscriptions like pointAt(), etc.
        #self.client.bindReceiveNotification('table.highlight.row', self.highlightRow)
        #self.client.bindReceiveNotification('table.select.rowList', self.getrows)
        self.client.bindReceiveNotification('table.highlight.row',
                                            self.getrows)
        self.client.bindReceiveNotification('table.load.fits',
                                            self.receiveNotification)
        self.client.bindReceiveNotification('samp.app.*',
                                            self.receiveNotification)

        self.client.bindReceiveCall('samp.app.*', self.receiveCall)
        self.client.bindReceiveCall('table.load.fits', self.receiveCall)
        self.client.bindReceiveCall('table.select.rowList', self.receiveCall)

        self.tables = {}
        self.rowlist = {}
        self.crow = None
        self.lastMessage = None

        tmpdir = os.getenv('HOME') + '/tempo/samptables'
        if not os.path.exists(tmpdir):
            os.makedirs(tmpdir)
        else:
            for f in os.listdir(tmpdir):
                os.remove(tmpdir + '/' +
                          f)  # maybe ask first before deleting ?
        self.tmpdir = tmpdir
Exemple #3
0
 def __init__(
         self,
         name="VAO Python Client",
         description="An interactive SAMP client for Python by the Virtual Astronomical Observatory",
         version="0.0.1"):
     self.metadata = {
         "samp.name": name,
         "samp.description.text": description,
         "client.version": version
     }
     sampy.SAMPIntegratedClient.__init__(self)
     self.do_close_hub = False
     if len(self.hub.getRunningHubs()) == 0:
         self.samp_hub = sampy.SAMPHubServer()
         self.samp_hub.start()
         self.do_close_hub = True
     self.connect()
     self.declareMetadata(self.metadata)
Exemple #4
0
 def __init__(self, addr, *args, **kwargs):
     self.SAMPHubServer = sampy.SAMPHubServer(addr=addr, *args, **kwargs)
     atexit.register(self.SAMPHubServer.stop)
                }
            }
            vot2csvClient.reply(msg_id, replyMsg)


def responseHandler(private_key, sender_id, msg_id, response):
    # Response received, typically an OK response,
    # we should not be receiving none of these
    print("Receiving response", private_key, sender_id, msg_id, response)


# Start binding behaviours
vot2csvClient = sampy.SAMPIntegratedClient(vot2csvMD)
log = sampy.SAMPLog(level=sampy.SAMPLog.OFF)
try:
    hub = sampy.SAMPHubServer(addr='127.0.0.1', port=50000, log=log)
except sampy.SAMPHubError, err:
    print err
    print "Possibly, already working hub."

try:
    vot2csvClient.connect()
except sampy.SAMPHubError, err:
    if err.value == 'Unable to find a running SAMP Hub.':
        try:
            hub.start()
            vot2csvClient.connect()
        except:
            raise

vot2csvClient.bindReceiveNotification("table.load.votable",
Exemple #6
0
def ds9echo(response):
	print response

class Client(sampy.SAMPIntegratedClient):

	def __init__(self,
			name="VAO Python Client",
			description="An interactive SAMP client for Python by the Virtual
                        Astronomical Observatory",
                        version="0.0.1"):
		self.metadata = {"samp.name": name, "samp.description.text": description, "client.version": version}
		sampy.SAMPIntegratedClient.__init__(self)
		self.do_close_hub = False
		if len(self.hub.getRunningHubs()) == 0:
			self.samp_hub = sampy.SAMPHubServer()
			self.samp_hub.start()
			self.do_close_hub = True
		self.connect()
		self.declareMetadata(self.metadata)
	
	def set(self, cmd, url=""):
		message = {"samp.mtype": "ds9.set", "samp.params":{"cmd": cmd, "url":url}}
		self.callAll("vaods9set", message)
		
	def get(self, cmd, url="", tag="vaods9get", function=ds9echo):
		self.bindReceiveResponse(tag, self.handler_wrapper)
		self.handler = function
		message = {"samp.mtype": "ds9.get", "samp.params":{"cmd": cmd, "url":url}}
		self.callAll(tag, message)
Exemple #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sampy
import time
import sys

newHub = sampy.SAMPHubServer(addr='127.0.0.1', port=50000)
newHub.start()

try:
    while True:
        time.sleep(0.01)
except KeyboardInterrupt:
    print "SIGINT received"
    try:
        newHub.stop()
    except:
        pass

    sys.exit(0)