[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patch to skLatex
From: |
C. Ecker |
Subject: |
patch to skLatex |
Date: |
Fri, 3 Sep 2004 16:35:59 +0200 (MEST) |
Hi,
I made a quick hack to skLatex to try out what I wrote yesterday. The
patch below adds an Editor to the plugin, so that one can set the values
\skwidth and \skheight directly by dragging handles. For example
\colorbox{blue}{
\begin{minipage}{\skwidth pt}
skwidth is \skwidth ~pt
\end{minipage}
}
draws a blue box with a width which can be resized similar to a rectangle
from the skencil canvas. This is a bad example, because latex adds some
additional space around the box. So the box will always be a bit too
large. It should be possible to avoid this additional space somehow ...
Christof
--- sklatex/sklatex/LatexMngr.py 2004-08-31 05:44:56.000000000
+0200
+++ hackedsklatex/sklatex/LatexMngr.py 2004-09-03 13:14:07.000000000
+0200
@@ -79,13 +79,15 @@
#---------------------------------------------------------------#
#
#---------------------------------------------------------------#
- def getSkFilePath(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula):
+ def getSkFilePath(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula, width, height):
self.__docClass = DocClass
self.__amsPreamble = AmsPreamble
self.__colorPreamble = ColorPreamble
self.__userDefPreamble = UserDefPreamble
self.__formula = Formula
+ self.__width = width
+ self.__height = height
if not self.__makeTempFile():
@@ -118,13 +120,15 @@
#---------------------------------------------------------------#
#
#---------------------------------------------------------------#
- def getPsFilePath(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula):
+ def getPsFilePath(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula, width, height):
self.__docClass = DocClass
self.__amsPreamble = AmsPreamble
self.__colorPreamble = ColorPreamble
self.__userDefPreamble = UserDefPreamble
self.__formula = Formula
+ self.__width = width
+ self.__height = height
if not self.__makeTempFile():
@@ -152,13 +156,16 @@
#---------------------------------------------------------------#
#
#---------------------------------------------------------------#
- def testLatexFile(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula):
+ def testLatexFile(self, DocClass, AmsPreamble, ColorPreamble,
UserDefPreamble, Formula, width, height):
self.__docClass = DocClass
self.__amsPreamble = AmsPreamble
self.__colorPreamble = ColorPreamble
self.__userDefPreamble = UserDefPreamble
self.__formula = Formula
+ self.__width = width
+ self.__height = height
+
if not self.__makeTempFile():
@@ -299,6 +306,8 @@
try:
latexFile.write(self.__docClass)
+ latexFile.write('\\pagestyle{empty}\n')
+ latexFile.write(r'\newcommand {\skwidth}{%s}' %
self.__width)
+ latexFile.write(r'\newcommand {\skheight}{%s}' %
self.__height)
latexFile.write('\\pagestyle{empty}\n')
latexFile.write(self.__amsPreamble)
latexFile.write(self.__colorPreamble)
--- sklatex/skLaTeX.py 2004-08-31 05:44:10.000000000 +0200
+++ hackedsklatex/skLaTeX.py 2004-09-03 16:42:55.000000000 +0200
@@ -43,19 +43,98 @@
import tempfile
import os
+from Sketch import _, Point, Translation, TrafoPlugin
+from Sketch.Graphics.base import Editor
+from Sketch.Graphics import handle
+
+
+class MyEditor(Editor):
+
+ commands = []
+ selection = 0 # we note here which handle was clicked
+
+ def __init__(self, object):
+ Editor.__init__(self, object)
+ self.p1, self.p2 = [Point(0,0), Point(self.width, self.height)]
+
+ def Destroy(self):
+ # nothing to do here
+ pass
+
+ def ButtonDown(self, p, button, state):
+ Editor.DragStart(self, p)
+
+ def ButtonUp(self, p, button, state):
+ p1, p2 = self.p1, self.p2
+ w, h = p2-p1
+ Params = {}
+ Params["width"] = w
+ Params["height"] = h
+ Params["origin"] = p1
+ return self.document.AddUndo(self.SetParameters(Params))
+
+ def MouseMove(self, p, state):
+ Editor.MouseMove(self, p, state)
+ x, y = self.origin
+ w, h = self.width, self.height
+ p1, p2 = [Point(x,y), Point(x+w, y+h)]
+ itrafo = self.trafo.inverse()
+ delta = itrafo(p)-itrafo(self.drag_start)
+ i = self.selection
+ if i == 0:
+ # lower left
+ p1 = p1+delta
+ elif i == 1:
+ # lower right
+ p1 = Point(p1[0], p1[1]+delta[1])
+ p2 = Point(p2[0]+delta[0], p2[1])
+ elif i == 2:
+ # upper right
+ p2 = p2+delta
+ elif i == 3:
+ # upper left
+ p1 = Point(p1[0]+delta[0], p1[1])
+ p2 = Point(p2[0], p2[1]+delta[1])
+ self.p1, self.p2 = p1, p2
+
+ def GetHandles(self):
+ handles = []
+ x, y = self.origin
+ w, h, = self.width, self.height
+ for p in (Point(x,y), Point(x+w, y), Point(x+w, y+h),
Point(x,y+h)):
+ handles.append(handle.MakeNodeHandle(self.trafo(p)))
+ return handles
+
+ def SelectPoint(self, p, rect, device, mode):
+ return 0
+
+ def SelectHandle(self, handle, mode):
+ self.selection = handle.index
+
+ def DrawDragged(self, device, partially):
+ device.PushTrafo()
+ device.Concat(self.trafo)
+ device.DrawRubberRect(self.p1, self.p2)
+ device.PopTrafo()
+
class skLaTeX(Sketch.TrafoPlugin):
#---------------------------------------------------------------#
#
#---------------------------------------------------------------#
class_name = 'skLaTeX'
-
+ has_edit_mode = 1
is_Group = 1
Ungroup = Sketch.TrafoPlugin.GetObjects
success = 1
+
+ width = 50
+ height = 50
+ origin = Point(0,0)
+
#---------------------------------------------------------------#
#---------------------------------------------------------------#
@@ -67,7 +146,11 @@
colorPreamble = '',
userDefPreamble = '',
formula = '',
- trafo = None, duplicate = None, loading = 0):
+ trafo = None,
+ width = 100,
+ height = 100,
+ origin = Point(0,0),
+ duplicate = None, loading = 0):
Sketch.TrafoPlugin.__init__(self, trafo = trafo, duplicate =
duplicate)
@@ -83,6 +166,10 @@
self.formula = duplicate.formula
+ self.width = duplicate.width
+ self.height = duplicate.height
+ self.origin = duplicate.origin
+
else:
self.docClass = docClass
@@ -94,6 +181,10 @@
self.formula = formula
+ self.width = width
+ self.height = height
+ self.origin = Point(origin)
+
if not loading:
self.createFiles()
@@ -115,6 +206,31 @@
#---------------------------------------------------------------#
#
+
+ #---------------------------------------------------------------#
+
+ def AsBezier(self):
+ paths = []
+ for obj in self.objects:
+ paths.append(obj.AsBezier())
+ return tuple(paths)
+
+ def Paths(self):
+ return self.AsBezier()
+
+ def GetObjectHandle(self, multiple):
+ return []
+
+ def Editor(self):
+ return MyEditor(self)
+
+ #---------------------------------------------------------------#
+
+ #---------------------------------------------------------------#
+ #
#---------------------------------------------------------------#
def SetParameters(self, params):
@@ -130,14 +246,20 @@
fileMngr = Lib.sklatex.LatexMngr.Mngr()
- filePath = fileMngr.getSkFilePath(self.docClass,
self.amsPreamble, self.colorPreamble, self.userDefPreamble, self.formula)
+ filePath = fileMngr.getSkFilePath(self.docClass,
self.amsPreamble,
+ self.colorPreamble,
self.userDefPreamble,
+ self.formula, self.width,
self.height)
if os.path.isfile(filePath):
try:
curveFormula = Sketch.load.load_drawing(filePath)
skObject = curveFormula.as_group()
-
+ x1, y1, x2, y2 = skObject.coord_rect
+ trafo = Translation(self.origin-Point(x1, y1))
+ skObject.Transform(trafo)
+ self.width = x2-x1
+ self.height = y2-y1
skObject.Transform(self.trafo)
self.set_objects(skObject.Ungroup())
@@ -166,7 +288,10 @@
self.colorPreamble,
self.userDefPreamble,
self.formula,
- self.trafo.coeff())
+ self.trafo.coeff(),
+ self.width,
+ self.height,
+ (self.origin[0], self.origin[1]))
#---------------------------------------------------------------#
#---------------------------------------------------------------#
@@ -1322,10 +1447,20 @@
Formula = self.editor.getText()
+ selectedObjs = self.document.SelectedObjects()
+
+ width = 100 # initial values
+ height = 100
+ if len(selectedObjs) == 1:
+ selected = selectedObjs[0]
+ if hasattr(selected, 'class_name') and selected.class_name
=='skLaTeX':
+ width = selected.width
+ height = selected.height
+
#
tmpFileMngr = Lib.sklatex.LatexMngr.Mngr()
- tmpFilePath = tmpFileMngr.testLatexFile(DocClass, AmsPreamble,
ColorPreamble, UserDefPreamble, Formula)
+ tmpFilePath = tmpFileMngr.testLatexFile(DocClass, AmsPreamble,
ColorPreamble, UserDefPreamble, Formula, width, height)
if os.path.exists(tmpFilePath):
@@ -1517,6 +1652,8 @@
UserDefPreamble = self.options.optstabs.getUserDefPreamble()
Formula = self.editor.getText()
+ width = self.width
+ height = self.height
#
tmpFileMngr = Lib.sklatex.LatexMngr.Mngr()
@@ -1552,7 +1689,7 @@
fileMngr = Lib.sklatex.LatexMngr.Mngr()
- filePath = fileMngr.getPsFilePath(DocClass, AmsPreamble,
ColorPreamble, UserDefPreamble, Formula)
+ filePath = fileMngr.getPsFilePath(DocClass, AmsPreamble,
ColorPreamble, UserDefPreamble, Formula, width, height)
if os.path.isfile(filePath):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- patch to skLatex,
C. Ecker <=