<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: simonritchie</title>
    <description>The latest articles on DEV Community by simonritchie (@simonritchie).</description>
    <link>https://dev.to/simonritchie</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F747356%2F58f08c8c-de1c-4ee9-8f6d-ea40366f3c8b.png</url>
      <title>DEV Community: simonritchie</title>
      <link>https://dev.to/simonritchie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simonritchie"/>
    <language>en</language>
    <item>
      <title>[WIP]SVG-based Python frontend lib</title>
      <dc:creator>simonritchie</dc:creator>
      <pubDate>Sat, 11 Dec 2021 04:02:01 +0000</pubDate>
      <link>https://dev.to/simonritchie/wipsvg-based-python-frontend-lib-3o</link>
      <guid>https://dev.to/simonritchie/wipsvg-based-python-frontend-lib-3o</guid>
      <description>&lt;p&gt;Hi, great DEVs!&lt;/p&gt;

&lt;p&gt;This is my first post on dev.to, and it is translated from the following Japanese article (note: skipped lots of usage details):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://qiita.com/simonritchie/items/26f7da93ac85f60b2972"&gt;https://qiita.com/simonritchie/items/26f7da93ac85f60b2972&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm working on an SVG-based frontend library that can be written in Python (currently work in progress).&lt;/p&gt;

&lt;p&gt;Please forgive me if this article is in poor English.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic information about the library
&lt;/h2&gt;

&lt;p&gt;GitHub:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/simon-ritchie/apysc"&gt;https://github.com/simon-ritchie/apysc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://simon-ritchie.github.io/apysc/index.html"&gt;https://simon-ritchie.github.io/apysc/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since it is already registered with PyPI, you can quickly install it with pip as follows (Python 3.6 or later is supported):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install apysc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What kind of library is it (what it can do currently)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Ability to draw various SVG shapes
&lt;/h3&gt;

&lt;p&gt;It can draw various SVG shapes such as rectangles, circles, and lines with lots of configurations:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pKK9Nxjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctdoq0nh7i3shqon1xvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pKK9Nxjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctdoq0nh7i3shqon1xvw.png" alt="Lots of SVG instances drawn with apysc" width="652" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, a rectangle can be drawn in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rectangle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sprite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graphics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;draw_rect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, each shape can be handled as a group with a container instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mouse event-related operations
&lt;/h3&gt;

&lt;p&gt;You can register mouse events such as click, mouse down/up, mouse over/out, move, etc to placed elements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--luOb4wux--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qhiolt5ynslove7umtd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--luOb4wux--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qhiolt5ynslove7umtd.gif" alt="Mouse move example" width="200" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For instance, a click event can be set as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;on_click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MouseEvent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Clicked!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;on_click&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Set each attribute
&lt;/h3&gt;

&lt;p&gt;You can also update the value of each attribute of the generated SVG  element. For example, to set the fill color to magenta and update the line width and line color later, use the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fill_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'#f0a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;line_thickness&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;line_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'#fff'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  (Tween) animation settings
&lt;/h3&gt;

&lt;p&gt;Each attribute can animate, including easing settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MbHAfW9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfq2jvmnsk2dej1ei322.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MbHAfW9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfq2jvmnsk2dej1ei322.gif" alt="Tween animation example" width="550" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interfaces are unified with the prefix &lt;code&gt;animation_&lt;/code&gt;, for example, the animation setting for x-coordinate is set as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;animation_x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;easing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Easing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EASE_OUT_QUINT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Saving the HTML and displaying it in Jupyter
&lt;/h3&gt;

&lt;p&gt;Code written in Python can be saved as HTML and displayed in a browser.&lt;/p&gt;

&lt;p&gt;Alternatively, you can use it directly in the Jupyter notebook, JupyterLab or Colaboratory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L7sTxeKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ym34gbo0xm9tqkdplrlr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L7sTxeKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ym34gbo0xm9tqkdplrlr.png" alt="apysc on the Jupyter notebook" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notes: Jupyter on VS Code is currently not supported.&lt;/p&gt;

&lt;h3&gt;
  
  
  You can benefit from type annotations
&lt;/h3&gt;

&lt;p&gt;In the internal implementation of apysc, the code is passed through mypy's Lint as CI, and in the editor, the code is checked with Pylance (Pyright), so basically all the code is type-annotated and can benefit from it (for instance, type-checking or code completion).&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefit from docstring
&lt;/h3&gt;

&lt;p&gt;Since the internal implementation of apysc sets Lint in the CI so that NumPy-style docstring settings are mandatory, you can develop while referring to docstrings in each interface.&lt;/p&gt;

&lt;p&gt;In addition, the URLs of the documentation for each interface are included in the &lt;code&gt;References&lt;/code&gt; section of the docstring, so you can easily check what the code output will look like when you run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dB-jKkWz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uuoddokbraf03t9haii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dB-jKkWz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uuoddokbraf03t9haii.png" alt="References URL example" width="727" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What features I'm planning to implement in the future?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Since it's originally intended to be used on Django project, I'd like to add various implementations and interfaces for use with parameters and template tags in Django templates.&lt;/li&gt;
&lt;li&gt;When the basic classes are more complete, I'd like to add various components (widgets), including the charts interfaces.&lt;/li&gt;
&lt;li&gt;In the future, I'd like to study and incorporate other areas besides SVG (Canvas, Processing, 3D, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion of article
&lt;/h2&gt;

&lt;p&gt;Please read the documentation for more detailed information:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://simon-ritchie.github.io/apysc/index.html"&gt;https://simon-ritchie.github.io/apysc/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you think you'll like apysc or excited about its future, I'd be very happy if you'd click a start on GitHub!🥳🚀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/simon-ritchie/apysc"&gt;https://github.com/simon-ritchie/apysc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>svg</category>
      <category>apysc</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
