kindle manager
This commit is contained in:
80
kmanapp.py
80
kmanapp.py
@@ -9,11 +9,17 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
import operator
|
||||
from time import sleep
|
||||
import pandas as pd
|
||||
#import pandas as pd
|
||||
from mtable import mTable
|
||||
import threading
|
||||
|
||||
from PySide2.QtWidgets import (QMainWindow, QApplication, QLabel, QAbstractItemView, QHeaderView)
|
||||
#if hasattr(sys, 'frozen'):
|
||||
# os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']
|
||||
|
||||
from PySide2.QtWidgets import (QMainWindow, QApplication, QMessageBox,
|
||||
QFileDialog, QLabel, QAbstractItemView, QHeaderView)
|
||||
from PySide2.QtCore import (QAbstractTableModel, Signal, QSize, QTimer, Qt)
|
||||
from PySide2.QtGui import (QPalette, QStandardItemModel, QStandardItem, QIcon)
|
||||
|
||||
@@ -81,6 +87,10 @@ class kmanWindow(QMainWindow):
|
||||
self.km = kMan()
|
||||
self.spide = bookInfoSpide()
|
||||
|
||||
### in order to smaller the package,
|
||||
### substitute pandas table with mTable
|
||||
self.mt = mTable()
|
||||
|
||||
# initial check order:
|
||||
# 1. backup file bk.data ->
|
||||
# 2. kindle(My Clippings.txt) ->
|
||||
@@ -89,9 +99,8 @@ class kmanWindow(QMainWindow):
|
||||
if os.path.exists(BACKUPNOTEFN) and os.path.exists(BACKUPWORDFN):
|
||||
self.books_data = self.km.json2dict(BACKUPNOTEFN)
|
||||
self.words_data = self.km.json2dict(BACKUPWORDFN)
|
||||
if (len(self.books_data)*len(self.words_data[0]))>=1:
|
||||
self.books_data = self.km.json2dict(BACKUPNOTEFN)
|
||||
self.words_data = self.km.json2dict(BACKUPWORDFN)
|
||||
if self.books_data and len(self.books_data) >=1 and \
|
||||
self.words_data and len(self.words_data[0])>=1:
|
||||
flg = 1
|
||||
|
||||
if not flg:
|
||||
@@ -163,6 +172,7 @@ class kmanWindow(QMainWindow):
|
||||
ui.tablemodel = nTableModel(data)
|
||||
ui.tableView.verticalHeader().hide()
|
||||
ui.tableView.setModel(self.ui.tablemodel)
|
||||
ui.tableView.setSortingEnabled(True)
|
||||
|
||||
self.ui.textEdit.installEventFilter(self)
|
||||
|
||||
@@ -319,12 +329,17 @@ class kmanWindow(QMainWindow):
|
||||
|
||||
def convert_to_panda(self, mlist, tp=0):
|
||||
if tp==0:
|
||||
pdframe = pd.DataFrame(mlist, \
|
||||
#### XXX remove pandas
|
||||
#pdframe = pd.DataFrame(mlist, \
|
||||
# columns = ['Type','Bookname','Author','Position','Date','Content'])
|
||||
self.mt.dataframe(mlist, \
|
||||
columns = ['Type','Bookname','Author','Position','Date','Content'])
|
||||
else:
|
||||
pdframe = pd.DataFrame(mlist, \
|
||||
#pdframe = pd.DataFrame(mlist, \
|
||||
# columns = ['Word','Bookname','Author','Category'])
|
||||
self.mt.dataframe(mlist, \
|
||||
columns = ['Word','Bookname','Author','Category'])
|
||||
return pdframe
|
||||
return self.mt
|
||||
|
||||
def tabledata_update_slot(self, s):
|
||||
print('call tabledata_update_slot() {}'.format(s))
|
||||
@@ -471,8 +486,8 @@ class kmanWindow(QMainWindow):
|
||||
self.messagebox(ico=2, info='\n\n kindle is not connected')
|
||||
return 0
|
||||
|
||||
self.books_data = self.km.import_clips(fp+'documents/'+CLIPFN)
|
||||
self.words_data = self.km.import_words(fp+'system/vocabulary/'+WORDFN)
|
||||
self.books_data = self.km.import_clips(os.path.join(fp,'documents',CLIPFN))
|
||||
self.words_data = self.km.import_words(os.path.join(fp,'system','vocabulary',WORDFN))
|
||||
[self.filter_books, self.filter_list] = self.km.filter_clips(self.books_data)
|
||||
self.filter_wordlist = self.km.filter_words(self.words_data)
|
||||
|
||||
@@ -676,6 +691,8 @@ class kmanWindow(QMainWindow):
|
||||
# backup file when kman closed
|
||||
# so we can read backup file when kman start
|
||||
def closeEvent(self, e):
|
||||
if not os.path.exists(BACKUPFOLDER): os.mkdir(BACKUPFOLDER)
|
||||
|
||||
with open(BACKUPNOTEFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||
fw.write(self.km.dict2json(self.books_data))
|
||||
with open(BACKUPWORDFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||
@@ -711,27 +728,60 @@ class nTableModel(QAbstractTableModel):
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.DisplayRole:
|
||||
value = self._data.iloc[index.row(), index.column()]
|
||||
#### XXX remove pandas
|
||||
#value = self._data.iloc[index.row(), index.column()]
|
||||
value = self._data.get_iat(index.row(), index.column())
|
||||
self.tabledata_update[str].emit('{} {}'.format(index.row(),index.column()))
|
||||
return str(value)
|
||||
|
||||
def rowCount(self, index):
|
||||
return self._data.shape[0]
|
||||
#### XXX remove pandas
|
||||
#return self._data.shape[1]
|
||||
return self._data.get_num_rows()
|
||||
|
||||
def columnCount(self, index):
|
||||
return self._data.shape[1]
|
||||
#### XXX remove pandas
|
||||
#return self._data.shape[1]
|
||||
return self._data.get_num_columns()
|
||||
|
||||
def headerData(self, section, orientation, role):
|
||||
# section is the index of the column/row.
|
||||
if role == Qt.DisplayRole:
|
||||
if orientation == Qt.Horizontal:
|
||||
return str(self._data.columns[section])
|
||||
#### XXX remove pandas
|
||||
#return str(self._data.columns[section])
|
||||
return str(self._data.get_columns()[section])
|
||||
|
||||
if orientation == Qt.Vertical:
|
||||
return str(self._data.index[section])
|
||||
#### XXX remove pandas
|
||||
#return str(self._data.index[section])
|
||||
return str(self._data.get_index()[section])
|
||||
|
||||
# cheer!!!
|
||||
def sort(self, column, order):
|
||||
"""Sort table by given column number.
|
||||
"""
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._data.set_data(sorted(self._data.get_data(), key=operator.itemgetter(column)))
|
||||
if order == Qt.DescendingOrder:
|
||||
self._data.reverse()
|
||||
|
||||
self.layoutChanged.emit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print('sys.path[0]', sys.path[0])
|
||||
print('sys.argv[0]', sys.argv[0])
|
||||
print('os.path.realpath(sys.executable)', os.path.realpath(sys.executable))
|
||||
print('os.path.realpath(sys.argv[0]))', os.path.realpath(sys.argv[0]))
|
||||
print('os.path.dirname(os.path.realpath(sys.executable))',
|
||||
os.path.dirname(os.path.realpath(sys.executable)))
|
||||
print('os.path.dirname(os.path.realpath(sys.argv[0]))',
|
||||
os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||
util = Util()
|
||||
print('get_app_path',util.get_app_path())
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
kmw = kmanWindow()
|
||||
icon = QIcon()
|
||||
|
||||
Reference in New Issue
Block a user