-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display turtle graphics in a view window.
Remove old ruler version of the display. Rename AddComposite to LiveCodingAnalyst.
- Loading branch information
Showing
10 changed files
with
236 additions
and
451 deletions.
There are no files selected for viewing
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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.4"?> | ||
<plugin> | ||
<extension | ||
point="org.eclipse.ui.workbench.texteditor.rulerColumns"> | ||
<column | ||
class="live_py.LiveCodingResultsRuler" | ||
enabled="true" | ||
global="true" | ||
id="live-py.live-results" | ||
includeInMenu="true" | ||
name="Live Coding Results"> | ||
<placement | ||
gravity="1.0"> | ||
</placement> | ||
<targetClass | ||
class="org.python.pydev.editor.PyEdit"> | ||
</targetClass> | ||
</column> | ||
</extension> | ||
<extension | ||
point="org.python.pydev.pydev_pyedit_listener"> | ||
<pyedit_listener_participant | ||
class="live_py.AddComposite"> | ||
class="live_py.LiveCodingAnalyst"> | ||
</pyedit_listener_participant> | ||
</extension> | ||
<extension | ||
point="org.eclipse.ui.views"> | ||
<view | ||
class="live_py.LiveCanvasView" | ||
icon="icons/turtle.png" | ||
id="com.github.donkirkby.live-canvas" | ||
name="Live Coding Canvas" | ||
restorable="true"> | ||
</view> | ||
</extension> | ||
|
||
</plugin> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package live_py; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.PaintEvent; | ||
import org.eclipse.swt.events.PaintListener; | ||
import org.eclipse.swt.graphics.Font; | ||
import org.eclipse.swt.graphics.GC; | ||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.swt.widgets.Canvas; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.IPartListener; | ||
import org.eclipse.ui.IViewSite; | ||
import org.eclipse.ui.IWorkbenchPart; | ||
import org.eclipse.ui.part.ViewPart; | ||
import org.python.pydev.editor.PyEdit; | ||
|
||
public class LiveCanvasView extends ViewPart { | ||
private LiveCodingAnalyst analyst; | ||
private Canvas canvas; | ||
|
||
public LiveCanvasView() { | ||
super(); | ||
} | ||
|
||
public void setFocus() { | ||
} | ||
|
||
public void createPartControl(Composite parent) { | ||
canvas = new Canvas(parent, SWT.NONE); | ||
|
||
canvas.addPaintListener(new PaintListener() { | ||
|
||
@Override | ||
public void paintControl(PaintEvent e) { | ||
drawResult(e.gc); | ||
} | ||
}); | ||
|
||
IViewSite site = getViewSite(); | ||
site.getPage().addPartListener(new IPartListener() { | ||
|
||
@Override | ||
public void partOpened(IWorkbenchPart part) { | ||
} | ||
|
||
@Override | ||
public void partDeactivated(IWorkbenchPart part) { | ||
} | ||
|
||
@Override | ||
public void partClosed(IWorkbenchPart part) { | ||
} | ||
|
||
@Override | ||
public void partBroughtToTop(IWorkbenchPart part) { | ||
} | ||
|
||
@Override | ||
public void partActivated(IWorkbenchPart part) { | ||
if (part instanceof PyEdit) | ||
{ | ||
PyEdit editor = (PyEdit)part; | ||
LiveCodingAnalyst newAnalyst = | ||
LiveCodingAnalyst.getAnalyst(editor); | ||
if (newAnalyst != analyst && analyst != null) { | ||
analyst.setCanvasView(null); | ||
} | ||
analyst = newAnalyst; | ||
analyst.setCanvasView(LiveCanvasView.this); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public void redraw() { | ||
if (canvas != null) { | ||
canvas.redraw(); | ||
} | ||
} | ||
|
||
private void drawResult(GC gc) { | ||
// Clear the drawing | ||
gc.fillRectangle(gc.getDevice().getBounds()); | ||
|
||
if (analyst == null) { | ||
return; | ||
} | ||
ArrayList<CanvasCommand> canvasCommands = analyst.getCanvasCommands(); | ||
// Execute the drawing commands | ||
for (CanvasCommand command : canvasCommands) { | ||
String method = command.getName(); | ||
if (method.equals("create_line")) { | ||
gc.drawLine( | ||
command.getCoordinate(0), | ||
command.getCoordinate(1), | ||
command.getCoordinate(2), | ||
command.getCoordinate(3)); | ||
} | ||
else if (method.equals("create_rectangle")) { | ||
gc.drawRectangle( | ||
command.getCoordinate(0), | ||
command.getCoordinate(1), | ||
command.getCoordinate(2) - command.getCoordinate(0), | ||
command.getCoordinate(3) - command.getCoordinate(1)); | ||
} | ||
else if (method.equals("create_text")) { | ||
Font oldFont = gc.getFont(); | ||
gc.setFont(command.getFontOption(gc.getDevice(), "font")); | ||
String text = command.getOption("text"); | ||
Point size = gc.textExtent(text); | ||
int x = command.getCoordinate(0); | ||
int y = command.getCoordinate(1); | ||
String anchor = command.getOption("anchor"); | ||
anchor = anchor == null ? "center" : anchor; | ||
if (anchor.startsWith("s")) { | ||
y -= size.y; | ||
} | ||
else if (anchor.startsWith("n")) { | ||
// defaults to top | ||
} | ||
else { | ||
y -= size.y/2; | ||
} | ||
if (anchor.endsWith("e")) { | ||
x -= size.x; | ||
} | ||
else if (anchor.endsWith("w")) { | ||
// defaults to left side | ||
} | ||
else { | ||
x -= size.x/2; | ||
} | ||
gc.drawText( | ||
text, | ||
x, | ||
y, | ||
SWT.DRAW_TRANSPARENT); | ||
gc.setFont(oldFont); | ||
} | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.