Skip to content

Commit

Permalink
Transfer LXMLModel to a new repo. I'll likely need it
Browse files Browse the repository at this point in the history
for other projects (like refactoring ChronosLNX,
continuing InQantation?, etc).
  • Loading branch information
ShadowKyogre committed Jul 22, 2014
1 parent 6451da8 commit 582ab22
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
3 changes: 2 additions & 1 deletion qtarotlib/deckedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from PyQt4 import QtGui,QtCore
from urllib.parse import urlparse
from random import sample,random
from pyqt_lxml_utils import LXMLModel

from .guiconfig import QTarotConfig
from .utilities import QDeckEdit, LXMLModel
from .utilities import QDeckEdit
from .xmlobjects import objectify, parser
from . import APPNAME,APPVERSION,AUTHOR,DESCRIPTION,YEAR,PAGE,EMAIL

Expand Down
59 changes: 0 additions & 59 deletions qtarotlib/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,6 @@
from lxml import objectify, etree
from .xmlobjects import TarotCard, objectify, parser

#http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel

class LXMLModel(QtCore.QAbstractItemModel):
def __init__(self, xmlobj):
QtCore.QAbstractItemModel.__init__(self)
self.xmlobj=xmlobj
self.cache=list(self.xmlobj.iter())

def index(self, row, column, parent):
print(row, column, parent, parent.isValid())
if not parent.isValid():
data=self.xmlobj.getchildren()[row]
return self.createIndex(row, column, data)
parentNode = parent.internalPointer()
print(parentNode.getchildren())
return self.createIndex(row, column, parentNode.getchildren()[row])

def parent(self, index):
#print('child', index)
if not index.isValid():
return QtCore.QModelIndex()
node = index.internalPointer()
if node.getparent() is None:
return QtCore.QModelIndex()
else:
parent=node.getparent()
grandparent=parent.getparent()
if grandparent is None:
return self.createIndex(parent.index(node), 0, parent)
else:
return self.createIndex(grandparent.index(parent), 0, parent)

def reset(self):
for i in self.xmlobject.iterchildren():
self.xmlobject.remove(i)
QtCore.QAbstractItemModel.reset(self)

def rowCount(self, parent):
#print('rowcount', parent, parent.isValid())
if not parent.isValid():
#print('counting root stuff', self.xmlobj.countchildren())
return self.xmlobj.countchildren()
#print('bx')
node = parent.internalPointer()
#print(node)
return node.countchildren()

def data(self, index, role):
#print('data', index, role)
if not index.isValid():
return None
node = index.internalPointer()
if role == QtCore.Qt.DisplayRole:
return node.tag+' - '+node.attrib.get('name', str(node.text))
return None

def columnCount(self, parent):
return 1

class QSuitEdit(QtGui.QWidget):
def __init__(self, parent = None, xmlobj=None):
super().__init__(parent)
Expand Down

0 comments on commit 582ab22

Please sign in to comment.