Update MgrCalibreDB.py and UI.py

This commit is contained in:
2024-12-08 01:06:45 +09:00
parent 1e06484b4e
commit 1c840a1e25
2 changed files with 45 additions and 19 deletions

View File

@@ -49,6 +49,21 @@ class MgrCalibreDB:
return listRet return listRet
def GetBookListforUI_ArcList(self):
if None == self.cursor:
return None
try:
strSQL = f"Select title, path from books;"
self.cursor.execute(strSQL)
listRet = self.cursor.fetchall()
except sqlite3.Error as e:
listRet = []
print(f"SQLite Erro occurred: {e}")
return listRet
def UpdateTableValue(self,Table, nID, ColName, Value): def UpdateTableValue(self,Table, nID, ColName, Value):
if None == self.cursor: if None == self.cursor:
return return
@@ -71,29 +86,29 @@ class MgrCalibreDB:
strSQL = f"SELECT MAX(id) FROM \'{strTableName}\';" strSQL = f"SELECT MAX(id) FROM \'{strTableName}\';"
self.cursor.execute(strSQL) self.cursor.execute(strSQL)
nMaxID = self.cursor.fetchone()[0] nMaxID = self.cursor.fetchone()[0]
nMaxID += 1. nMaxID += 1
strAuthorSort = strAuthor.replace(" ", ",") strAuthorSort = strAuthor.replace(" ", ",")
strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strAuthor}\',\'{strAuthorSort}\', \'\');" strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strAuthor}\',\'{strAuthorSort}\', \'\');"
self.cursor.execute(strSQL) self.cursor.execute(strSQL)
self.conn.commit() self.conn.commit()
def InsertTag(self, tag): def InsertTag(self, tag):
if None == self.cursor: if None == self.cursor:
return return
if True == util.IsEmptyStr(tag): if True == util.IsEmptyStr(tag):
return return
strTableName = "tags" strTableName = "tags"
strSQL = f"SELECT MAX(id) FROM \'{strTableName}\';" strSQL = f"SELECT MAX(id) FROM \'{strTableName}\';"
self.cursor.execute(strSQL) self.cursor.execute(strSQL)
nMaxID = self.cursor.fetchone()[0] nMaxID = self.cursor.fetchone()[0]
nMaxID += 1. nMaxID += 1.
strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strAuthor}\', \'\');" strSQL = f"INSERT OR IGNORE INTO \'{strTableName}\' VALUES ({nMaxID}, \'{strAuthor}\', \'\');"
self.cursor.execute(strSQL) self.cursor.execute(strSQL)
self.conn.commit() self.conn.commit()
def main(): def main():
db = MgrCalibreDB("/Users/minarinari/캘리버 서재/metadata.db") db = MgrCalibreDB("/Users/minarinari/캘리버 서재/metadata.db")

19
UI.py
View File

@@ -1,6 +1,8 @@
import sys import sys
import os import os
import UtilPack as util import UtilPack as util
import MgrCalibreDB as calDB
import MgrCalibreLibs as calLib
from io import BytesIO from io import BytesIO
@@ -21,6 +23,7 @@ class MyApp(QMainWindow):
self.saveINI() self.saveINI()
event.accept() event.accept()
def resizeEvent(self, event): def resizeEvent(self, event):
self.GetFitSize(self.label_Image.size()) self.GetFitSize(self.label_Image.size())
print( self.label_Image.size() ) print( self.label_Image.size() )
@@ -107,6 +110,7 @@ class MyApp(QMainWindow):
return layout return layout
def GetFitSize(self, szTarget): def GetFitSize(self, szTarget):
szDesktop = self.screen().size() szDesktop = self.screen().size()
szWindow = self.size() szWindow = self.size()
@@ -115,8 +119,6 @@ class MyApp(QMainWindow):
nTrgWidth = szWindow.width() - ( self.list_ArcList.width() + self.list_Items.width() ) nTrgWidth = szWindow.width() - ( self.list_ArcList.width() + self.list_Items.width() )
def on_click_SrcAdd(self): def on_click_SrcAdd(self):
# 폴더 선택 창을 띄움 # 폴더 선택 창을 띄움
folder_path = QFileDialog.getExistingDirectory(self, '폴더 선택', '') folder_path = QFileDialog.getExistingDirectory(self, '폴더 선택', '')
@@ -163,8 +165,16 @@ class MyApp(QMainWindow):
ItemName = os.path.join(FolderName, filename) ItemName = os.path.join(FolderName, filename)
item = QListWidgetItem(ItemName) item = QListWidgetItem(ItemName)
# 전체 경로를 따로 저장 # 전체 경로를 따로 저장
item.setData(Qt.UserRole, pathFile) #item.setData(Qt.UserRole, pathFile)
self.list_ArcList.addItem(item) #self.list_ArcList.addItem(item)
print(pathFile)
db = calDB.MgrCalibreDB(pathFile)
db.init()
listBooks = db.GetBookListforUI_ArcList()
for book in listBooks:
item.setData(Qt.UserRole, book[1])
self.list_ArcList.addItem(book[0])
# 이미지 파일이 들어있다면... # 이미지 파일이 들어있다면...
if fileExt.lower() in [".jpg", ".webp", ".jpeg", ".png", ".gif"]: if fileExt.lower() in [".jpg", ".webp", ".jpeg", ".png", ".gif"]:
@@ -205,6 +215,7 @@ class MyApp(QMainWindow):
for item in items: for item in items:
pathTarget = item.data(Qt.UserRole) pathTarget = item.data(Qt.UserRole)
print(f"arc : {pathTarget}")
if False == os.path.exists(pathTarget): if False == os.path.exists(pathTarget):
return return