这是如果你对新想法和学习新事物持开放态度。
您想要加入两种语言并不是针对您的特定问题的解决方案,而是替代将所有内容合并到 Python 中的想法。
#!/usr/bin/python
import pyglet
from time import time, sleep
class Window(pyglet.window.Window):
def __init__(self):
super(Window, self).__init__(vsync = False)
self.alive = 1
self.click = None
self.drag = False
with open('map.png', 'rb') as fh:
self.geodata_image = pyglet.image.load('map.png', file=fh)
self.geo_info = self.geodata_image.width, self.geodata_image.height
def on_draw(self):
self.render()
def on_mouse_press(self, x, y, button, modifiers):
self.click = x,y
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
if self.click:
self.drag = True
print 'Drag offset:',(dx,dy)
def on_mouse_release(self, x, y, button, modifiers):
if not self.drag and self.click:
print 'You clicked here', self.click, 'Relese point:',(x,y)
## Do work on corindate
else:
print 'You draged from', self.click, 'to:',(x,y)
## Move or link two points, or w/e you want to do.
self.click = None
self.drag = False
def render(self):
self.clear()
## An alternative to only getting a region if you only want to show a specific part of
## the image:
# subimage = self.geodata_image.get_region(0, 0, self.geo_info[0], self.geo_info[1])
self.geodata_image.blit(0, 0, 0) # x, y, z from the bottom left corner
self.flip()
def on_close(self):
self.alive = 0
def run(self):
while self.alive:
self.render()
## self.dispatch_events() must be in the main loop
## or any loop that you want to "render" something
## Because it is what lets Pyglet continue with the next frame.
event = self.dispatch_events()
sleep(1.0/25) # 25FPS limit
win = Window()
win.run()
所有你需要的是:
作为 Javav 的子模块运行的 Python 模型
import sys
for line in sys.stdin.readline():
if line == 'plot':
pass # create image here
例如。