技术控

    今日:173| 主题:49347
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Adding a Simple GUI to shell scripts with kdialog

[复制链接]
高跟鞋的旋律 发表于 6 天前
85 1

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Adding a Simple GUI to Linux shell scripts with kdialog

   Shell scripts are incredibly useful things. They allow you to do something as basic as creating an easy command to replace a more difficult one with lots of flags, to batching up many complex commands to run from acron job. They’re great because you can quickly fire them off in your favorite terminal, but in some cases they require you to remember specific combinations of flags or options. If you find yourself in this situation, you can add some simple GUI dialogs to help you speed your way through the task at hand.
  In order to make use of this tutorial, you’ll need the following:
  
       
  • Access to a Unix-like shell (this is written with bash in mind).
       
  • macOS and *nix OSes (like Linux) should come with this or one like it.
       
  • On Windows, you could install the CygWin environment, or on recent versions of Windows 10 use the "Windows Subsystem for Linux"
       
  •   The base libraries for the KDE desktop environment. You don’t need the entire thing, especially if you already have another DE installed.
      
   Installing kdialog should only be necessary if you started with a desktop environment other than KDE, and you have no other KDE applications on your machine. It is a part of the package kde-baseapps-bin on Ubuntu, which means it is installed by default on Kubuntu. On other derivatives, you can install it with the following command at the terminal:
  Installing kdialog from the terminal.

  [code]sudo apt-get install kde-baseapps-bin[/code]  This will likely result in a sizable installation, as other KDE libraries and packages will be installed along with it. But hey, hard drive space is cheap, right?
  Since scripts are (in general) supposed to do things automatically, we’ll only need to show this dialog in the following situations:
  
       
  • If we need to capture some sort of input from the user, or;
       
  • If we want to show the user some sort of feedback in a noticable way (i.e. not just some text spat out at the command-line).
      
  Let’s take the example of using a command to [backup your Drupal site using drush]. Of course, since you’re a budding Internet entrepreneur, you don’t just have one Drupal site—? you have three. You’d rather not have to run separate commands when you want to back-up all your sites, but at the same time you don’t want to have to remember a long path if you want to take a snapshot of just one. We can use a couple of dialogs to help ourselves by:
  
       
  • Present the user with a list of sites we can back-up, and as her to make a choice, and;
       
  • Show the user a message confirming the result, whether it’s a success or failure.
      
   kDialog works by calling it at the command line along with a dialog type , any parameters that type may require, and any other options such as a dialog title.
  There are a good variety of dialog types to choose from depending on your needs, as follows:
        kDialog Types              Dialog Type     Sample Image     Description                    Information Message Boxes
      
Adding a Simple GUI to shell scripts with kdialog-1 (difficult,following,something,situation,remember)
       Displays a box with an "OK" button to close, providing a text message and either a "non-critical" information, warning, or error icon.
               Passive Pop-up

Adding a Simple GUI to shell scripts with kdialog-2 (difficult,following,something,situation,remember)
       This displays a message that will disappear within a few seconds, i.e. it doesn’t require the user to close or dismiss it.
               Yes/No Message Box
1234下一页
友荐云推荐




上一篇:Saying Farewell to Snapins!
下一篇:The Hitchhiker’s Guide to Ggplot2 in R
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

947068972 发表于 6 天前
一觉醒来,天都黑了。
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表