9 ms·
Show HN: Procal: A simple Qt-based programming calculator
- stephendause 4y agoCool! Do you have any Web programming experience? If so, how would you compare/contrast the experience coding in Qt vs. JavaScript? I have ~1-2 years of experience programming in each, and I tend to prefer Qt because to me, it seems easier to make components that are truly reusable. On the other hand, there are numerous advantages to Web programming, such as the fact that it's easier to deliver content and it's ubiquitous.
- fellerts 4y agoThanks! I come from the embedded world and my preferred language is C - hence the need for a calculator that can wield bits like this. I wrote this tool around 4 years ago and it was my first attempt at creating anything that wasn't a CLI tool or bare-metal firmware. In other words, I can't really compare this experience to anything! I guess the reason I chose Qt over any web-based frameworks is I wanted a standalone app that would launch in a fraction of a second and just do its job. I don't think a webapp (if that's what they're called) would give me that. At the time, it seemed that Qt would work well and, as a bonus, be cross-platform. I had some Python experience to boot which helped. Edit: I do have a personal site at https://www.fellerts.no/ https://www.fellerts.no/ but it's entirely static, no real js to speak of.
- billfruit 4y agoBut Qt is a quite huge dependency, and has sort of turned into a commercial product. If you were starting to develop something similar today would you still choose Qt for it..
- fellerts 4y agoGood question. If I want fast and cross-platform, GTK might be a more viable option today. What would you choose for a project like this in 2023?
- billfruit 4y agoSome years ago JavaFx would have been a reasonable choice.
- ranger_danger 4y agoQt hands down. I don't consider GTK particularly usable or friendly, especially outside of Linux.
- oynqr 4y agoThis is so bad, even on Linux, that the experience of trying to package a GTK4 libhandy application to the distro I use made me permanently switch from Gnome to KDE.
- criddell 4y agoI'd pick the native toolkit for wherever I want to use it. If I want it on Windows, I'd use C++ & Win32 / WinRT. On mac, Swift + AppKit. For iOS, Swift + UIKit. For Linux, probably C and GTK (I mostly use Gnome-based distros). I'd go 100% native because that's how you make the best app for that platform. I also enjoy working with different toolkits and if I wanted this on more than one platform, I think I would enjoy designing and building it for different environments. For example the version I'd make for my small screen touch-based phone would probably be significantly different than what I'd want on my keyboard and mouse equipped big screen desktop. A multi-platform or web-based solution would have too many compromises.
- jenadine 4y agoSlint? https://slint-ui.com https://slint-ui.com
- ognarb 4y agoQt is not turning into a commercial project. It has always been a project which is dual licensed under GPL (and later some of the modules were also licensed under LGPL) and a commercial license. It's just that the Qt company always tries to make it non-clear that Qt is not open source to drive their sales. Regarding bloat, Qt is quite modular and if you want just the widgets you only need QtBase and none of the additional modules.
- ranger_danger 4y agomost components are LGPL not GPL. also after I think it was Qt 5.6, they switched to LGPLv3 instead of v2, so the anti-tivoization clause applies.
- jakear 4y agoCould you give an example (source code link) of a "truly reusable" component?
- ranger_danger 4y agoIt's old but I still use it just fine with modern Qt versions: https://docs.huihoo.com/qt/solutions/4/qtcopydialog/qtcopydialog.html https://docs.huihoo.com/qt/solutions/4/qtcopydialog/qtcopydi... https://github.com/sintegrial/qtsolutions https://github.com/sintegrial/qtsolutions
- stephendause 4y agoOne that I have been thinking about lately is the `QEnumComboBox` [1]. It takes the concept of a combobox (i.e. drop down list/`select`) and combines it with a python `Enum` to produce a very commonly desired functionality: allowing the user to select a value and then converting it to an `Enum`. This to me seems easily reusable because it encapsulates that functionality in a clean way. I can't think of a corresponding example in a JavaScript framework, but I would love to see one. I think this might be more difficult because one can't really pass types at runtime. I think instead of "truly reusable" I should have said something like "requires minimal configuration." I think Python's reflection capabilities allow one to supply less boilerplate when writing PyQt apps. This is just a subjective impression that I have, and unfortunately I am having trouble elaborating on this in a way that I think would be effective. That is why I asked the author what they thought, since I am wondering if anyone else has had this impression. However, I will think about this more, and I might provide more examples if I can think of them. [1] https://pyapp-kit.github.io/superqt/widgets/qenumcombobox/ https://pyapp-kit.github.io/superqt/widgets/qenumcombobox/
- jakear 4y agoI'm sure there's a million things out in reactland for this, but even in vanilla JS it's pretty simple. I'd write it something like this: https://github.com/JacksonKearl/JSEnumComboBox/blob/main/index.ts https://github.com/JacksonKearl/JSEnumComboBox/blob/main/ind..., demo at https://jacksonkearl.github.io/JSEnumComboBox/ https://jacksonkearl.github.io/JSEnumComboBox/ Neither JS nor Python really have types at runtime or any other time, but you can approximate them with Objects and/or Classes (of course, I repeat myself ;) ). With some TS magic you can even get the `setEnumClass` call to be well typed, though if I were building it from scratch I'd make the EnumClass prop immutable, too many weird corner cases otherwise. I've never worked extensively with Qt myself, but when helping out a friend making Maya plugins in Qt we'd occasionally hit SEGFAULTS from writing seemingly mundane Python that'd crash all of Maya. That was enough to turn me off of it, but looking through the docs you linked there are some compelling components. It's nice to have a component library separated from a specific framework (in the React/VUE/etc. sense)... I don't know of any in JS. Every framework seems to think their (incompatibile with everything else) approach to reactivity is the hold grail, and being modular across it would be impossible. Though reconsidering, I suppose Qt is sorta the same... it's just another framework and their "signals" aren't Python. Ah well. Diving deeper, signals are weird... they aren't even really part of the underlying C++! Some sort of strange new modifier Qt invented at the level of `private`/`public`/`protected` and such. https://doc.qt.io/qt-6/signalsandslots.html https://doc.qt.io/qt-6/signalsandslots.html
- Devil5757 4y agoHi
- nazgulsenpai 4y agoThis comment looks like it was written by ChatGPT!
- ryanianian 4y agoNeat little project. Easy to setup and use. Unfortunately with macOS's "Dark Mode" enabled the colors have little or no contrast. And the UI renders very small for my eyes (and compared to the demo gif). This is a criticism of Qt (or maybe its python bindings) rather than this project. (Screenshot: https://imgur.com/a/G9eAPoO https://imgur.com/a/G9eAPoO) I wonder if there's a way to shimmy in a "modern macOS Qt renderer" or something into an existing project like this without a rewrite?
- fellerts 4y agoThanks for checking it out. You could play with the QT_SCALE_FACTOR environment variable to fix the scaling issue at least. Something like this could work: $ QT_SCALE_FACTOR=2 python procal.py As for the colors, that's probably something this tool should handle. I'll take a look to see if this is an easy fix.
- fellerts 4y ago> I wonder if there's a way to shimmy in a "modern macOS Qt renderer" or something into an existing project like this without a rewrite? Apparently there is. I hacked something together in a new branch: https://github.com/fellerts/procal/tree/fredrik/theme https://github.com/fellerts/procal/tree/fredrik/theme. Feel free to check it out and let me know how it works for you.
- eql5 4y agoI tried on macOS, yes dark mode works great now, thanks. But I needed to change all QFont('monospace', 10) occurrences to QFont('Monaco', 12) in order to make it look nice.
- fellerts 4y agoThanks for trying it out. If you wouldn't mind, I'd appreciate it if you could open an issue with a screenshot of how the default behavior looked. Edit: merged a fix for this, thanks for reporting.
- 4y ago
- MatthiasPortzel 4y agoOne feature that I'd love in a programming calculator is the ability to set arbitrary bit widths. 32bit or 64 bit is okay, but a lot of the time when I'm thinking about individual bits; it's because I'm doing embedded programming for 8 or 16 bit devices. Similarly, the ability to toggle signed and unsigned representations.
- fellerts 4y agoI totally agree, which is why I included that in procal! Just right-click a cell to turn it into a sign bit.
- SimDeBeau 4y agoThats really convenient, but probably not the most discoverable.
- fellerts 4y agoFair point. At least it's mentioned in the README. My goal was a lean and efficient tool without any extra fluff, so discoverability took a hit.
- MatthiasPortzel 4y agoI did not notice that. I will have to download procal and give it a try.
- recklesstodd 4y agoHave a look at this: https://www.heise.de/download/product/bitfummler-70589?hg=1&hgi=1&hgf=false https://www.heise.de/download/product/bitfummler-70589?hg=1&...
- spc476 4y agoI once wrote a calculator that has five output displays: signed decimal, unsigned decimal, hexadecimal, octal and binary. I did it that way because I was tired of having to select the output mode. I also added the ability to select 8, 16, 32 or 64 bit output.
- amelius 4y agoThis would be even better if it integrated with every desktop program out there. E.g. if you want to compute the width of some object in Inkscape or Freecad, using some formula not supported by those programs.
- fellerts 4y agoI used to have xclip integration in procal that would copy any selected text into the input field for just this purpose. However I removed it because it wasn't particularly useful and got in the way of "normal calculating" (apparently I select text quite frequently). Let me know if you think of a usage pattern that would make sense!
- schemescape 4y agoI didn’t realize you can use Qt from Python! How is the developer experience for that? Anyone able to contrast with Tkinter?
- JasonFruit 4y agoThe developer experience is great, though its approach is much different from TKinter. The documentation is excellent, there aren't maddening incomplete corners like GTK, the results look good (if you think Qt looks good), and it's simple and straightforward. The main downside is that sometimes your code looks more like Qt and less like Python.
- e4m2 4y ago> The main downside is that sometimes your code looks more like Qt and less like Python. This can be remedied to a degree: https://doc.qt.io/qtforpython/considerations.html#features https://doc.qt.io/qtforpython/considerations.html#features
- johndubchak 4y agoAdding the snake case does move it more to the Python idioms, for sure.
- VadimPR 4y agoQalculate! is my favourite GTK and Qt-based calculator that's great at accepting all sorts of inputs, even solving for X: https://github.com/Qalculate/qalculate-qt https://github.com/Qalculate/qalculate-qt
- EntrePrescott 4y agoI second that. Great program. Not only does Qalculate! also handle binary operations and numbers of any base of your choice (including hex, octal, binary), both for output and input (even when working in another base, e.g. when the output mode is set to decimal, you can just input hexadecimal values such as 0x1AF and Qalculate! will understand)… … but most importantly it can calculate with units and show the result converted to your liking e.g. you can write 10 Nm×2pi×20/minute to W and Qalculate will show the result as 209,4395102 W. When you get used to that, you don't want to use any calculator that doesn't have that feature any more.
- jonas-w 4y agoSecond that also as a cli `qalc`. Use it nearly every day, to convert units and quickly qalculate that would take way longer when opening a gui or pulling out my phone. e.g. > 100 GB/minute to kB/s https://github.com/Qalculate/libqalculate https://github.com/Qalculate/libqalculate
- ThePhysicist 4y agoI love PyQt, I wrote lots of graphical user interfaces for my lab equipment during my PhD, was super easy to wire stuff up and replace Labview with Python. The design was similar to this app, simple frontend that allowed you to e.g. set microwave frequencies, toggle outputs or make measurements. My colleagues were initially quite skeptical but 10 years later they're still using the software and it spread to other labs, they even hired a full-time developer to work on it.
- dekhn 4y agoI use PyQt to write an entire interface to my self-built microscope. It's awesome. Personally, i design the UI in Qt Designer, then wire it up in code. The absolute gem of gems in Qt is the Graphics View Framework, which is a retained scene graph for 2D rendering with extraordinary power and performance. I can do realtime work with the scope including image processing all from python but at C++ speeds.
- spacechild1 4y agoQGraphicsView is indeed awesome. I have been using it in the tile map editor of my hobby 2D game engine and it can easily handle thousands of objects. IIRC, it uses spatial partitioning to determine which objects need to be redrawn.
- fellerts 4y agoIndeed! And with PyQtGraph you can create live graphs and visualizations that update at 100 Hz or more. It's really fun.
- appveyor 4y agoFlet (https://flet.dev https://flet.dev) is a new GUI library for Python to write apps like that. It uses Flutter to render UI with a modern-looking Material design. Your app can be run as a desktop app and published as a web app (standalone with Pyodide or server-driven with built-in web server).
- deleted 4y ago
- madduci 4y agoDo you think to port the code to C++ or do you think to keep it in Python?
- fellerts 4y agoI wasn't planning on that, no. Is there a good reason to do so?
- yoavm 4y agoWhat's wrong with Python? Do you find the calculator too slow?
- smolsky 4y agoLOL, here is my C++ implementation of the same concept: https://github.com/os12/calc https://github.com/os12/calc
- johndubchak 4y agoI love that you include the BNF-ish grammar. Grammars are so straight-forward to read, I wish my eyes didn't glaze over during those times I've tried to sit down and create one.
- not_the_fda 4y agoI believe your license is incorrect. PyQt is licensed either commercial or GPL, so you would have to either purchase a license or license this under GPL verses the more permissive MIT license you are using.
- fellerts 4y agoThanks! I changed the license to GPLv3.
- sho_hn 4y agoNote your alternative would be to use the official "Qt for Python" (aka PySide) bindings. Those are LGPL, which is one of the main reasons they exist (PyQt was started earlier but unlike much of Qt is not LGPL). This is from when Qt still cared about LGPL, i.e. the Nokia days when the aim was to be the commercial-friendly Nokia SDK.
- bombolo 4y agoSince pyside was discontinued once already, I tend to not trust it any longer.
- necovek 4y agoWasn't QT originally GPL-or-commercial by Trolltech? Which is what spawned GNOME and Gtk as a response to QT-using KDE?
- not_the_fda 4y agoNot exactly. It was originally licensed under its own Qt Free License which the K Desktop environment was using and becoming a large player in the DE space. It was not considered "free software", which spawned GTK. Then it was released under its own QPL license, and KDE negotiated that if Qt went bankrupt it would change to an MIT license. Finally it was released as GPL.
- 4y ago
- gfodor 4y agoWow I’m reading Hacker’s Delight and was just wondering if something like this existed.
- smolsky 4y agoLOL, nice! I wrote something quite similar a few years ago: https://github.com/os12/calc https://github.com/os12/calc
- johndubchak 4y agoCool, thanks for sharing your github link.
- manchmalscott 4y agoI find it...mildly disconcerting that a calculator app where one of the key motivations is "it's a hassle to copy + paste things in" just chucks whatever you enter into eval().
- frutiger 4y agoAn expression you author executes on your machine. It’s not wholly unreasonable to use eval(). If it were executing third party input on your machine, then it’s a completely different ball game.
- recklesstodd 4y agoSimilar concept but more oriented for embedded development: https://www.heise.de/download/product/bitfummler-70589?hg=1&hgi=1&hgf=false https://www.heise.de/download/product/bitfummler-70589?hg=1&... It includes a C interpreter and is very handy when manipulating registers. Unfortunately not open-source.
- themadsens 4y agoHmm doesn't seem to do 64bit very well: 0xdeadbeefcafebabe -> 0xdeadbeefcafeb800 Is the result by any means passing through a double? like in freakin' JS!
- fellerts 4y agoGood catch, that appears to be a bug! I'll have a look tomorrow.
- p4bl0 4y agoCool link for the PyQt project example! My daily calculator is `jupyter qtconsole` (formerly `ipython qtconsole`). I've had it binded to Meta+Q forever and it is very handy to have a full Python REPL which can occasionally display graphs and stuff that can pop up at hand.