-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathview3d.py
More file actions
114 lines (82 loc) · 2.94 KB
/
Copy pathview3d.py
File metadata and controls
114 lines (82 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python
##################
# view3d.py
#
# Copyright David Baddeley, 2011
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##################
import wx
import sys
import socket
from optparse import OptionParser
# noinspection PyCompatibility
import socketserver
op = OptionParser(usage = 'usage: %s [options] [filename]' % sys.argv[0])
op.add_option('-m', '--mode', dest='mode', help="mode (or personality), as defined in PYME/DSView/modules/__init__.py")
op.add_option('-q', '--queueURI', dest='queueURI', help="the Pyro URI of the task queue - to avoid having to use the nameserver lookup")
#options, args = op.parse_args()
def OpenFile(argv, show=False):
from PYME.DSView.dsviewer import ImageStack, DSViewFrame
options, args = op.parse_args(argv)
if len (args) > 0:
im = ImageStack(filename=args[0], queueURI=options.queueURI)
else:
im = ImageStack(queueURI=options.queueURI)
if options.mode is None:
mode = im.mode
else:
mode = options.mode
vframe = DSViewFrame(im, None, im.filename, mode = mode)
if show:
vframe.Show()
return vframe
class MyApp(wx.App):
def OnInit(self):
vframe = OpenFile(sys.argv[1:])
self.SetTopWindow(vframe)
vframe.Show(1)
return 1
class MyTCPHandler(socketserver.BaseRequestHandler):
"""
The RequestHandler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""
def handle(self):
# self.request is the TCP socket connected to the client
data = self.request.recv(1024).strip()
print(("%s wrote:" % self.client_address[0]))
print(data)
wx.CallAfter(OpenFile, data.split('\t'), True)
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(('localhost',9898))
sock.send('\t'.join(sys.argv[1:]))
except:
#server not running
import threading
app = MyApp(0)
sockServ = socketserver.TCPServer(('localhost',9898), MyTCPHandler)
thrd = threading.Thread(target=sockServ.serve_forever)
thrd.start()
app.MainLoop()
sockServ.shutdown()
thrd.join()
finally:
sock.close()