Last active
August 29, 2015 14:17
-
-
Save xcriptus/4eb129938e3e458362bf to your computer and use it in GitHub Desktop.
Shows how to build a basic SWT windows from Modelio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This code show how to translates SWI Widgets snippets into a simple | |
# script that can be run directly in the Script window of Modelio. | |
# The code has been translated from java to jython and the first | |
# lines have been accomodated to fit within Modelio (indeed the | |
# eclipse part of modelio). | |
# | |
# This example take a particular exemple "Paint a cirle in a canvas". | |
# You should read th | |
# http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet245.java | |
# but the technique can be used for all the SWT widgets from | |
# https://www.eclipse.org/swt/widgets/ | |
# Just look in the corresponding snippet section and translate the code. | |
# (A) first import all necessary elements EXPLICITLY by name | |
# Note that "*" cannot be used in jython because of class loading | |
from org.eclipse.swt.widgets import Display, Shell | |
from org.eclipse.swt.events import PaintListener | |
from org.eclipse.swt import SWT | |
# (B) put the code at top level for instance | |
# B.1 here we get | |
display = Display.getDefault().getActiveShell() | |
shell = Shell(display) | |
class SimplePaintListener(PaintListener): | |
def paintControl(self, event) : | |
rect = shell.getClientArea() | |
event.gc.drawOval(0,0, rect.width-1, rect.height - 1) | |
shell.addPaintListener(SimplePaintListener()) | |
shell.open() | |
# --------- the code below is the original code from the SWT widget catalog | |
# -- a few annotations have been added to explained has been done during the python translation | |
# | |
# import org.eclipse.swt.graphics.*; <- from package import name1, name2, | |
# import org.eclipse.swt.widgets.*; | |
# import org.eclipse.swt.events.*; | |
# public class Snippet245 { <- removed, code at top level | |
# public static void main(String [] args) { <- removed, code at top level | |
# final Display display = new Display(); <- changed to get exisiting display | |
# final Shell shell = new Shell(display); <- add some parameters to close window, etc. | |
# shell.addPaintListener(new PaintListener() { <- first create the jython class, then register | |
# @Override | |
# public void paintControl(PaintEvent event) { <- same | |
# Rectangle rect = shell.getClientArea(); | |
# event.gc.drawOval(0, 0, rect.width - 1, rect.height - 1); | |
# } | |
# }); | |
# Rectangle clientArea = shell.getClientArea(); | |
# shell.setBounds(clientArea.x + 10, clientArea.y + 10, 200, 200); | |
# shell.open (); | |
# while (!shell.isDisposed()) { <- this loop must be removed in the context of modelio | |
# if (!display.readAndDispatch()) display.sleep(); | |
# } | |
# display.dispose(); <- must be removed in the context of modelio | |
# } | |
#} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment