Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pequeños aportes #9

Merged
merged 5 commits into from Feb 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
103 changes: 85 additions & 18 deletions pineboolib/flcontrols.py
Expand Up @@ -467,17 +467,41 @@ def data(self, index, role = QtCore.Qt.DisplayRole):
return None


class FLTableDB(QtGui.QTableView):
class FLTableDB(QtGui.QWidget):
_tableView = None
_vlayout = None
_lineEdit = None
_comboBox_1 = None
_comboBox_2 = None

def __init__(self, parent = None, action_or_cursor = None, *args):
print("FLTableDB:", parent, action_or_cursor , args)
# TODO: Falta el lineeditsearch y el combo, que los QS lo piden
super(FLTableDB,self).__init__(parent,*args)
# TODO: LA inicialización final hay que hacerla más tarde, en el primer
# show(), porque sino obligas a tenerlo todo preparado en el constructor.
self._v_header = self.verticalHeader()
self._v_header.setDefaultSectionSize(18)
self._h_header = self.horizontalHeader()
self._h_header.setDefaultSectionSize(70)
self._tableView = QtGui.QTableView()
self._lineEdit = QtGui.QLineEdit()
_label1 = QtGui.QLabel()
_label2 = QtGui.QLabel()
self._comboBox_1 = QtGui.QComboBox()
self._comboBox_2 = QtGui.QComboBox()
_label1.setText("Buscar")
_label2.setText("en")
self._vlayout = QtGui.QVBoxLayout()
_hlayout = QtGui.QHBoxLayout()
self._tableView._v_header = self._tableView.verticalHeader()
self._tableView._v_header.setDefaultSectionSize(18)
self._tableView._h_header = self._tableView.horizontalHeader()
self._tableView._h_header.setDefaultSectionSize(70)
_hlayout.addWidget(_label1)
_hlayout.addWidget(self._lineEdit)
_hlayout.addWidget(_label2)
_hlayout.addWidget(self._comboBox_1)
_hlayout.addWidget(self._comboBox_2)
self._vlayout.addLayout(_hlayout)
self._vlayout.addWidget(self._tableView)
self.setLayout(self._vlayout)
self._parent = parent
while True:
parent_cursor = getattr(self._parent,"_cursor", None)
Expand All @@ -487,10 +511,10 @@ def __init__(self, parent = None, action_or_cursor = None, *args):
self._parent = new_parent
print(self._parent)

self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.setAlternatingRowColors(True)
self._tableView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self._tableView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self._tableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self._tableView.setAlternatingRowColors(True)

if action_or_cursor is None and parent_cursor:
action_or_cursor = parent_cursor
Expand All @@ -501,10 +525,23 @@ def __init__(self, parent = None, action_or_cursor = None, *args):
else:
self._cursor = None
if self._cursor:
self._h_header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.setModel(self._cursor._model)
self.setSelectionModel(self._cursor.selection())
self._tableView._h_header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
self._tableView.setModel(self._cursor._model)
self._tableView.setSelectionModel(self._cursor.selection())
self.tableRecords = self # control de tabla interno

#Carga de comboBoxs y connects .- posiblemente a mejorar
if self._cursor:
for column in range(self._cursor._model.columnCount()):
self._comboBox_1.addItem(self._cursor._model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole))
self._comboBox_2.addItem(self._cursor._model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole))
self._comboBox_1.addItem("*")
self._comboBox_2.addItem("*")
self._comboBox_1.setCurrentIndex(0)
self._comboBox_2.setCurrentIndex(1)
self._comboBox_1.currentIndexChanged.connect(self.comboBox_putFirstCol)
self._comboBox_2.currentIndexChanged.connect(self.comboBox_putSecondCol)

self.sort = []
self.timer_1 = QtCore.QTimer(self)
self.timer_1.singleShot(100, self.loaded)
Expand All @@ -515,7 +552,7 @@ def loaded(self):
# Es necesario pasar a modo interactivo lo antes posible
# Sino, creamos un bug en el cierre de ventana: se recarga toda la tabla para saber el tamaño
print("FLTableDB: setting columns in interactive mode")
self._h_header.setResizeMode(QtGui.QHeaderView.Interactive)
self._tableView._h_header.setResizeMode(QtGui.QHeaderView.Interactive)

def cursor(self):
assert self._cursor
Expand All @@ -524,18 +561,46 @@ def cursor(self):
def obj(self):
return self

def comboBox_putFirstCol(self):
self.putFirstCol(str(self._comboBox_1.currentText()))

def comboBox_putSecondCol(self):
self.putSecondCol(str(self._comboBox_2.currentText()))

def putFirstCol(self, fN):
oldPos= None
_oldPos= None
_oldFirst = self._tableView._h_header.logicalIndex(0)
for column in range(self._cursor._model.columnCount()):
if self._cursor._model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole).lower() == fN.lower():
oldPos = column
_oldPos = self._tableView._h_header.visualIndex(column)
if not self._comboBox_1.currentText() == fN:
self._comboBox_1.setCurrentIndex(column)
return False
break
if not oldPos:

if not _oldPos or fN == "*":
return False
else:
self._h_header.swapSections(oldPos, 0)
else:
self._tableView._h_header.swapSections(_oldPos, 0)
self._comboBox_2.setCurrentIndex(_oldFirst)
return True

def putSecondCol(self, fN):
_oldPos= None
_oldSecond = self._tableView._h_header.logicalIndex(1)
for column in range(self._cursor._model.columnCount()):
if self._cursor._model.headerData(column, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole).lower() == fN.lower():
_oldPos = self._tableView._h_header.visualIndex(column)
break

if not _oldPos or fN == "*":
return False
if not self._comboBox_1.currentText() == fN:
self._tableView._h_header.swapSections(_oldPos, 1)
else:
self._comboBox_1.setCurrentIndex(_oldSecond)
return True

@QtCore.pyqtSlot()
def close(self):
print("FLTableDB: close()")
Expand Down Expand Up @@ -883,6 +948,8 @@ def __init__(self, parent, *args):
self._lineEdit = QtGui.QLineEdit()
self._layout = QtGui.QHBoxLayout()
self._label = QtGui.QLabel()
spacer = QtGui.QSpacerItem(40,0,QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Expanding)
self._layout.addItem(spacer)
self._layout.addWidget(self._label)
self._layout.addWidget(self._lineEdit)
self.setLayout(self._layout)
Expand Down
5 changes: 5 additions & 0 deletions pineboolib/qt3ui.py
Expand Up @@ -9,6 +9,8 @@

from pineboolib import flcontrols

import zlib

Qt = QtCore.Qt
ICONS = {}

Expand Down Expand Up @@ -227,6 +229,9 @@ def loadIcon(xml):
img_format = xmldata.get("format")
data = unhexlify(xmldata.text.strip())
pixmap = QtGui.QPixmap()
if img_format == "XPM.GZ":
data = zlib.decompress(data,15)
img_format = "XPM"
pixmap.loadFromData(data, img_format)
icon = QtGui.QIcon(pixmap)
ICONS[name] = icon
Expand Down