{"id":707,"date":"2024-07-21T16:41:37","date_gmt":"2024-07-21T16:41:37","guid":{"rendered":"https:\/\/doctor-dark.co.uk\/blog\/?p=707"},"modified":"2024-07-21T16:41:37","modified_gmt":"2024-07-21T16:41:37","slug":"at-last-an-app-with-a-gui","status":"publish","type":"post","link":"https:\/\/doctor-dark.co.uk\/blog\/at-last-an-app-with-a-gui\/","title":{"rendered":"At last, an app with a GUI!"},"content":{"rendered":"\n<p>For a while, I have been turning the camera on the Pi in the greenhouse on and off manually. By that I mean&#8230;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Connecting to the Pi using VNC<\/li>\n\n\n\n<li>Opening the \/var\/tmp directory in the file manager<\/li>\n\n\n\n<li>Creating a file called blind to switch the camera off, or<\/li>\n\n\n\n<li>Deleting\/renaming the blind file to switch the camera on<\/li>\n\n\n\n<li>Disconnecting from the Pi<\/li>\n<\/ul>\n\n\n\n<p>That&#8217;s clearly a huge faff, so I decided I&#8217;d finally make a GUI based program to do the job, using guizero. Other GUI libraries were either immensely complex or mysteriously impossible to install. I looked at a couple of example programs, and cobbled this together&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import paramiko\nfrom guizero import App, Text, PushButton\n\ndef switch_camera_on():\n    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(\"sudo rm \/var\/tmp\/blind\")\n    \ndef switch_camera_off():\n    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(\"touch \/var\/tmp\/blind\")\n\nssh = paramiko.SSHClient()\nssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\nssh.connect(\"server-name-here\", username = \"user-name-here\", password = \"password-here\")\n\napp = App(title=\"Greenhouse Camera Control\", bg = \"lightblue\", width = 400, height = 200)\nwelcome_message = Text(app, text = \"Click button to switch camera state.\", size = 15)\nonswitch  = PushButton(app, command = switch_camera_on,  text = \"Camera on.\")\noffswitch = PushButton(app, command = switch_camera_off, text = \"Camera off.\")\n\napp.display()<\/code><\/pre>\n\n\n\n<p>It does need you to have used ssh-keygen on your systems, so they can communicate. I can&#8217;t believe how easy simple stuff like this is to hack out!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"765\" height=\"460\" src=\"https:\/\/doctor-dark.co.uk\/blog\/wp-content\/uploads\/2024\/07\/croppedguipic.png\" alt=\"\" class=\"wp-image-708\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>For a while, I have been turning the camera on the Pi in the greenhouse on and off manually. By that I mean&#8230; That&#8217;s clearly a huge faff, so I decided I&#8217;d finally make a GUI based program to do the job, using guizero. Other GUI libraries were either immensely complex or mysteriously impossible to &hellip; <a href=\"https:\/\/doctor-dark.co.uk\/blog\/at-last-an-app-with-a-gui\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;At last, an app with a GUI!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[13,27,29,28],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-computing","tag-raspberrypi","tag-gui","tag-paramiko","tag-python3"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":1,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":709,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions\/709"}],"wp:attachment":[{"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/doctor-dark.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}