Skip to content

Commit

Permalink
Starting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heeres committed Jun 28, 2013
1 parent 7f759c9 commit d9890ee
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
9 changes: 8 additions & 1 deletion clients/client_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ def _close_gui_cb(*args):
sys.exit()

if __name__ == "__main__":
srv = share_gtk.start_client('localhost', port=args.port, nretry=60)
srv = share_gtk.start_client(args.host, port=args.port, nretry=60)
logging.debug('Connected to %s', srv.get_instance_name())

# Be sure to talk to the qtlab instance that we just connected to
if srv:
import lib.config as cfg
cfg.get_config()['instance_name'] = srv.get_instance_name()


# Close when requested
flow = objsh.helper.find_object('%s:flow' % srv.get_instance_name())
flow.connect('close-gui', _close_gui_cb)

# Or if disconected
objsh.helper.register_event_callback('disconnected', _close_gui_cb)

if args.module:
Expand Down
16 changes: 15 additions & 1 deletion clients/client_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,33 @@
help='Port to connect to')
parser.add_option('--name', default='',
help='QTlab instance name to connect to, should be auto-detected')
parser.add_option('--host', default='localhost',
help='Host to connect to')
parser.add_option('--module', default=None,
help='Client module to import')
parser.add_option('--config', default=None,
help='Set config file to use')
help='Set config file to use, defaults to <argv0>_<module>.cfg')
parser.add_option('--debug', default=False, action='store_true',
help='Enable debugging mode, ie more logging')

def process_args():
args, pargs = parser.parse_args()

if args.config is None:
args.config = os.path.split(sys.argv[0])[-1]
if args.config.endswith('.py'):
args.config = args.config[:-3]
if args.module:
args.config += '_' + args.module + '.cfg'

if args.config:
import lib.config as cfg
global config
config = cfg.create_config(args.config)
if args.name:
config['instance_name'] = args.name
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)

return args, pargs

Expand Down
3 changes: 2 additions & 1 deletion clients/gui_client/gui_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
adddir = os.path.join(os.getcwd(), 'source')
sys.path.insert(0, adddir)

# We should not overwrite the config file set up by client_shared.py
from lib import config
config = config.create_config('qtlabgui.cfg')
config = config.get_config()

from lib.network import object_sharer as objsh

Expand Down
2 changes: 1 addition & 1 deletion qtlab
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ if [[ "$_ipython" ]]; then
if [[ "$version" < "0.11" ]]; then
ipython -gthread $basedir/source/qtlab_shell.py -- "$@"
else
ipython --gui=gtk -i $basedir/source/qtlab_shell.py
ipython --gui=gtk -i $basedir/source/qtlab_shell.py -- "$@"
fi
fi
27 changes: 20 additions & 7 deletions source/lib/network/object_sharer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ def add_client(self, conn, handler):
self._do_event_callbacks('connect', client)
return client

def get_client_for_socket(self, conn):
for c in self.clients:
if c.get_proxy_socket() == conn:
return c
return None

def remove_client(self, client):
if client in self._clients:
del self._clients[self._clients.index(client)]

self._do_event_callbacks('disconnected', client)

def register_event_callback(self, event, cb):
'''
Register callback cb for event. Event is one of:
Expand All @@ -106,12 +118,6 @@ def _do_event_callbacks(self, event, *args):
for func in self._event_callbacks[event]:
func(*args)

def remove_client(self, client):
if client in self._clients:
del self._clients[self._clients.index(client)]

self._do_event_callbacks('disconnected', client)

def _client_disconnected(self, conn):
for client in self._clients:
if client.get_connection() == conn:
Expand Down Expand Up @@ -743,6 +749,14 @@ def connect(self, signame, func):
def disconnect(self, hid):
return helper.disconnect(hid)

def get_proxy_client(self):
'''Return the client where this proxy is pointing to'''
return helper.get_client_for_socket(self.__conn)

def get_proxy_socket(self):
'''Return the connection this proxy is using'''
return self.__conn

def cache_result(f):
f._share_options = {'cache_result': True}
return f
Expand Down Expand Up @@ -802,7 +816,6 @@ def __init__(self, name, namespace={}):
self._namespace = namespace

def cmd(self, cmd):
print 'Evaluating %s' % (cmd, )
retval = eval(cmd, self._namespace, self._namespace)
return retval

Expand Down
4 changes: 2 additions & 2 deletions source/qtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class constants():
FLAG_SOFTGET = 0x08
FLAG_PERSIST = 0x10

flow = helper.find_object('%s:flow' % config['instance_name'])
flow = helper.find_remote_object('%s:flow' % config['instance_name'])
if flow is None:
flow = helper.find_object('flow')
flow = helper.find_remote_object('flow')
if flow is None:
raise ValueError('Unable to locate qt.flow object (%s), client failed to start' % config['instance_name'])
else:
Expand Down

0 comments on commit d9890ee

Please sign in to comment.