kindle manager

This commit is contained in:
gavin
2020-06-11 17:21:16 +08:00
parent c903004b8f
commit 43c602d8d6
38 changed files with 565 additions and 248 deletions

83
tfile/tdataframe.py Normal file
View File

@@ -0,0 +1,83 @@
# CG test pandas
import pandas as pd
from kman import *
data = {
'state':['Ohio','Ohio','Ohio','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002],
'pop':[1.5,1.7,3.6,2.4,2.9],
'xx':[1.5,1.7,3.6,2.4,2.9]
}
"""
year state pop debt
one 2000 Ohio 1.5 16.5
two 2001 Ohio 1.7 16.5
three 2002 Ohio 3.6 16.5
four 2001 Nevada 2.4 16.5
five 2002 Nevada 2.9 16.5
"""
frame = pd.DataFrame(data,
index = ['one', 'two','three','four','five'],
columns = ['year','state','pop','debt','xx'])
print(frame.iat[0, 0])
print(frame.iat[1, 1])
print(frame.iat[2, 2])
print(frame.iat[2, 1])
'''
print('\n---------------------')
print(frame)
print('\n---------------------')
frame['debt']=16.5
print(frame)
print('\n---------------------')
print(frame.iloc[2]) #line 2
print('\n---------------------')
print(frame.iloc[[2,3],0:2])
print('\n---------------------')
print(frame.iloc[[2,3],0:2])
print('\n---------------------')
print(frame.iat[1, 1])
print('\n---------------------')
for index, row in frame.iterrows():
print(index)
print(row)
print('\n---------------------')
for row in frame.iterrows():
print(row)
#print(row[0], row[1])
print('\n---------------------')
print(frame.head(2))
print('\n---------------------')
print(frame.columns)
print('\n---------------------')
print(frame.index)
print('\n---------------------')
print(frame.to_dict())
print('\n---------------------')
'''
km = kMan()
books = km.import_clips()
print(books)
print('\n---------------------')
frame = pd.DataFrame(books)
print(frame)
print('\n---------------------')
data = [['Ohio','Ohio','Ohio','Nevada','Nevada'],
[2000,2001,2002,2001,2002],
[1.5,1.7,3.6,2.4,2.9],
[1.5,1.7,3.6,2.4,2.9],
[1.5,1.7,3.6,2.4,2.9],
]
frame = pd.DataFrame(data,
columns = ['year','state','pop','debt','xx'])
print(frame)

39
tfile/tdict.py Normal file
View File

@@ -0,0 +1,39 @@
#########################################################
## @file : tdict.py
## @desc : test dict
## @create : 2020/05/26
## @author : Chengan
## @email : douboer@gmail.com
#########################################################
import re
from collections import defaultdict
t = {'a':{'b':{'c':1}}}
t['a']['b']['c']=2
t['a']=2
print(t)
t1 = {'a':{'b':{'c':'3'}}}
t2 = t1
print(t2)
t3 = {'b':{'c':'4'}}
t4 = defaultdict(dict)
t4['a'] = t3
print(t4)
t4['a1']['b2'] = {'c3':'5'}
print(t4)
t4['a1']['d2'] = {'c3':'6'}
print(t4)
t4['a1']['e2'] = {'c3':'7'}
print(t4)
t4['b1']['b2'] = {'b5':1}
print(t4)
t4['b1']['b2']['b3'] = {'b5':1}
print(t4)

19
tfile/tlog.py Normal file
View File

@@ -0,0 +1,19 @@
# CG test logging
import logging
import os.path
import time
logger = logging.getLogger()
logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
level=logging.INFO)
logger.setLevel(logging.DEBUG)
tt = 'xxx'
tt1 = 'yyy'
logger.debug('this is a logger debug message {} {}'.format(tt,tt1))
logger.info('this is a logger info message')
logger.warning('this is a logger warning message')
logger.error('this is a logger error message')
logger.critical('this is a logger critical message')

88
tfile/tqtableview.py Normal file
View File

@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
"""
@author: Taar
"""
#conversion of https://github.com/openwebos/qt/tree/master/examples/tutorials/modelview/5_edit
#I work with ints for values instead of strings (less cumbersome to add)
import sys
import pandas as pd
from PySide2.QtWidgets import *
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,
QPixmap, QRadialGradient, QStandardItem, QStandardItemModel)
from PySide2.QtCore import (QCoreApplication, QDate, QDateTime, QMetaObject,
QAbstractTableModel, QObject, QPoint, QRect, QSize, QTime,
QUrl, Qt, QThread, Signal, QTimer)
class TableModel(QAbstractTableModel):
def __init__(self, data):
super(TableModel, self).__init__()
self._data = data
def data(self, index, role):
if role == Qt.DisplayRole:
value = self._data.iloc[index.row(), index.column()]
return str(value)
def rowCount(self, index):
return self._data.shape[0]
def columnCount(self, index):
return self._data.shape[1]
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])
if orientation == Qt.Vertical:
return str(self._data.index[section])
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.table = QTableView()
data = pd.DataFrame([
[1, 9, 2],
[1, 0, -1],
[3, 5, 2],
[3, 3, 2],
[5, 8, 9],
],
columns = ['A', 'B', 'C'],
index=['Row 1', 'Row 2', 'Row 3', 'Row 4', 'Row 5'])
self.model = TableModel(data)
self.table.setModel(self.model)
data = pd.DataFrame([
[1, 5, 5, 9],
[1, 5, 5, 9],
[1, 2, 1, 3],
[1, 1, 0, -1],
[1, 5, 5, 2],
[1, 5, 5, 8],
[1, 5, 5, 9],
],
columns = ['Aa', 'Bb', 'Cc', 'dd'],
index=['Row 1', 'Row 3', 'Row 4', 'Row 4', 'Row 5', '6', '7'])
self.model = TableModel(data)
self.table.setModel(self.model)
self.setCentralWidget(self.table)
if __name__ == '__main__':
app=QApplication(sys.argv)
window=MainWindow()
window.show()
app.exec_()

6
tfile/tsys.py Normal file
View File

@@ -0,0 +1,6 @@
import platform
print(platform.system(),platform.machine(),platform.platform(aliased=0, terse=0) )

106
tfile/tthread.py Normal file
View File

@@ -0,0 +1,106 @@
import sys
import pyqtgraph as pg
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QThread, pyqtSignal, QTimer
import numpy as np
class PlotSin(QThread):
# 定义信号self.y 是 numpy.array所以信号数据类型为 object
signal = pyqtSignal(object)
def __init__(self, parent=None):
super().__init__()
self.y = None
self.phase = 0
def sin(self):
self.x = np.arange(0, 3.0, 0.01)
self.y = np.sin(2 * np.pi * self.x + self.phase)
self.phase += 0.1
QThread.msleep(200) # 等待200毫秒
def run(self):
for _ in range(300):
self.sin()
self.signal.emit(self.y) # 向连接槽发射信号 self.y
class PlotSin_MainWindow(QDialog):
def __init__(self):
super().__init__()
self.initUI()
self.clock_time = 0
self.timer = QTimer(self) # 生成定时器
self.timer.timeout.connect(self.clock) # 绑定计时函数 self.clock
def initUI(self):
self.creatContorls("时间显示:")
self.creatResult("函数绘制:")
layout = QHBoxLayout()
layout.addWidget(self.controlsGroup)
layout.addWidget(self.resultGroup)
self.setLayout(layout)
self.beginButton.clicked.connect(self.clock_begin)
self.setGeometry(300, 300, 600, 300)
self.setWindowTitle('Plot Sine')
self.show()
def creatContorls(self,title):
self.controlsGroup = QGroupBox(title)
self.beginButton = QPushButton("开始")
numberLabel = QLabel("运行时间:")
self.clockLabel = QLabel("")
controlsLayout = QGridLayout()
controlsLayout.addWidget(numberLabel, 0, 0)
controlsLayout.addWidget(self.clockLabel, 0, 1)
controlsLayout.addWidget(self.beginButton, 3, 0)
self.controlsGroup.setLayout(controlsLayout)
def creatResult(self,title):
self.resultGroup = QGroupBox(title)
self.guiplot = pg.PlotWidget()
gridLayout = QGridLayout()
gridLayout.addWidget(self.guiplot,0,2,2,3)
self.resultGroup.setLayout(gridLayout)
def clock_begin(self):
if not self.timer.isActive():
self.recorder_thread = PlotSin()
self.recorder_thread.signal.connect(self.displaySin) # 绑定信号槽函数
self.recorder_thread.start() # 线程执行
self.clock()
self.timer.start(1000)
else:
self.beginButton.setText("开始")
self.clockLabel.setText("")
self.recorder_thread.terminate() # 终止线程
self.timer.stop() # 终止定时器
self.clock_time = 0
text = str(self.clock_time) + "s"
self.clockLabel.setText(text)
def clock(self):
text = str(self.clock_time) + "s"
self.clockLabel.setText(text)
if self.clock_time == 0:
self.beginButton.setText("结束")
self.clock_time += 1
def plotSin(self, y):
self.guiplot.clear()
self.guiplot.plot(y)
def displaySin(self, y):
self.plotSin(y)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = PlotSin_MainWindow()
window.show()
sys.exit(app.exec_())