1

I've ran into a problem with using PyQT as a GUI with python. I am making a simple spelling aid for my aunt who has severe cerebral palsy, as part of a school project. I want to run a loop that cycles through the spelling options and then updates the HTML in the GUI. Unfortunately when I launched the GUI it stops all other code, due to app.exec_(). I was wondering is there anyway to stop this happening. I've added a version of my code. With all the spelling procedures and grammar corrections my entire code would be too long but, I should be able to implement the solution in the rest of my code, if I can get this version working.

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import time as t

var = "A"
settings = "option"
section1 = "highlight"
section2 = "option"
section3 = "option"
numbers = "option"
symbols = "option"
quickCom = "option"
quiting = "option"
sentence = "Hello"

def main():
    changeVar()
    reloading()
    web.reload()

def changeVar():
    global var
    var = "B"
    return var

def reloading():
    web.setHtml('''<html>
<head>
<title>Input Capture</title>
<style>
div {
   border: 1px solid Black;
}
body {
  margin: 5px;
  padding: 5px;
  width: 100%;
  font: 140% 'PT Sans', 'Verdana', Helvetica, Arial, sans-serif;
}
#navigation {
  float: left;
  width: 20%;
  font-family: Verdana;
  margin: 5px;
}
#content {
  float: left;
  font-size: 1000%;
  align: center;
  margin: 5px;
  padding: 20px 30px 30px 30px;
  border: none;
}

#footer {
  float: bottom;
  clear: both;
  width: 100%;
}
.highlight {
  margin: 5px;
  padding: 3px;
  weight: bold;
  color: white;
  background-color: black;
}
.option {
  margin: 5px;
  padding: 3px;
}

#inputSoFar {
  weight: bold;
  color: white;
  background-color: black;
  padding: 10px;
  font-size: 200%;
}
</style>
  <head>
  <body>
    <div border="">
      <div id="navigation">
        <div class= ''' + settings +'''>Settings</div>
        <div class=''' + section1 + '''>A-I</div>
        <div class=''' + section2 + '''>J-Q</div>
        <div class=''' + section3 + '''>R-Z</div>
        <div class=''' + numbers + '''>0-9</div>
        <div class=''' + symbols + '''>Symbols</div>
        <div class=''' + quickCom + '''>Quick Com</div>
        <div class=''' + quiting + '''>Quit</div>
      </div>
      <div id="content">
         ''' + var + '''
      </div>
    </div>
    <div id="footer">
      <div id="inputSoFar">''' + sentence+ '''</div>
      </div>
  </body>
</html> ''', QUrl('http://localhost'))

app = QApplication(sys.argv)

web = QWebView()
reloading()
web.show()
app.exec_()
main()

The idea behind the project, is that as my aunt goes through the options the variables will change and the HTML will be updated, but it's not doing that yet. Thanks for any advice you can offer

Conor
  • 31
  • 1
  • 1
    See http://stackoverflow.com/questions/23142719/pyqt-app-exec-stops-all-following-code-from-running – Alex Martelli Dec 22 '14 at 18:42
  • 1
    What do you mean by "a loop that cycles through the spelling options"? I see main starts with var=A, reloads the HTML, then sets var to B, then reloads. Is this meant to be a loop? And if so, how fast is it suppose to "cycle through the spelling options". Take a look at the link that Alex posted in the previous comment, and add details to your question if still having trouble. – Oliver Dec 24 '14 at 05:28
  • What about [multithreading](http://stackoverflow.com/questions/9957195/updating-gui-elements-in-multithreaded-pyqt) and spell checking in the background? It is a bit of work but can be done and I wish you luck with your project. – NoDataDumpNoContribution Jan 05 '15 at 13:35

0 Answers0