QCheckBox がチェックされているかどうかに基づいて QTableWidget の値を取得する際に問題があります。
from PyQt4 import QtGui
import cx_Oracle
from PyQt4.QtGui import *
from PyQt4.QtCore import Qt
from sympy import true
class PCFFileChecker(QFrame):
def on_click(self):
print("\n")
for currentQTableWidgetItem in self.tableV5.selectedItems():
print currentQTableWidgetItem.text()
def __init__(self, parent=None):
super(PCFFileChecker, self).__init__(parent)
self.Tab = QtGui.QTabWidget()
qvboxlayout = QtGui.QGridLayout(self)
self.TabV5 = QtGui.QWidget()
self.TabV7 = QtGui.QWidget()
self.tableV5 = QtGui.QTableWidget(0, 8, self.TabV5)
self.tableV7 = QtGui.QTableWidget(0, 9, self.TabV7)
# layout = QtGui.QVBoxLayout(self)
self.buttonV5 = QtGui.QWidget()
self.button1 = QtGui.QPushButton("Update Markit")
self.button2 = QtGui.QPushButton("Clear")
# self.TabV5.addWidget(self.button)
self.get_markitv5_details()
self.get_markitv7_details()
self.Tab.addTab(self.tableV5, "Markit v5")
self.Tab.addTab(self.tableV7, "Markit v7")
qvboxlayout.addWidget(self.Tab)
qvboxlayout.addWidget(self.button1)
qvboxlayout.addWidget(self.button2)
self.tableV5.itemSelectionChanged.connect(self.on_click)
self.tableV7.itemSelectionChanged.connect(self.on_click)
self.button1.clicked.connect(self.ButtonClicked)
def ButtonClicked(self):
checked_listV5 = []
for i in range(self.tableV5.rowCount()):
if self.tableV5.cellWidget(i, 0).findChild(type(QtGui.QCheckBox())).isChecked():
checked_listV5.append(self.tableV5.item(i, 1).text())
print checked_listV5
def get_markitv5_details(self):
self.tableV5.setHorizontalHeaderLabels(
['Tick', 'Instrument ID', 'Bloolmberg Code', 'Cluster ID', 'Insutrument Name', 'Position Date',
'Last Update Time', 'ISIN'])
db = cx_Oracle.connect('DBURL')
# db = cx_Oracle.connect('DBURL')
cur = db.cursor()
# insturment_id, bloomberg_code, instrument_name, ,Cluster_id, posistion_date, last_update_time, ISIN
cur.execute(
'select p.instrumentid, vmc.bloomberg_code, i.clusterid, i.instrumentname, p.positiondate, p.lastupdated, vmc.isin_code from markit.instruments i, markit.positions p , MARKIT.VW_MRK_COMPOSITE_INSTRUMENTS vmc where clusterid in ( select clusterid from markit.clusters where CLUSTERNAME in ( select vmci.SHORT_INSTRUMENT_NAME from MARKIT.VW_MRK_COMPOSITE_INSTRUMENTS vmci, TRD_DATA_ADM.IRE_ETF_MASTER@repl_prod aa, markit_etf_params mep where vmci.bloomberg_code = aa.ROOTBLOOMBERG and aa.ROOTBLOOMBERG = mep.INSTR_NAME)) and i.instrumentid = p.instrumentid and vmc.INSTRUMENT_ID = i.instrumentid and p.positiondate <= trunc(sysdate)')
rows = cur.fetchall()
# print rows
for i, row in enumerate(rows):
self.tableV5.insertRow(i)
checkItem = QTableWidgetItem()
checkItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
checkItem.setCheckState(Qt.Unchecked)
checkItem.setTextAlignment(Qt.AlignVCenter)
self.tableV5.setItem(i, 0, checkItem)
#self.tableV5.setItem(i, 5, DateItem)
#self.tableV5.setCellWidget(i, 0,self.Tab)
print (i)
for j, item in enumerate(row):
newItem = QTableWidgetItem(str(item))
self.tableV5.setItem(i, j + 1, newItem)
if (j != 5):
newItem.setFlags(Qt.ItemIsEditable)
header = self.tableV5.horizontalHeader()
header.setResizeMode(QHeaderView.ResizeToContents)
cur.close()
print(db.version)
db.close()
def checkItem_changed(self, state):
self.itemCheck = (state == Qt.Checked)
print(self.itemCheck)
def get_markitv7_details(self):
self.tableV7.setHorizontalHeaderLabels(
['Tick', 'ISIN', 'Asset Code', 'Asset ID', 'Asset Code Type', 'Cluster ID', 'Instrument Name',
'Last Update Time', 'Trade Date'])
# db = cx_Oracle.connect('DBURL')
db = cx_Oracle.connect('DBURL')
cur = db.cursor()
# insturment_id, bloomberg_code, instrument_name, ,Cluster_id, posistion_date, last_update_time, ISIN
cur.execute(
"select distinct ac.Value ISIN, vmis.asset_code, vmis.asset_code_type, a.AssetID, c.ClusterID, c.Name, c.SourceLastUpdated, cast(e.TradeDate as date) TradeDate from MARKIT7_SIG.tblCluster c join MARKIT7_SIG.tblInstrument i on i.ClusterID = c.ClusterID join MARKIT7_SIG.tblInstrumentSmry iss on iss.IndexMark = i.InstrumentMark join MARKIT7_SIG.tblEtp e on e.ClusterID = c.ClusterID join MARKIT7_SIG.tblAsset a on a.AssetID = e.EtpAssetID join MARKIT7_SIG.VW_MRK7_COMP_INSTRUMENTS_SPRD vmis on vmis.asset_id = a.AssetID join MARKIT7_SIG.tblAssetCode ac on ac.AssetID = e.EtpAssetID and ac.CodeVendorID = (select CodeVendorID from MARKIT7_SIG.tblCodeVendor where Value = 'ISIN') and nvl(e.TradeDate, sysdate) < trunc(sysdate) and c.SourceLastUpdated < trunc(sysdate) and c.name like '%'")
rows = cur.fetchall()
# print rows
for i, row in enumerate(rows):
self.tableV7.insertRow(i)
checkItemV7 = QTableWidgetItem()
checkItemV7.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
checkItemV7.setCheckState(Qt.Unchecked)
checkItemV7.setTextAlignment(Qt.AlignVCenter)
self.tableV7.setItem(i, 0, checkItemV7)
print (i)
for j, item in enumerate(row):
newItem = QTableWidgetItem(str(item))
self.tableV7.setItem(i, j + 1, newItem)
if (j != 6):
newItem.setFlags(Qt.ItemIsEditable)
header = self.tableV7.horizontalHeader()
header.setResizeMode(QHeaderView.ResizeToContents)
cur.close()
print(db.version)
db.close()
コードを実行すると、以下のエラーが発生します。
Traceback (most recent call last):
File "C:/Users/admindholkawa/PycharmProjects/PCFChecks/pcffilechecks.py", line 54, in ButtonClicked
if self.tableV5.cellWidget(i, 0).findChild(type(QtGui.QCheckBox())).isChecked():
AttributeError: 'NoneType' object has no attribute 'findChild'
ここで何が欠けているのか分かりますか?