def setupList(self):
     self.newConnector = SQLiteConnector(self.CURR_DATABASE)
     if not self.newConnector.connection:
         QMessageBox.critical(self, "Error", u'Cannot access the Database')
     else:
         nameQuery = self.newConnector.getNameData(self.CURR_DATABASE)
         self.nameList = []
         while nameQuery.next():
             self.nameList.append(nameQuery.value(0).toString())
         self.ui.cocktailListWidget.addItems(self.nameList)
         self.completeListWidget = QListWidget()
         self.completeListWidget.addItems(self.nameList)
Пример #2
0
 def signUp(self):
     print('btn clck')
     username = str(self.ui.txtUsername.text())
     email = str(self.ui.txtEmail.text())
     stmt = 'insert into users(username, email) values (?, ?)'
     sqlt = SQLiteConnector(self)
     if (sqlt.executeOne(stmt, [username, email])):
         self.lyrikerWindow.hide()
         # self.qMainWindow.hide()
         MainWindow(self.lyrikerWindow, True)
         #self.close()
         #self.Lyriker.close()
         #self.app.exit()
         #QtWidgets.qApp.quit()
         #MainWindow()
     else:
         print('error')
   def openDataBase(self, filename = None):
      self.currFilename = filename
      self.sqliteConnector = SQLiteConnector(self.currFilename)
      if not self.sqliteConnector.connection:
         QMessageBox.critical(self,
               "Error",
               u'The file cannot be opened')

      else:
         self.showTableNames()
Пример #4
0
 def saveToSearchHistory(self, title, artist):
     sqlt = SQLiteConnector(self)
     stmt = '''select * from searchhistory where songtitle = ? and artist = ?'''
     data = sqlt.readDB(stmt, [title, artist])
     if (data == False or data == []):
         stmt2 = '''insert into searchhistory(songtitle, artist, frequency) values (?, ?, ?)'''
         sqlt.executeOne(stmt2, [title, artist, 1])
     else:
         frequency = int(data[0][2]) + 1
         stmt2 = '''update searchhistory set frequency = ? where songtitle = ? and artist = ?'''
         sqlt.executeOne(stmt2, [frequency, title, artist])
Пример #5
0
    def calcFavArtists(self):
        sqlt = SQLiteConnector(self.aContext)
        stmt = '''select * from searchhistory'''
        history = sqlt.readDB(stmt, [])
        print(history)
        searchedArtists = []
        searchedArtistsFrequency = []
        for song in history:
            try:
                ind = searchedArtists.index(song[1])
                searchedArtistsFrequency[ind] = searchedArtistsFrequency + song[2]
            except:
                searchedArtists.append(song[1])
                searchedArtistsFrequency.append(song[2])
        favArtists = []
        for i in range(6):
            if(len(searchedArtistsFrequency)==i):
                break
            ind = searchedArtistsFrequency.index(max(searchedArtistsFrequency))
            favArtists.append(searchedArtists[ind])
            searchedArtistsFrequency[ind] = 0

        return favArtists
class ControlCocktail(QMainWindow):
    def __init__(self):
        super(ControlCocktail, self).__init__()
        self.ui = Ui_RecipesWindow()
        self.ui.setupUi(self)
        self.show()

        #Basic GUI done, setting up the ListWidget
        self.CURR_DATABASE = "cocktails"
        self.setupSignals()
        self.setupList()

    def searchCocktail(self, text):
        print text
        items = self.completeListWidget.findItems(text, Qt.MatchContains)
        tempItemList = []
        if len(items) > 0 and text:
            for item in items:
                tempItemList.append(item.text())
            self.ui.cocktailListWidget.clear()
            self.ui.cocktailListWidget.addItems(tempItemList)
            self.ui.ingredientsLabel.setText("")
            self.ui.preparationLabel.setText("")
        else:
            self.ui.cocktailListWidget.clear()
            self.ui.cocktailListWidget.addItems(self.nameList)

    def setupSignals(self):
        self.ui.lineEdit.textChanged.connect(self.searchCocktail)
        self.ui.cocktailListWidget.currentItemChanged.connect(
            self.showTotalData)
        self.ui.cocktailListWidget.itemActivated.connect(self.showTotalData)
        self.ui.cocktailListWidget.itemChanged.connect(self.showTotalData)
        self.ui.cocktailListWidget.itemClicked.connect(self.showTotalData)

    def setupList(self):
        self.newConnector = SQLiteConnector(self.CURR_DATABASE)
        if not self.newConnector.connection:
            QMessageBox.critical(self, "Error", u'Cannot access the Database')
        else:
            nameQuery = self.newConnector.getNameData(self.CURR_DATABASE)
            self.nameList = []
            while nameQuery.next():
                self.nameList.append(nameQuery.value(0).toString())
            self.ui.cocktailListWidget.addItems(self.nameList)
            self.completeListWidget = QListWidget()
            self.completeListWidget.addItems(self.nameList)

    def showTotalData(self, listWidgetItem):
        try:
            currText = listWidgetItem.text()
            currIngredients = self.newConnector.getIngredients(
                self.CURR_DATABASE, currText)
            currPreparation = self.newConnector.getPreparation(
                self.CURR_DATABASE, currText)
            self.ui.titleLabel.setText(currText)
            self.ui.ingredientsLabel.setText(currIngredients)
            self.ui.preparationLabel.setText(currPreparation)
        except:
            self.ui.ingredientsLabel.setText("")
            self.ui.preparationLabel.setText("")
class SQLiteHandler(QMainWindow):

   def __init__(self):
      super(SQLiteHandler, self).__init__()
      self.ui = Ui_MainWindow()
      self.ui.setupUi(self)
      self.show()

      self.openDataBase("cocktails")
      #self.getDataBase()




   def getDataBase(self):
      filePath = QFileDialog.getOpenFileName(filter = u'SQLite File (*.db)')
      if filePath:
         self.openDataBase(filePath)

   def openDataBase(self, filename = None):
      self.currFilename = filename
      self.sqliteConnector = SQLiteConnector(self.currFilename)
      if not self.sqliteConnector.connection:
         QMessageBox.critical(self,
               "Error",
               u'The file cannot be opened')

      else:
         self.showTableNames()

   def showTableNames(self):
      tables_names = self.sqliteConnector.getTableNames()
      if len(tables_names) > 0:
         tempTablesDialog, output = QInputDialog.getItem(self,
               "Tables available in " + self.currFilename,
               "",
               tables_names,
               current = 0,
               editable = False) 

         if output:
            self.openTable(tempTablesDialog)

      else:
         QMessageBox.critical(self, "Error", u'There are no tables registered in ' + self.currFilename)

   def openTable(self, tableName):
      #Get Header Names
      self.columnNames = self.sqliteConnector.getColumnNames(tableName)
      if len(self.columnNames) > 0:
         self.setupTableHeaders()
         self.ui.tableWidget.clearContents()

         #Get query data
         searchResult = self.sqliteConnector.getCompleteData(tableName)
         row = 0
         while searchResult.next():
            self.ui.tableWidget.setRowCount(row + 1)
            for column in range(len(self.columnNames)):
               temp = searchResult.value(column).toString()
               item = QTableWidgetItem(temp)
               self.ui.tableWidget.setItem(row, column, item)
            row += 1
         self.ui.tableWidget.setRowCount(row + 1)






   def setupTableHeaders(self):
        self.ui.tableWidget.setColumnCount(len(self.columnNames))
        self.ui.tableWidget.setHorizontalHeaderLabels(self.columnNames)
        currTableHeaders = self.ui.tableWidget.horizontalHeader()
        currTableHeaders.setResizeMode(QHeaderView.Stretch)        
Пример #8
0
	def __init__(self):
		self.conn = SQLiteConnector.getInstance()
		self.cursor = self.conn.cursor()
		self.initSchema()
Пример #9
0
 def loadUi(self):
     sqlt = SQLiteConnector(self)
     if (sqlt.checkDB()):
         MainWindow(self.lyrikerWindow, False)
     else:
         SignUpWindow(self.lyrikerWindow)