Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Please Help
Forum Updated to NodeBB v4.3 + New Features

Please Help

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 274 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Whambham100
    wrote on last edited by
    #1

    I am attempting to create a basic shopping cart package for my university course and have used the following code:

    import sys
    import os

    pip install PySide2

    from PySide2 import QtGui, QtWidgets, QtCore

    from PySide2.QtCore import *
    from PySide2.QtWidgets import *
    from PySide2.QtUiTools import *

    cartItems = []

    cartAnnualTotal = 8250.00

    IntAnnualPrices = {'Art Intervention': 200.00,'Behaviour Intervention': 187.50,'Collaborative Problem Solving': 104.00,'Learning Mentor': 13.00,'Self Regulation': 1040.00,'1 to 1 Tuition': 360.00,'Outdoor Learning': 216.00,'Parental Engagement': 350.00,'Phonics': 120.00,'Reading Comprehension': 120.00,'Reduced Class Sizes': 0.00,'Social and Emotional Learning': 1040.00,'Summer School': 120.00,'Teaching Assistant Intervention': 2200.00,'Youth Drugs and Alcohol YDAP': 2160.00,'Youth Offending Services': 2160.00,'Educational Psychologist': 5400.00,'Education 5 Attendance Support': 225.00,'Early Help Worker': 1968.33,'Family Liason Officer': 350.00,'Century Online Learning Platform': 400.00,'Lexonic Literacy Support': 62.50,'Chances Football Coaching': 360.00,'Cahms Support': 420.00,'CYPS': 420.00,'EHCP Application': 5500.00,'Exam Access Arrangement Testing': 60.00,'Anger Management': 13.00}

    IntTermPrices = {'Art Intervention': 66.67,'Behaviour Intervention': 62.50,'Collaborative Problem Solving': 34.67,'Learning Mentor': 4.33,'Self Regulation': 346.67,'1 to 1 Tuition': 120.00,'Outdoor Learning': 72.00,'Parental Engagement': 116.67,'Phonics': 40.00,'Reading Comprehension': 40.00,'Reduced Class Sizes': 0.00,'Social and Emotional Learning': 346.67,'Summer School': 40.00,'Teaching Assistant Intervention': 733.33,'Youth Drugs and Alcohol YDAP': 720.00,'Youth Offending Services': 720.00,'Educational Psychologist': 1800.00,'Education 5 Attendance Support': 75.00,'Early Help Worker': 656.11,'Family Liason Officer': 116.67,'Century Online Learning Platform': 133.33,'Lexonic Literacy Support': 20.83,'Chances Football Coaching': 120.00,'Cahms Support': 140.00,'CYPS': 140.00,'EHCP Application': 1800.00,'Exam Access Arrangement Testing': 20.00,'Anger Management': 4.33}

    class Form(QObject):
    def init(self, ui_file, parent = None):
    super(Form, self).init(parent)

        #Load UI File
        ui_file = QFile(ui_file)
        ui_file.open(QFile.ReadOnly)
    
        loader = QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()
    
        #Initialise User Interface Items
        cmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList')
        btnAdd = self.window.findChild(QPushButton, 'btnAdd')
    
        cmbInterventionsList.addItem("Art Intervention")
        cmbInterventionsList.addItem("Behaviour Intervention")
        cmbInterventionsList.addItem("Collaborative Problem Solving")
        cmbInterventionsList.addItem("Learning Mentor")
        cmbInterventionsList.addItem("Self Regulation")
        cmbInterventionsList.addItem("1 to 1 Tuition")
        cmbInterventionsList.addItem("Outdoor Learning")
        cmbInterventionsList.addItem("Parental Engagement")
        cmbInterventionsList.addItem("Phonics")
        cmbInterventionsList.addItem("Reading Comprehension")
        cmbInterventionsList.addItem("Reduced Class Sizes")
        cmbInterventionsList.addItem("Social and Emotional Learning")
        cmbInterventionsList.addItem("Summer School")
        cmbInterventionsList.addItem("Teaching Assistant Intervention")
        cmbInterventionsList.addItem("Youth Drugs and Alcohol YDAP")
        cmbInterventionsList.addItem("Youth Offending Services")
        cmbInterventionsList.addItem("Educational Psychologist")
        cmbInterventionsList.addItem("Education 5 Attendance Support")
        cmbInterventionsList.addItem("Early Help Worker")
        cmbInterventionsList.addItem("Family Liason Officer")
        cmbInterventionsList.addItem("Century Online Learning Platform")
        cmbInterventionsList.addItem("Lexonic Literacy Support")
        cmbInterventionsList.addItem("Chances Football Coaching")
        cmbInterventionsList.addItem("Cahms Support")
        cmbInterventionsList.addItem("CYPS")
        cmbInterventionsList.addItem("EHCP Application")
        cmbInterventionsList.addItem("Exam Access Arrangement Testing")
        cmbInterventionsList.addItem("Anger Management")
    
        #Make Click on Button
        btnAdd.clicked.connect(self.updateInt)
    
        self.window.show()
    

    def addIntervention(self, itemName):
    # Add the current item in combo box to a list and list view
    cmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList')
    lstViewInterventions = self.window.findChild(QListWidget, 'lstViewInterventions')

    lstViewInterntions.addItem(cmbInterventionsList.currentText)
    cartItems.append(itemName)
    

    def updateInt(self):
    global cartItems, cartAnnualTotal, IntAnnualPrices

    cmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList')
    lblSummary = self.window.findChild(QLabel, 'lblSummary')
    lblTotal = self.window.findChild(QLabel, 'lblTotal')
    
        #Add Button Click
    self.addIntervention(cmbInterventionsList.currentText())
    
        #Update Cart Summary
    cartSummary = dict((item, cartItems.count(item)) for item in cartItems)
    lblSummary.setText(str(cartSummary))
    
    #Loop Through All Items in Cart, Select Prices and Add to Total
    for item in cartItems:
        itemPrice = IntAnnualPrices.get(item, 0)
        cartAnnualTotal += itemPrice
    
    lblTotal.setText(str(cartAnnualTotal))
    cartAnnualTotal = 0
    

    if name == 'main':
    app = QApplication(sys.argv)

    # Load UI
    form = Form('CM.ui')
    
    sys.exit(app.exec_())
    

    however the section of code that stats if name

    crashes in google collab and restarts the Kernel

    Can anyone help me fix this issue and or explain this?

    much appreciated

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Google colab ? I am currently not sure you can run a Qt application as the one you build in that environment.

      The crash logs shows the usual error with regard to the xcb plugin that is not loading which I can understand since there's no X server involved in Google Colab.

      Since you are using Google Collab, shouldn't you rather use ipywidgets ?

      On a side note, please use coding tags when posting code to make it readable.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Google colab ? I am currently not sure you can run a Qt application as the one you build in that environment.

        The crash logs shows the usual error with regard to the xcb plugin that is not loading which I can understand since there's no X server involved in Google Colab.

        Since you are using Google Collab, shouldn't you rather use ipywidgets ?

        On a side note, please use coding tags when posting code to make it readable.

        W Offline
        W Offline
        Whambham100
        wrote on last edited by
        #3

        @SGaist thank you for the reply, so how would I best run the QT application?

        SGaistS 1 Reply Last reply
        0
        • W Whambham100

          @SGaist thank you for the reply, so how would I best run the QT application?

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The most simple would be to do that on your own machine using a virtual environment. You can use either conda or pip's virtualenv. You also might want to move to PySide6.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved