tools.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. from lazpaint import command, colors
  2. HAND = 'Hand'
  3. HOT_SPOT = 'HotSpot'
  4. MOVE_LAYER = 'MoveLayer'
  5. ROTATE_LAYER = 'RotateLayer'
  6. ZOOM_LAYER = 'ZoomLayer'
  7. PEN = 'Pen'
  8. BRUSH = 'Brush'
  9. CLONE = 'Clone'
  10. COLOR_PICKER = 'ColorPicker'
  11. ERASER = 'Eraser'
  12. EDIT_SHAPE = 'EditShape'
  13. RECTANGLE = 'Rect'
  14. ELLIPSE = 'Ellipse'
  15. POLYGON = 'Polygon'
  16. SPLINE = 'Spline'
  17. FLOOD_FILL = 'FloodFill'
  18. GRADIENT = 'Gradient'
  19. PHONG_SHAPE = 'Phong'
  20. SELECT_PEN = 'SelectPen'
  21. SELECT_RECT = 'SelectRect'
  22. SELECT_ELLIPSE = 'SelectEllipse'
  23. SELECT_POLY = 'SelectPoly'
  24. SELECT_SPLINE = 'SelectSpline'
  25. MOVE_SELECTION = 'MoveSelection'
  26. ROTATE_SELECTION = 'RotateSelection'
  27. MAGIC_WAND = 'MagicWand'
  28. DEFORMATION_GRID = 'Deformation'
  29. TEXTURE_MAPPING = 'TextureMapping'
  30. LAYER_MAPPING = 'LayerMapping'
  31. TEXT = 'Text'
  32. #click state
  33. STATE_LEFT = 'Left'
  34. STATE_RIGHT = 'Right'
  35. STATE_SHIFT = 'Shift'
  36. STATE_ALT = 'Alt'
  37. STATE_CTRL = 'Ctrl'
  38. ERASER_MODE_ALPHA = 'EraseAlpha'
  39. ERASER_MODE_SHARPEN = 'Sharpen'
  40. ERASER_MODE_SOFTEN = 'Soften'
  41. ERASER_MODE_LIGHTEN = 'Lighten'
  42. ERASER_MODE_DARKEN = 'Darken'
  43. PEN_STYLE_SOLD = 'Solid'
  44. PEN_STYLE_DASH = 'Dash'
  45. PEN_STYLE_DOT = 'Dot'
  46. PEN_STYLE_DASH_DOT = 'DashDot'
  47. PEN_STYLE_DASH_DOT_DOT = 'DashDotDot'
  48. JOIN_STYLE_BEVEL = 'Bevel'
  49. JOIN_STYLE_MITER = 'Miter'
  50. JOIN_STYLE_ROUND = 'Round'
  51. LINE_CAP_ROUND = 'Round'
  52. LINE_CAP_SQUARE = 'Square'
  53. LINE_CAP_FLAT = 'Flat'
  54. FONT_STYLE_BOLD = 'Bold'
  55. FONT_STYLE_ITALIC = 'Italic'
  56. FONT_STYLE_UNDERLINE = 'Underline'
  57. FONT_STYLE_STRIKE_OUT = 'StrikeOut'
  58. ALIGN_LEFT = 'Left'
  59. ALIGN_CENTER = 'Center'
  60. ALIGN_RIGHT = 'Right'
  61. BIDI_AUTO = 'BidiAuto'
  62. BIDI_LEFT_TO_RIGHT = 'LeftToRight'
  63. BIDI_RIGHT_TO_LEFT = 'RightToLeft'
  64. SHAPE_OPTION_DRAW_SHAPE = 'DrawShape'
  65. SHAPE_OPTION_FILL_SHAPE = 'FillShape'
  66. SHAPE_OPTION_CLOSE_SHAPE = 'CloseShape'
  67. ARROW_NONE = 'None'
  68. ARROW_TAIL = 'Tail'
  69. ARROW_TIP = 'Tip'
  70. ARROW_NORMAL = 'Normal'
  71. ARROW_CUT = 'Cut'
  72. ARROW_FLIPPED = 'Flipped'
  73. ARROW_FLIPPED_CUT = 'FlippedCut'
  74. ARROW_TRIANGLE = 'Triangle'
  75. ARROW_TRIANGLE_BACK1 = 'TriangleBack1'
  76. ARROW_TRIANGLE_BACK2 = 'TriangleBack2'
  77. ARROW_HOLLOW_TRIANGLE = 'HollowTriangle'
  78. ARROW_HOLLOW_TRIANGLE_BACK1 = 'HollowTriangleBack1'
  79. ARROW_HOLLOW_TRIANGLE_BACK2 = 'HollowTriangleBack2'
  80. SPLINE_STYLE_INSIDE = 'Inside'
  81. SPLINE_STYLE_INSIDE_WITH_ENDS = 'InsideWithEnds'
  82. SPLINE_STYLE_CROSSING = 'Crossing'
  83. SPLINE_STYLE_CROSSING_WITH_ENDS = 'CrossingWithEnds'
  84. SPLINE_STYLE_OUTSIDE = 'Outside'
  85. SPLINE_STYLE_ROUND_OUTSIDE = 'RoundOutside'
  86. SPLINE_STYLE_VERTEX_TO_SIDE = 'VertexToSide'
  87. SPLINE_STYLE_EASY_BEZIER = 'EasyBezier'
  88. GRADIENT_TYPE_LINEAR = 'Linear'
  89. GRADIENT_TYPE_REFLECTED = 'Reflected'
  90. GRADIENT_TYPE_DIAMOND = 'Diamond'
  91. GRADIENT_TYPE_RADIAL = 'Radial'
  92. GRADIENT_TYPE_ANGULAR = 'Angular'
  93. GRADIENT_INTERPOLATION_STD_RGB = 'StdRGB'
  94. GRADIENT_INTERPOLATION_LINEAR_RGB = 'LinearRGB'
  95. GRADIENT_INTERPOLATION_LINEAR_HSL_POSITIVE = 'LinearHSLPositive'
  96. GRADIENT_INTERPOLATION_LINEAR_HSL_NEGATIVE = 'LinearHSLNegative'
  97. GRADIENT_INTERPOLATION_CORR_HSL_POSITIVE = 'GSBPositive'
  98. GRADIENT_INTERPOLATION_CORR_HSL_NEGATIVE = 'GSBNegative'
  99. GRADIENT_REPETITION_PAD = 'Pad'
  100. GRADIENT_REPETITION_REPEAT = 'Repeat'
  101. GRADIENT_REPETITION_REFLECT = 'Reflect'
  102. GRADIENT_REPETITION_SINE = 'Sine'
  103. TEXTURE_REPETITION_NONE = 'None';
  104. TEXTURE_REPETITION_X = 'RepeatX';
  105. TEXTURE_REPETITION_Y = 'RepeatY';
  106. TEXTURE_REPETITION_BOTH = 'RepeatBoth';
  107. SHAPE_KIND_RECTANGLE = 'Rectangle'
  108. SHAPE_KIND_ROUND_RECTANGLE = 'RoundRectangle'
  109. SHAPE_KIND_HALF_SPHERE = 'HalfSphere'
  110. SHAPE_KIND_CONE_TOP = 'ConeTop'
  111. SHAPE_KIND_CONE_SIDE = 'ConeSide'
  112. SHAPE_KIND_HORIZ_CYLINDER = 'HorizCylinder'
  113. SHAPE_KIND_VERT_CYLINDER = 'VertCylinder'
  114. DEFORMATION_MODE_DEFORM = 'Deform'
  115. DEFORMATION_MODE_MOVE_POINT_WITHOUT_DEFORMATION = 'MovePointWithoutDeformation'
  116. FLOOD_FILL_PROGRESSIVE = 'Progressive'
  117. FLOOD_FILL_FILL_ALL = 'FillAll' #not implemented
  118. PERSPECTIVE_REPEAT = 'Repeat'
  119. PERSPECTIVE_TWO_PLANES = 'TwoPlanes'
  120. KEY_UNKNOWN = 'Unknown'
  121. KEY_BACKSPACE = 'Backspace'
  122. KEY_TAB = 'Tab'
  123. KEY_RETURN = 'Return'
  124. KEY_ESCAPE = 'Escape'
  125. KEY_PAGE_UP = 'PageUp'
  126. KEY_PAGE_DOWN = 'PageDown'
  127. KEY_HOME = 'Home'
  128. KEY_END = 'End'
  129. KEY_LEFT = 'Left'
  130. KEY_UP = 'Up'
  131. KEY_RIGHT = 'Right'
  132. KEY_DOWN = 'Down'
  133. KEY_INSERT = 'Insert'
  134. KEY_DELETE = 'Delete'
  135. KEY_NUM0 = 'Num0'
  136. KEY_NUM1 = 'Num1'
  137. KEY_NUM2 = 'Num2'
  138. KEY_NUM3 = 'Num3'
  139. KEY_NUM4 = 'Num4'
  140. KEY_NUM5 = 'Num5'
  141. KEY_NUM6 = 'Num6'
  142. KEY_NUM7 = 'Num7'
  143. KEY_NUM8 = 'Num8'
  144. KEY_NUM9 = 'Num9'
  145. KEY_F1 = 'F1'
  146. KEY_F2 = 'F2'
  147. KEY_F3 = 'F3'
  148. KEY_F4 = 'F4'
  149. KEY_F5 = 'F5'
  150. KEY_F6 = 'F6'
  151. KEY_F7 = 'F7'
  152. KEY_F8 = 'F8'
  153. KEY_F9 = 'F9'
  154. KEY_F10 = 'F10'
  155. KEY_F11 = 'F11'
  156. KEY_F12 = 'F12'
  157. KEY_A = 'A'
  158. KEY_B = 'B'
  159. KEY_C = 'C'
  160. KEY_D = 'D'
  161. KEY_E = 'E'
  162. KEY_F = 'F'
  163. KEY_G = 'G'
  164. KEY_H = 'H'
  165. KEY_I = 'I'
  166. KEY_J = 'J'
  167. KEY_K = 'K'
  168. KEY_L = 'L'
  169. KEY_M = 'M'
  170. KEY_M = 'N'
  171. KEY_O = 'O'
  172. KEY_P = 'P'
  173. KEY_Q = 'Q'
  174. KEY_R = 'R'
  175. KEY_S = 'S'
  176. KEY_T = 'T'
  177. KEY_U = 'U'
  178. KEY_V = 'V'
  179. KEY_W = 'W'
  180. KEY_X = 'X'
  181. KEY_Y = 'Y'
  182. KEY_W = 'Z'
  183. KEY_0 = '0'
  184. KEY_1 = '1'
  185. KEY_2 = '2'
  186. KEY_3 = '3'
  187. KEY_4 = '4'
  188. KEY_5 = '5'
  189. KEY_6 = '6'
  190. KEY_7 = '7'
  191. KEY_8 = '8'
  192. KEY_9 = '9'
  193. KEY_SHIFT = 'Shift'
  194. KEY_CTRL = 'Ctrl'
  195. KEY_ALT = 'Alt'
  196. def choose(name):
  197. command.send("ChooseTool", Name=name)
  198. def mouse(coords, state=[STATE_LEFT], default_pressure=1.0):
  199. if not isinstance(coords, list):
  200. xy = [(float(coords[0]), float(coords[1]))]
  201. if len(coords)>2:
  202. pressure = [float(coords[2])]
  203. else:
  204. pressure = [default_pressure]
  205. else:
  206. xy = [(float(c[0]), float(c[1])) for c in coords]
  207. pressure = [float(c[2]) if len(c)>2 else default_pressure for c in coords]
  208. command.send("ToolMouse", Coords=xy, State=state, Pressure=pressure)
  209. def keys(keys, state=[]):
  210. if isinstance(keys, str):
  211. keys = [keys]
  212. command.send("ToolKeys", Keys=keys, State=state)
  213. def write(text):
  214. command.send("ToolWrite", Text=text)
  215. def set_fore_color(color):
  216. command.send("ToolSetForeColor", Color=color)
  217. def set_back_color(color):
  218. command.send("ToolSetBackColor", Color=color)
  219. def set_outline_color(color):
  220. command.send("ToolSetOutlineColor", Color=color)
  221. def get_fore_color():
  222. return colors.str_to_RGBA(command.send("ToolGetForeColor?"))
  223. def get_back_color():
  224. return colors.str_to_RGBA(command.send("ToolGetBackColor?"))
  225. def get_outline_color():
  226. return colors.str_to_RGBA(command.send("ToolGetOutlineColor?"))
  227. def set_eraser_mode(mode):
  228. command.send('ToolSetEraserMode', Mode=mode)
  229. def get_eraser_mode():
  230. return command.send('ToolGetEraserMode?')
  231. def set_eraser_alpha(alpha: int): #0..255
  232. command.send('ToolSetEraserAlpha', Alpha=alpha)
  233. def get_eraser_alpha() -> int:
  234. return command.send('ToolGetEraserAlpha?')
  235. def set_pen_width(width: float):
  236. command.send('ToolSetPenWidth', Width=width)
  237. def get_pen_width():
  238. return command.send('ToolGetPenWidth?')
  239. def set_pen_style(style):
  240. command.send('ToolSetPenStyle', Style=style)
  241. def get_pen_style():
  242. return command.send('ToolGetPenStyle?')
  243. def set_join_style(style):
  244. command.send('ToolSetJoinStyle', Style=style)
  245. def get_join_style():
  246. return command.send('ToolGetJoinStyle?')
  247. def set_line_cap(cap):
  248. command.send('ToolSetLineCap', Cap=cap)
  249. def get_line_cap():
  250. return command.send('ToolGetLineCap?')
  251. def set_shape_options(options: list):
  252. command.send('ToolSetShapeOptions', Options=options)
  253. def get_shape_options() -> list:
  254. return command.send('ToolGetShapeOptions?')
  255. def set_aliasing(enabled: bool):
  256. command.send('ToolSetAliasing', Enabled=enabled)
  257. def get_aliasing() -> bool:
  258. return command.send('ToolGetAliasing?')
  259. def set_shape_ratio(ratio: float):
  260. command.send('ToolSetShapeRatio', Ratio=ratio)
  261. def get_shape_ratio() -> float:
  262. return command.send('ToolGetShapeRatio?')
  263. def set_brush_index(index: int):
  264. command.send('ToolSetBrushIndex', Index=index)
  265. def get_brush_index() -> int:
  266. return command.send('ToolGetBrushIndex?')
  267. def get_brush_count() -> int:
  268. return command.send('ToolGetBrushCount?')
  269. def set_brush_spacing(spacing: int):
  270. command.send('ToolSetBrushSpacing', Spacing=spacing)
  271. def get_brush_spacing() -> int:
  272. return command.send('ToolGetBrushSpacing?')
  273. def set_font_name(name: str):
  274. command.send('ToolSetFontName', Name=name)
  275. def get_font_name() -> str:
  276. return command.send('ToolGetFontName?')
  277. def set_font_size(size: float):
  278. command.send('ToolSetFontSize', Size=size)
  279. def get_font_size() -> float:
  280. return command.send('ToolGetFontSize?')
  281. def set_font_style(style: list):
  282. command.send('ToolSetFontStyle', Style=style)
  283. def get_font_style() -> list:
  284. return command.send('ToolGetFontStyle?')
  285. def set_text_align(align):
  286. command.send('ToolSetTextAlign', Align=align)
  287. def get_text_align():
  288. return command.send('ToolGetTextAlign?')
  289. def set_text_bidi_mode(bidi_mode):
  290. command.send('ToolSetTextBidiMode', BidiMode=bidi_mode)
  291. def get_text_bidi_mode():
  292. return command.send('ToolGetTextBidiMode?')
  293. def set_text_outline(width: float):
  294. command.send('ToolSetTextOutline', Width=width)
  295. def get_text_outline() -> float:
  296. return command.send('ToolGetTextOutline?')
  297. def set_text_phong(enabled: bool):
  298. command.send('ToolSetTextPhong', Enabled=enabled)
  299. def get_text_phong() -> bool:
  300. return command.send('ToolGetTextPhong?')
  301. def set_light_position(x: float, y: float):
  302. command.send('ToolSetLightPosition', Position=(x, y))
  303. def get_light_position() -> tuple:
  304. return command.send('ToolGetLightPosition?')
  305. def set_arrow_start(arrow):
  306. command.send('ToolSetArrowStart', Arrow=arrow)
  307. def get_arrow_start():
  308. return command.send('ToolGetArrowStart?')
  309. def set_arrow_end(arrow):
  310. command.send('ToolSetArrowEnd', Arrow=arrow)
  311. def get_arrow_end():
  312. return command.send('ToolGetArrowEnd?')
  313. def set_arrow_size(x, y):
  314. command.send('ToolSetArrowSize', Size=(x, y))
  315. def get_arrow_size() -> tuple:
  316. return command.send('ToolGetArrowSize?')
  317. def set_spline_style(style):
  318. command.send('ToolSetSplineStyle', Style=style)
  319. def get_spline_style():
  320. return command.send('ToolGetSplineStyle?')
  321. def set_fore_gradient_type(gradient_type):
  322. command.send('ToolSetForeGradientType', GradientType=gradient_type)
  323. def get_fore_gradient_type():
  324. return command.send('ToolGetForeGradientType?')
  325. def set_fore_gradient_colors(colors: list):
  326. command.send('ToolSetForeGradientColors', Colors=colors)
  327. def get_fore_gradient_colors() -> list:
  328. return colors.str_to_RGBA(command.send('ToolGetForeGradientColors?'))
  329. def set_fore_gradient_interpolation(interpolation):
  330. command.send('ToolSetForeGradientInterpolation', Interpolation=interpolation)
  331. def get_fore_gradient_interpolation():
  332. return command.send('ToolGetForeGradientInterpolation?')
  333. def set_fore_gradient_repetition(repetition):
  334. command.send('ToolSetForeGradientRepetition', Repetition=repetition)
  335. def get_fore_gradient_repetition():
  336. return command.send('ToolGetForeGradientRepetition?')
  337. def set_back_gradient_type(gradient_type):
  338. command.send('ToolSetBackGradientType', GradientType=gradient_type)
  339. def get_back_gradient_type():
  340. return command.send('ToolGetGradientType?')
  341. def set_back_gradient_interpolation(interpolation):
  342. command.send('ToolSetBackGradientInterpolation', Interpolation=interpolation)
  343. def get_back_gradient_interpolation():
  344. return command.send('ToolGetBackGradientInterpolation?')
  345. def set_back_gradient_colors(colors: list):
  346. command.send('ToolSetBackGradientColors', Colors=colors)
  347. def get_back_gradient_colors() -> list:
  348. return colors.str_to_RGBA(command.send('ToolGetBackGradientColors?'))
  349. def set_back_gradient_repetition(repetition):
  350. command.send('ToolSetBackGradientRepetition', Repetition=repetition)
  351. def get_back_gradient_repetition():
  352. return command.send('ToolGetBackGradientRepetition?')
  353. def set_outline_gradient_type(gradient_type):
  354. command.send('ToolSetOutlineGradientType', GradientType=gradient_type)
  355. def get_outline_gradient_type():
  356. return command.send('ToolGetOutlineGradientType?')
  357. def set_outline_gradient_colors(colors: list):
  358. command.send('ToolSetOutlineGradientColors', Colors=colors)
  359. def get_outline_gradient_colors() -> list:
  360. return colors.str_to_RGBA(command.send('ToolGetOutlineGradientColors?'))
  361. def set_outline_gradient_interpolation(interpolation):
  362. command.send('ToolSetOutlineGradientInterpolation', Interpolation=interpolation)
  363. def get_outline_gradient_interpolation():
  364. return command.send('ToolGetOutlineGradientInterpolation?')
  365. def set_outline_gradient_repetition(repetition):
  366. command.send('ToolSetOutlineGradientRepetition', Repetition=repetition)
  367. def get_outline_gradient_repetition():
  368. return command.send('ToolGetOutlineGradientRepetition?')
  369. def set_fore_texture(file_name):
  370. command.send('ToolSetForeTexture', FileName=file_name)
  371. def set_fore_texture_repetition(repetition):
  372. command.send('ToolSetForeTextureRepetition', Repetition=repetition)
  373. def get_fore_texture_repetition():
  374. return command.send('ToolGetForeTextureRepetition?')
  375. def set_fore_texture_opacity(opacity: int):
  376. command.send('ToolSetForeTextureOpacity', Opacity=opacity)
  377. def get_fore_texture_opacity(): #-> int 0..255
  378. return command.send('ToolGetForeTextureOpacity?')
  379. def set_back_texture(file_name):
  380. command.send('ToolSetBackTexture', FileName=file_name)
  381. def set_back_texture_repetition(repetition):
  382. command.send('ToolSetBackTextureRepetition', Repetition=repetition)
  383. def get_back_texture_repetition():
  384. return command.send('ToolGetBackTextureRepetition?')
  385. def set_back_texture_opacity(opacity: int):
  386. command.send('ToolSetBackTextureOpacity', Opacity=opacity)
  387. def get_back_texture_opacity(): #-> int 0..255
  388. return command.send('ToolGetBackTextureOpacity?')
  389. def set_outline_texture(file_name):
  390. command.send('ToolSetOutlineTexture', FileName=file_name)
  391. def set_outline_texture_repetition(repetition):
  392. command.send('ToolSetOutlineTextureRepetition', Repetition=repetition)
  393. def get_outline_texture_repetition():
  394. return command.send('ToolGetOutlineTextureRepetition?')
  395. def set_outline_texture_opacity(opacity: int):
  396. command.send('ToolSetOutlineTextureOpacity', Opacity=opacity)
  397. def get_outline_texture_opacity(): #-> int 0..255
  398. return command.send('ToolGetOutlineTextureOpacity?')
  399. def set_phong_shape_kind(kind):
  400. command.send('ToolSetPhongShapeKind', Kind=kind)
  401. def get_phong_shape_kind():
  402. return command.send('ToolGetPhongShapeKind?')
  403. def set_grid_deformation_mode(mode):
  404. command.send('ToolSetDeformationGridMode', Mode=mode)
  405. def get_grid_deformation_mode():
  406. return command.send('ToolGetDeformationGridMode?')
  407. def set_flood_fill_options(options: list):
  408. command.send('ToolSetFloodFillOptions', Options=options)
  409. def get_flood_fill_options() -> list:
  410. return command.send('ToolGetFloodFillOptions?')
  411. def set_perspective_options(options: list):
  412. command.send('ToolSetPerspectiveOptions', Options=options)
  413. def get_perspective_options() -> list:
  414. return command.send('ToolGetPerspectiveOptions?')