How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask ATLPROG Your Own Question
ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7260
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now

Hi i wanted to know how i could run a class by clicking on

Customer Question

Hi i wanted to know how i could run a class by clicking on an item in a menubar??
My code is as shown below but doesnt seem to work?! :(

import sys
from PyQt4 import QtCore,QtGui
import sqlite3 as lite

class AddTest(QtGui.QMainWindow):
def __init__(self, parent=None):
super(AddTest, self).__init__(parent)
self.QuestionList = QtGui.QListWidget()
self.QuestionView = QtGui.QTextBrowser()

self.mainSplitter = QtGui.QSplitter(QtCore.Qt.Vertical)
self.mainSplitter.addWidget(self.QuestionList)
self.mainSplitter.addWidget(self.QuestionView)
self.setCentralWidget(self.mainSplitter)

self.mainSplitter.setStretchFactor(0, 1)
self.mainSplitter.setStretchFactor(1, 3)

self.createMenusAndToolbars()

settings = QtCore.QSettings()
self.restoreGeometry(settings.value("MainWindow/Geometry",
QtCore.QByteArray()))
self.restoreState(settings.value("MainWindow/State",
QtCore.QByteArray()))
self.mainSplitter.restoreState(settings.value("MainSplitter",
QtCore.QByteArray()))

status = self.statusBar()
status.setSizeGripEnabled(False)
status.showMessage("Ready", 5000)
self.setWindowTitle("Add Test")

def createMenusAndToolbars(self):
fileMenu = self.menuBar().addMenu("&File")
fileMenu.addAction('Save As...', self.save)
fileMenu.addAction('Quit', self.Quit)

editMenu = self.menuBar().addMenu("&Edit")
editMenu.addAction('Add...', self.addQuestion)
editMenu.addAction('Edit...', self.EditQuestion)
editMenu.addAction('Remove', self.RemoveQuestion)

def closeEvent(self, event):
if self.okToContinue():
settings = QtCore.QSettings()
settings.setValue("MainWindow/Geometry", self.saveGeometry())
settings.setValue("MainWindow/State", self.saveState())
settings.setValue("MainSplitter", self.mainSplitter.saveState())
else:
event.ignore()

def okToContinue(self):
return True

def addQuestion(self):
AddTQuestions()


def RemoveQuestion(self):
for item in self.QuestionList.selectedItems():
self.QuestionList.takeItem(self.QuestionList.row(item))

def EditQuestion(self):
print("Edit")

def Quit(self):
self.close()

def save(self):
datalist = [('Calculator', [0, 'Yes', 'No']),
('Assign to Students', [0, 'Yes', 'No']),
('Timelimit', [0, 'Seconds', 'Minutes']),
('TimeLimit', 10),
]
print("result:", fedit(datalist, title="Add Test", comment="Please fill in the fields below"))


def generateData(self):
try:
con = lite.connect('Records.db')
with con:
cur = con.cursor()
cur.execute("SELECT Question FROM Questions")
rows = cur.fetchall()
if len(rows)==0:
self.QuestionList.addItem("None")
else:
for row in rows:
Question = str(row)
Question = Question[2:-3]
self.QuestionList.addItem("{}".format(Question))
except:
self.QuestionList.addItem("None")

Item = self.QuestionList.currentItem()
Item = str(Item)
self.QuestionView.setHtml(Item)

class AddTQuestions(QtGui.QMainWindow):
def __init__(self, parent=None):
super(AddTQuestions, self).__init__(parent)
self.welcomelbl = QtGui.QLabel('Welcome')
layout = QVBoxLayout()
layout.addWidget(self.welcomelbl)
self.setLayout(layout)
Submitted: 3 years ago.
Category: Programming
Expert:  adamd-mod replied 3 years ago.

Hello there,

I've been working hard to find a Professional to assist you with your question, but sometimes finding the right Professional can take a little longer than expected.

I wonder whether you're ok with continuing to wait for an answer. If you are, please let me know and I will continue my search. If not, feel free to let me know and I will cancel this question for you.

Please note, I am just a moderator for this category, I can only try and find experts to help, I can't answer the question itself.

Thank you!

Adam