Exemplo n.º 1
0
class Soletrando(QtGui.QMainWindow):
  def __init__(self):
    QtGui.QMainWindow.__init__(self)
    self.ui = Ui_Soletrando()
    self.ui.setupUi(self)
    self.ui.pushButton.clicked.connect(self.soletrar)
  sorteadas = []
  sx = 0;
  def soletrar(self):
     f = open('palavras.txt','r')
     ler = f.readlines()
     my_array = []
     x = 0
     b = 0
     total = 0

     
     combo = self.ui.comboBox.currentText()
     for item in ler:
       i = item.split(';')
       i[1] = i[1].replace('\n','')
       my_array.insert(x,[i[0],i[1]])
       x = x + 1       
       if(i[1] == self.ui.comboBox.currentText()):
         b = 1
         total = total + 1
     f.close()
     m = random.randint(0,x-1)
     v = 0
     total2 = 0
     
     for ite in self.sorteadas:
       if(ite[1] == self.ui.comboBox.currentText()):
         total2 = total2  + 1
     if(b == 1):
       v = 0
       t = 0
       while(v == 0):
         tem = 1
         for ite in self.sorteadas:
           print my_array[m][0] not in ite
           print ite
           if(my_array[m][0] in ite):
             tem = 0
         print total2 , ' - ', total
         if(my_array[m][1] == self.ui.comboBox.currentText() and tem == 1 and total2 < total):
           self.ui.textoBox.setPlainText(my_array[m][0])
           v = 1;
           self.sorteadas.insert(self.sx,[my_array[m][0],my_array[m][1]])
           self.sx = self.sx + 1
         elif(total2 >= total):
           self.ui.textoBox.setPlainText("Nao existe mais palavras para esse nivel")
           break
         else:
           m = random.randint(0,x-1)
         
     else:
        self.ui.textoBox.setPlainText("Nao existe palavras para esse nivel")
     print self.sorteadas
Exemplo n.º 2
0
class Soletrando(QtGui.QDialog):
  def __init__(self, parent=None):
    super(Soletrando, self).__init__(parent)
    self.ui = Ui_Soletrando()
    self.ui.setupUi(self)
    self.ui.pushButton.clicked.connect(self.soletrar)
    self.ui.spinBox.valueChanged.connect(self.aumentar)
  sorteadas = []
  sx = 0;



  def aumentar(self):
    font = QtGui.QFont()
    font.setPointSize(self.ui.spinBox.value())
    self.ui.textoBox.setFont(font)
  def soletrar(self):
     f = open('palavras.txt','r')
     ler = f.readlines()
     my_array = []
     x = 0
     b = 0
     total = 0
     if(len(self.sorteadas) > 0):
       tablemodel = MyTableModel(self.sorteadas, self)
       self.ui.tableView.setModel(tablemodel)
     else:
       self.ui.tableView.clearSpans()
     
     combo = self.ui.comboBox.currentText()
     if(len(ler) > 0):
       for item in ler:
         i = item.split(';')
         i[1] = i[1].replace('\n','')
         my_array.insert(x,[i[0],i[1]])
         x = x + 1       
         if(i[1] == self.ui.comboBox.currentText()):
           b = 1
           total = total + 1
       f.close()
       m = random.randint(0,x-1)
       v = 0
       total2 = 0
       
       for ite in self.sorteadas:
         if(ite[1] == self.ui.comboBox.currentText()):
           total2 = total2  + 1
       if(b == 1):
         v = 0
         t = 0
         while(v == 0):
           tem = 1
           for ite in self.sorteadas:
             if(my_array[m][0] in ite):
               tem = 0

           if(my_array[m][1] == self.ui.comboBox.currentText() and tem == 1 and total2 < total):
             self.ui.textoBox.setPlainText(my_array[m][0])
             v = 1;
             self.sorteadas.insert(self.sx,[my_array[m][0],my_array[m][1]])
             self.sx = self.sx + 1
           elif(total2 >= total):
             self.ui.textoBox.setPlainText("Nao existe mais palavras para esse nivel")
             break
           else:
             m = random.randint(0,x-1)
           
       else:
          self.ui.textoBox.setPlainText("Nao existe palavras para esse nivel")
     else:
       self.ui.textoBox.setPlainText("Nao existe palavras cadastradas")