Announcement

Collapse
No announcement yet.

Making my life easier

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Making my life easier

    I want to wright a simple program for automating some of my daily workload for my media server, adding new user adding the user to a secondary user group adding them to a chroot jail amonst other things.

    I would like to have a gui to work with.

    I haven't coded in about ten fifteen years since i learnt visual basic 6.0 back in college.

    And that was on windows since then ive become a full fledged linux user.

    Ive got an operrunity yo upgrade to the latest LTS of kubuntu 20.04 so i will be building this project for that platform.

    I know im gunna have to learn a new language but which one to pick thats where im stuck there are just so many to choose from.

    Any help you may be able to offer would be much appreciated

    Sent from my POT-LX1 using Tapatalk
    Tutorials:
    Yoda's ownCloud Installation on Kubuntu 20.04

    #2
    Any suggestions on the programming language would be helpful something flexible but not overly complicated.

    Ive heard good things about python but im not sure about the GUI possibilities with python.

    Sent from my POT-LX1 using Tapatalk
    Tutorials:
    Yoda's ownCloud Installation on Kubuntu 20.04

    Comment


      #3
      The Qt5 API is a complete package and the GPL version is open source and free. It is based on and uses the C++ language. While Python is a good scripting language if you want to add GUI components you have to synchronize it with 2nd and 3rd party tools. Back in 2004 when I switched from Visual Studio to Qt I learned both Qt and C++ at the same time. Sixteen years later and I've heard that the apps I wrote back then are still being used. (I retired in 2008).

      Here is tutorial for Qt5 (Qt is pronounced "Cute").
      Last edited by GreyGeek; Jun 22, 2020, 08:29 PM.
      "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
      – John F. Kennedy, February 26, 1962.

      Comment


        #4
        Originally posted by GreyGeek View Post
        The Qt5 API is a complete package and the GPL version is open source and free. It is based on and uses the C++ language. While Python is a good scripting language if you want to add GUI components you have to synchronize it with 2nd and 3rd party tools. Back in 2004 when I switched from Visual Studio to Qt I learned both Qt and C++ at the same time. Sixteen years later and I've heard that the apps I wrote back then are still being used. (I retired in 2008).

        Here is tutorial for Qt5 (Qt is pronounced "Cute").
        Thanks GreyGeek it sounds like learning c++ and qt5 might be benifical not only for this project but for future projects or jobs

        Sent from my POT-LX1 using Tapatalk
        Tutorials:
        Yoda's ownCloud Installation on Kubuntu 20.04

        Comment


          #5
          Just out of curiosity i know c++ works on linux and windows how does that work as i know windows uses dynamic link library's not sure what the linux equivalent is.

          Are there two version's of c++ or is it a difference in the way you define recourses in your code

          Sent from my POT-LX1 using Tapatalk
          Tutorials:
          Yoda's ownCloud Installation on Kubuntu 20.04

          Comment


            #6
            I would choose Python or Java before I would choose C++ as a beginner language. And, I would choose Python over Java.

            Python and Java are highly practical in today's job market. And, are much easier to use for simple programs than C++, in my opinion.

            Python also has Qt bindings/libraries and does not require a "special" preprocessor as C++ does to compile Qt code.

            Comment


              #7
              Originally posted by andystmartin View Post
              I would choose Python or Java before I would choose C++ as a beginner language. And, I would choose Python over Java.

              Python and Java are highly practical in today's job market. And, are much easier to use for simple programs than C++, in my opinion.

              Python also has Qt bindings/libraries and does not require a "special" preprocessor as C++ does to compile Qt code.
              Thanks for your input my friend, would you know any good resources for learning python

              Sent from my POT-LX1 using Tapatalk
              Tutorials:
              Yoda's ownCloud Installation on Kubuntu 20.04

              Comment


                #8
                C, Python, Java and C++ are ranked 1, 2, 3 and 4.

                And, it is a myth that learning C or C++ is harder than Python or Java. All programming tools have five basic functions: input, output, sequence, choice and repetition (looping). Each have their easy points and hard points.

                The biggest problem with making GUI apps with Python and Java is version compatibility between the language and the GUI tools. I ran into that big time while looking to replace VisualFoxPro 5.0 when MS dropped it. Over the years that problem still remains, but is not as bad as it used to be.

                Here is a PyQt5 tutorial playlist
                https://www.youtube.com/watch?v=Vde5...LTEHO9zJDDLpYj


                Python is a fun language and is especially good at quick and dirty script programming. The major Python GUI tools are Tkinter, wxPython, Kiwi GUI and PyQt5. Compared to PyQt5 and the Qt API the others are rudimentary. Tk-Tcl is in the repository and it won't take long to install and play with them to see how limited tkinter is. Some of Kiwi is in the repository as well. qt5-default is also in the repository, along with a ton of qt5-xxxx packages. So is python3-pyqt5, which also installs:
                QtCore
                QtDBus
                QtDesigner
                QtGui
                QtHelp
                QtNetwork
                QtPrintSupport
                QtTest




                The Qt API is EXTREMELY RICH in methods and properties for every aspect of GUI programming. Like Java and Python, PyQt5 is cross platform. You write the code on one platform and compile it on all the others, including mobile phones.

                Using Qt's "Signals and Slots" technology, regardless of which language you chose to use, makes callbacks child's play. The Open Source version of Qt5 binaries can be downloaded from here. If you install the qt5-x packages from the repository the libraries will be scattered among the appropriate directories. The web installer will put everything into one directory in your home account. I've run Qt both ways and it makes little difference.

                Here is a simple application with a couple of buttons:
                Click image for larger version

Name:	qvboxlayout.png
Views:	1
Size:	3.9 KB
ID:	644804
                and the code to create it:
                Code:
                from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
                app = QApplication([])
                window = QWidget()
                layout = QVBoxLayout()
                layout.addWidget(QPushButton('Top'))
                layout.addWidget(QPushButton('Bottom'))
                window.setLayout(layout)
                window.show()
                app.exec_()

                For a more complicated example here is an image of the most commonly used widgets in PyQt5:
                Click image for larger version

Name:	widgets.png
Views:	1
Size:	47.9 KB
ID:	644803
                Here is the code which produced it:
                Code:
                #!/usr/bin/env python
                #############################################################################
                ##
                ## Copyright (C) 2013 Riverbank Computing Limited.
                ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
                ## All rights reserved.
                ##
                ## This file is part of the examples of PyQt.
                ##
                ## $QT_BEGIN_LICENSE:BSD$
                ## You may use this file under the terms of the BSD license as follows:
                ##
                ## "Redistribution and use in source and binary forms, with or without
                ## modification, are permitted provided that the following conditions are
                ## met:
                ##   * Redistributions of source code must retain the above copyright
                ##     notice, this list of conditions and the following disclaimer.
                ##   * Redistributions in binary form must reproduce the above copyright
                ##     notice, this list of conditions and the following disclaimer in
                ##     the documentation and/or other materials provided with the
                ##     distribution.
                ##   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
                ##     the names of its contributors may be used to endorse or promote
                ##     products derived from this software without specific prior written
                ##     permission.
                ##
                ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
                ## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
                ## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
                ## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
                ## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
                ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
                ## $QT_END_LICENSE$
                ##
                #############################################################################
                
                from fbs_runtime.application_context.PyQt5 import ApplicationContext
                from PyQt5.QtCore import QDateTime, Qt, QTimer
                from PyQt5.QtWidgets import (QApplication, QCheckBox, QComboBox, QDateTimeEdit,
                        QDial, QDialog, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
                        QProgressBar, QPushButton, QRadioButton, QScrollBar, QSizePolicy,
                        QSlider, QSpinBox, QStyleFactory, QTableWidget, QTabWidget, QTextEdit,
                        QVBoxLayout, QWidget)
                
                import sys
                
                class WidgetGallery(QDialog):
                    def __init__(self, parent=None):
                        super(WidgetGallery, self).__init__(parent)
                
                        self.originalPalette = QApplication.palette()
                
                        styleComboBox = QComboBox()
                        styleComboBox.addItems(QStyleFactory.keys())
                
                        styleLabel = QLabel("&Style:")
                        styleLabel.setBuddy(styleComboBox)
                
                        self.useStylePaletteCheckBox = QCheckBox("&Use style's standard palette")
                        self.useStylePaletteCheckBox.setChecked(True)
                
                        disableWidgetsCheckBox = QCheckBox("&Disable widgets")
                
                        self.createTopLeftGroupBox()
                        self.createTopRightGroupBox()
                        self.createBottomLeftTabWidget()
                        self.createBottomRightGroupBox()
                        self.createProgressBar()
                
                        styleComboBox.activated[str].connect(self.changeStyle)
                        self.useStylePaletteCheckBox.toggled.connect(self.changePalette)
                        disableWidgetsCheckBox.toggled.connect(self.topLeftGroupBox.setDisabled)
                        disableWidgetsCheckBox.toggled.connect(self.topRightGroupBox.setDisabled)
                        disableWidgetsCheckBox.toggled.connect(self.bottomLeftTabWidget.setDisabled)
                        disableWidgetsCheckBox.toggled.connect(self.bottomRightGroupBox.setDisabled)
                
                        topLayout = QHBoxLayout()
                        topLayout.addWidget(styleLabel)
                        topLayout.addWidget(styleComboBox)
                        topLayout.addStretch(1)
                        topLayout.addWidget(self.useStylePaletteCheckBox)
                        topLayout.addWidget(disableWidgetsCheckBox)
                
                        mainLayout = QGridLayout()
                        mainLayout.addLayout(topLayout, 0, 0, 1, 2)
                        mainLayout.addWidget(self.topLeftGroupBox, 1, 0)
                        mainLayout.addWidget(self.topRightGroupBox, 1, 1)
                        mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0)
                        mainLayout.addWidget(self.bottomRightGroupBox, 2, 1)
                        mainLayout.addWidget(self.progressBar, 3, 0, 1, 2)
                        mainLayout.setRowStretch(1, 1)
                        mainLayout.setRowStretch(2, 1)
                        mainLayout.setColumnStretch(0, 1)
                        mainLayout.setColumnStretch(1, 1)
                        self.setLayout(mainLayout)
                
                        self.setWindowTitle("Styles")
                        self.changeStyle('Windows')
                
                    def changeStyle(self, styleName):
                        QApplication.setStyle(QStyleFactory.create(styleName))
                        self.changePalette()
                
                    def changePalette(self):
                        if (self.useStylePaletteCheckBox.isChecked()):
                            QApplication.setPalette(QApplication.style().standardPalette())
                        else:
                            QApplication.setPalette(self.originalPalette)
                
                    def advanceProgressBar(self):
                        curVal = self.progressBar.value()
                        maxVal = self.progressBar.maximum()
                        self.progressBar.setValue(curVal + (maxVal - curVal) / 100)
                
                    def createTopLeftGroupBox(self):
                        self.topLeftGroupBox = QGroupBox("Group 1")
                
                        radioButton1 = QRadioButton("Radio button 1")
                        radioButton2 = QRadioButton("Radio button 2")
                        radioButton3 = QRadioButton("Radio button 3")
                        radioButton1.setChecked(True)
                
                        checkBox = QCheckBox("Tri-state check box")
                        checkBox.setTristate(True)
                        checkBox.setCheckState(Qt.PartiallyChecked)
                
                        layout = QVBoxLayout()
                        layout.addWidget(radioButton1)
                        layout.addWidget(radioButton2)
                        layout.addWidget(radioButton3)
                        layout.addWidget(checkBox)
                        layout.addStretch(1)
                        self.topLeftGroupBox.setLayout(layout)    
                
                    def createTopRightGroupBox(self):
                        self.topRightGroupBox = QGroupBox("Group 2")
                
                        defaultPushButton = QPushButton("Default Push Button")
                        defaultPushButton.setDefault(True)
                
                        togglePushButton = QPushButton("Toggle Push Button")
                        togglePushButton.setCheckable(True)
                        togglePushButton.setChecked(True)
                
                        flatPushButton = QPushButton("Flat Push Button")
                        flatPushButton.setFlat(True)
                
                        layout = QVBoxLayout()
                        layout.addWidget(defaultPushButton)
                        layout.addWidget(togglePushButton)
                        layout.addWidget(flatPushButton)
                        layout.addStretch(1)
                        self.topRightGroupBox.setLayout(layout)
                
                    def createBottomLeftTabWidget(self):
                        self.bottomLeftTabWidget = QTabWidget()
                        self.bottomLeftTabWidget.setSizePolicy(QSizePolicy.Preferred,
                                QSizePolicy.Ignored)
                
                        tab1 = QWidget()
                        tableWidget = QTableWidget(10, 10)
                
                        tab1hbox = QHBoxLayout()
                        tab1hbox.setContentsMargins(5, 5, 5, 5)
                        tab1hbox.addWidget(tableWidget)
                        tab1.setLayout(tab1hbox)
                
                        tab2 = QWidget()
                        textEdit = QTextEdit()
                
                        textEdit.setPlainText("Twinkle, twinkle, little star,\n"
                                              "How I wonder what you are.\n" 
                                              "Up above the world so high,\n"
                                              "Like a diamond in the sky.\n"
                                              "Twinkle, twinkle, little star,\n" 
                                              "How I wonder what you are!\n")
                
                        tab2hbox = QHBoxLayout()
                        tab2hbox.setContentsMargins(5, 5, 5, 5)
                        tab2hbox.addWidget(textEdit)
                        tab2.setLayout(tab2hbox)
                
                        self.bottomLeftTabWidget.addTab(tab1, "&Table")
                        self.bottomLeftTabWidget.addTab(tab2, "Text &Edit")
                
                    def createBottomRightGroupBox(self):
                        self.bottomRightGroupBox = QGroupBox("Group 3")
                        self.bottomRightGroupBox.setCheckable(True)
                        self.bottomRightGroupBox.setChecked(True)
                
                        lineEdit = QLineEdit('s3cRe7')
                        lineEdit.setEchoMode(QLineEdit.Password)
                
                        spinBox = QSpinBox(self.bottomRightGroupBox)
                        spinBox.setValue(50)
                
                        dateTimeEdit = QDateTimeEdit(self.bottomRightGroupBox)
                        dateTimeEdit.setDateTime(QDateTime.currentDateTime())
                
                        slider = QSlider(Qt.Horizontal, self.bottomRightGroupBox)
                        slider.setValue(40)
                
                        scrollBar = QScrollBar(Qt.Horizontal, self.bottomRightGroupBox)
                        scrollBar.setValue(60)
                
                        dial = QDial(self.bottomRightGroupBox)
                        dial.setValue(30)
                        dial.setNotchesVisible(True)
                
                        layout = QGridLayout()
                        layout.addWidget(lineEdit, 0, 0, 1, 2)
                        layout.addWidget(spinBox, 1, 0, 1, 2)
                        layout.addWidget(dateTimeEdit, 2, 0, 1, 2)
                        layout.addWidget(slider, 3, 0)
                        layout.addWidget(scrollBar, 4, 0)
                        layout.addWidget(dial, 3, 1, 2, 1)
                        layout.setRowStretch(5, 1)
                        self.bottomRightGroupBox.setLayout(layout)
                
                    def createProgressBar(self):
                        self.progressBar = QProgressBar()
                        self.progressBar.setRange(0, 10000)
                        self.progressBar.setValue(0)
                
                        timer = QTimer(self)
                        timer.timeout.connect(self.advanceProgressBar)
                        timer.start(1000)
                
                
                if __name__ == '__main__':
                    appctxt = ApplicationContext()
                    gallery = WidgetGallery()
                    gallery.show()
                    sys.exit(appctxt.app.exec_())
                EDIT: I forgot to say that one does not have to write the code shown above. Using the QDesigner app the window can be drawn using drag&drop from a list of controls, and then settings changed and/or added. That code above is generated automatically as a *.ui when the code is compiled.
                END OF EDIT

                What isn't shown is the depth and range of properties and functions available to each control. The layouts, groupings, tab settings, intial values, ranges, colors, text fonts, and on and on and on.
                A text box control, for example, is made using the QLineEdit widget. It has 77 properties, 18 of its own, 58 inherited from QWidget, and 1 from QObject. QObject is the base object from which all classes derive. QLineEdit has 51 functions, 28 slots and 8 signals.

                I got all of these examples from here.
                The docs are here.
                The Qt Reference page is here.
                Last edited by GreyGeek; Jun 24, 2020, 06:24 PM.
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #9
                  Adding a new user and adding a user to a group are easily done by shell scripting, and I imagine adding to chroot jail is the same. I think the quickest (that is, the least learning curve) way to get to a GUI for these would be to use KDialog for the user interactions, or a tool like yad if that's too limiting. I think you have to understand the shell scripting anyway, and maybe you already do. Prototyping using something like this might be a good idea anyway, even if you want to dive in deep with more powerful tools like pyQt.

                  Once I did a GUI app using gtk-server, with a bash script talking to a database, and it works, but for it to be polished I'd have to learn the depths of GTK layout, and it would be very similar code in another language such as python.
                  Regards, John Little

                  Comment

                  Working...
                  X