Re: Drawing electronic circuits or schematics with schemdraw Python package in a wxPython GUI
Matthias Brennwald <[email protected]> Fri, 26 Nov 2021 10:13:12 +0100
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <CAEzcwTGdAU81=68dLBoZpHMK-JSOOJOo3ij2EBBoBf937Gj-9w@mail.gmail.com> |
--000000000000c0177405d1ad803b Content-Type: text/plain; charset="UTF-8" On Thu, 25 Nov 2021 at 20:28, Dietmar Schwertberger < [email protected]> wrote: > On 25.11.2021 19:33, Matthias Brennwald wrote: > > I was thinking that a vector graphics format would be better in view of > different (high) DPI environments. However, PNG (or other bitmap formats) > are not necessarily out of question if there is no good way with vector > graphics. > > That's only relevant if you want e.g. to zoom and edit or if Schemdraw > does no good job in rendering into the image. > > If you want to zoom etc., i.e. you want to edit your schematics, then you > should look into something else anyway. > Not sure what you mean here. Something else than wxPython? Something else than SVG? Or something else? > How could I make use of the PNG output from schemdraw in wxPython? The PNG > examples I found for wxPython always make use of a PNG file as the source > for the image data. > > Have a look at the "Using Images" section of the wxPython demo and also at > the wxPython documentation. > The wxPython Demo is a bit tricky to get hold of, at least in my Linux environment. The instructions at https://wxpython.org/pages/downloads/index.html are a bit sketchy when it comes to Linux. That said, I managed to get the schemdraw PNG data to display in a wx panel. I believe the trick is convert the schemdraw PNG data to a stream, which can then feed into wx.ImageFromStream(...). I added a small self-contained example below (code inspired by googling for examples by others). I'd appreciate any thoughts on this. ------------------------------------------------------- import wx from io import BytesIO import schemdraw import schemdraw.elements as elm class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None) p = wx.Panel(self) fgs = wx.FlexGridSizer(cols=1) d = schemdraw.Drawing() d.add(elm.Resistor()) d.add(elm.SourceV()) data = d.get_imagedata('png') stream = BytesIO(data) img = wx.ImageFromStream(stream) sb = wx.StaticBitmap(p, -1, wx.BitmapFromImage(img)) fgs.Add(sb) p.SetSizerAndFit(fgs) self.Fit() app = wx.PySimpleApp() frm = TestFrame() frm.Show() app.MainLoop() ------------------------------------------------------- Why are you "stuck at 4.0"? It's not too hard to upgrade or to use project > specific versions. > I like to write my code such that it works with the libraries available in the standard software repositories of most systems. As far as I can tell, many Linux distros have wxPython version 4.0. Version 4.1 seems to rely on some stuff that is not considered stable/ready for inclusion in most mainline distributions. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAEzcwTGdAU81%3D68dLBoZpHMK-JSOOJOo3ij2EBBoBf937Gj-9w%40mail.gmail.com. --000000000000c0177405d1ad803b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 25 Nov 2021 = at 20:28, Dietmar Schwertberger <<a href=3D"mailto:maillist@schwertberge= r.de">[email protected]</a>> wrote:<br></div><div class=3D"gmail= _quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex= ;border-left:1px solid rgb(204,204,204);padding-left:1ex"> =20 =20 =20 <div> <div>On 25.11.2021 19:33, Matthias Brennwald wrote:<br> </div> <blockquote type=3D"cite"> =20 <span style=3D"white-space:break-spaces">I was thinking that a vector= graphics format would be better in view of different (high) DPI environmen= ts. However, PNG (or other bitmap formats) are not necessarily out of quest= ion if there is no good way with vector graphics.</span></blockquote> <p>That's only relevant if you want e.g. to zoom and edit or if Schemdraw does no good job in rendering into the image.</p> <p>If you want to zoom etc., i.e. you want to edit your schematics, then you should look into something else anyway.<br></p></div></block= quote><div>Not sure what you mean here. Something else than wxPython? Somet= hing else than SVG? Or something else? <br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex"><div><p> </p> <blockquote type=3D"cite"> <div id=3D"gmail-m_-6392289052295859067geary-quote" dir=3D"auto"> <div><span style=3D"white-space:break-spaces">How could I make use = of the PNG output from schemdraw in wxPython? The PNG examples I found for = wxPython always make use of a PNG file as the source for the image data.</s= pan></div> </div> </blockquote> <p>Have a look at the "Using Images" section of the wxPython = demo and also at the wxPython documentation.</p></div></blockquote><div>Th= e wxPython Demo is a bit tricky to get hold of, at least in my Linux enviro= nment. The instructions at <a href=3D"https://wxpython.org/pages/downloads/= index.html">https://wxpython.org/pages/downloads/index.html</a> are a bit s= ketchy when it comes to Linux.</div><div><br></div><div>That said, I manage= d to get the schemdraw PNG data to display in a wx panel. I believe the tri= ck is convert the schemdraw PNG data to a stream, which can then feed into = wx.ImageFromStream(...). I added a small self-contained example below (code= inspired by googling for examples by others). I'd appreciate any thoug= hts on this.<br></div><div><br></div><div>---------------------------------= ----------------------<br></div><div>import wx<br>from io import BytesIO<br= >import schemdraw<br>import schemdraw.elements as elm<br>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<br>class TestFrame(wx.Frame):<br>=C2=A0 =C2= =A0 def __init__(self):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 wx.Frame.__init__(se= lf, None)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p =3D wx.Panel(self)<br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 fgs =3D wx.FlexGridSizer(cols=3D1)<br>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 d =3D schemdraw.Drawing()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 d.add(e= lm.Resistor())<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 d.add(elm.SourceV())<br>=C2= =A0 =C2=A0 =C2=A0 =C2=A0 data =3D d.get_imagedata('png')<br>=C2=A0 = =C2=A0 =C2=A0 =C2=A0 stream =3D BytesIO(data)<br>=C2=A0 =C2=A0 =C2=A0 =C2= =A0 img =3D wx.ImageFromStream(stream)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 sb = =3D wx.StaticBitmap(p, -1, wx.BitmapFromImage(img))<br>=C2=A0 =C2=A0 =C2=A0= =C2=A0 fgs.Add(sb)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p.SetSizerAndFit(fgs)<br= >=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.Fit()<br><br>app =3D wx.PySimpleApp()<br>= frm =3D TestFrame()<br>frm.Show()<br>app.MainLoop()</div><div><div>--------= -----------------------------------------------<br></div></div><div><br></d= iv><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px= 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Wh= y are you "stuck at 4.0"? It's not too hard to upgrade or to use project specific versions.<br></div></blockquote><div><br></div><= div>I like to write my code such that it works with the libraries available= in the standard software repositories of most systems. As far as I can tel= l, many Linux distros have wxPython version 4.0. Version 4.1 seems to rely = on some stuff that is not considered stable/ready for inclusion in most mai= nline distributions.</div></div></div> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups &= quot;wxPython-users" group.<br /> To unsubscribe from this group and stop receiving emails from it, send an e= mail to <a href=3D"mailto:[email protected]">wxpy= [email protected]</a>.<br /> To view this discussion on the web visit <a href=3D"https://groups.google.c= om/d/msgid/wxpython-users/CAEzcwTGdAU81%3D68dLBoZpHMK-JSOOJOo3ij2EBBoBf937G= j-9w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://group= s.google.com/d/msgid/wxpython-users/CAEzcwTGdAU81%3D68dLBoZpHMK-JSOOJOo3ij2= EBBoBf937Gj-9w%40mail.gmail.com</a>.<br /> --000000000000c0177405d1ad803b--