Python GUI with Java

I am working on a program that accepts user input and generates output as a map projection graph. The lightest map projection library I have found is matplotlib-basemap, written in python, which I don't really like (I work in Java). I wrote a user interface in Java. I am currently executing python code and sending arrays of data commands using the Runtime and exec () commands, calling the ".py" file. This displays the command and shows the plot as a separate window.

My question is: Is it possible to implement this base map (Interactive with Zoom) on Jpanel? Or on python GUI, which can then be embedded in JPanel? I know that I can save the image generated by matplotlib as a file that can be captured on the panel, but then it will not be interactive, then the Zoom functions are not available. Or is a Java-based tool used instead of a basemap? (I did not find anything good)

---- Edit May 22, 2013 ------

Jython is not a solution because matplotlib is incompatible with it. Doing all this in python, I agree, would be optimal, but I have to work with that.

JACOB Jar: I was unable to find sample code showing how to embed a single application (base map) in a JPanel or JFrame.

I am currently planning to embed a basemap in the wxpython GUI and then use sockets to communicate between the two languages.

TCP / IP socket with Java server and client-side Python.

+8
java python matplotlib-basemap
source share
2 answers

This is if you are open to new ideas and learn new things.
This is not a solution to your specific problem, that you want to join the two languages, it is a replacement for this idea to include everything in 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() 

All you need is:


Python layout to work as a submodule in Javav

 import sys for line in sys.stdin.readline(): if line == 'plot': pass # create image here 

For example.

+2
source share

You can embed your GUI in Jython , a Java implementation in Python. Unfortunately, it does not support matplotlib since it relies on native code. You can try using execnet to call Python from Jython.

0
source share

All Articles