Skip to content

Commit

Permalink
Merge branch 'wip' of github.com:ShadowKyogre/QTarot into wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowKyogre committed Jul 24, 2014
2 parents 660b145 + 582ab22 commit 419a0c3
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.py[cod]
*.swp
*~

# C extensions
*.so
Expand Down
4 changes: 4 additions & 0 deletions qtarot-deckedit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3
from qtarotlib import deckedit
deckedit.main()

23 changes: 22 additions & 1 deletion qtarotlib/deckedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
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
from .xmlobjects import objectify, parser
from . import APPNAME,APPVERSION,AUTHOR,DESCRIPTION,YEAR,PAGE,EMAIL

#http://www.sacred-texts.com/tarot/faq.htm#US1909
Expand Down Expand Up @@ -91,7 +93,26 @@ def about(self):

def initUI(self):
self.setWindowTitle(app.applicationName())
self.view = QDeckEdit(self)
#self.view = QDeckEdit(self)
self.view = QtGui.QTreeView(self)
blub=objectify.fromstring("""
<deck>
<author>me</author>
<source>yeep</source>
<suit name='them' affinity='durp'>
<card name='you'>
<file>selfie.png</file>
<meaning>
<normal>normal self</normal>
<reversed>a&lt;i&gt;e&lt;/i&gt;a</reversed>
</meaning>
<source>yeep/you</source>
</card>
</suit>
</deck>
""",parser=parser)
model = LXMLModel(blub)
self.view.setModel(model)

self.setCentralWidget(self.view)
self.setDockNestingEnabled(True)
Expand Down
31 changes: 26 additions & 5 deletions qtarotlib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
class QTarot(QtGui.QMainWindow):

def __init__(self):
super(QTarot, self).__init__()
super().__init__()
self.last_layout=None
self.initUI()

def updateCards(self):
Expand Down Expand Up @@ -132,15 +133,22 @@ def newReading(self,item=None,neg=None,skin=None,

qtrcfg.setup_skin(skin)

if item not in list(qtrcfg.layouts.keys()):
layouts=list(qtrcfg.layouts.keys())
if item not in layouts:
try:
idx = layouts.index(self.last_layout)
except ValueError as e:
idx = 0
item,ok = QtGui.QInputDialog.getItem(self, "Generate new reading",
"Layout to use:", list(qtrcfg.layouts.keys()), 0, False)
"Layout to use:", layouts, idx, False)
if ok and item:
lay=qtrcfg.layouts[str(item)]
lay=qtrcfg.layouts[item]
self.last_layout=item
else:
return
else:
lay=qtrcfg.layouts[str(item)]
lay=qtrcfg.layouts[item]
self.last_layout=item
self.scene.clear()
self.scene.invalidate()

Expand Down Expand Up @@ -427,6 +435,16 @@ def initUI(self):
newChooseAction.setStatusTip('Generate a new reading using a deck and skin of choice')
newChooseAction.triggered.connect(lambda: self.newReading(ask_for_deck=True))

reloadDataAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-new'), 'Reload data', self)
reloadDataAction.setShortcut('Ctrl+Shift+R')
reloadDataAction.setStatusTip('Generate a new reading using a deck and skin of choice')
reloadDataAction.triggered.connect(qtrcfg.refreshData)

reloadReadingAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-new'), 'Reload reading', self)
reloadReadingAction.setShortcut('Ctrl+R')
reloadReadingAction.setStatusTip('Generate a new reading using the last layout')
reloadReadingAction.triggered.connect(lambda: self.newReading(item=self.last_layout))

saveAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-save'), 'Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.setStatusTip('Save')
Expand Down Expand Up @@ -456,13 +474,16 @@ def initUI(self):
fileMenu.addAction(exitAction)
fileMenu.addAction(newLayAction)
fileMenu.addAction(newChooseAction)
fileMenu.addAction(reloadReadingAction)
fileMenu.addAction(reloadDataAction)
fileMenu.addAction(openAction)
fileMenu.addAction(saveAction)
fileMenu.addAction(settingsAction)

toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
toolbar.addAction(newLayAction)
toolbar.addAction(reloadReadingAction)
toolbar.addAction(openAction)
toolbar.addAction(saveAction)
toolbar.addAction(browsingAction)
Expand Down
3 changes: 3 additions & 0 deletions qtarotlib/guiconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def reset_settings(self):
self.table=self.settings.value("table","skin:table.png")
self.settings.endGroup()

self.refreshData()

def refreshData(self):
self.load_deck_defs()
self.load_layouts()
self.load_skins()
Expand Down
17 changes: 11 additions & 6 deletions qtarotlib/utilities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from PyQt4 import QtGui,QtCore
from lxml import objectify
from .xmlobjects import TarotCard
from lxml import objectify, etree
from .xmlobjects import TarotCard, objectify, parser

class QSuitEdit(QtGui.QWidget):
def __init__(self, parent = None):
def __init__(self, parent = None, xmlobj=None):
super().__init__(parent)
layout = QtGui.QGridLayout(self)
layout.addWidget(QtGui.QLabel("Name:"),0,0)
Expand All @@ -16,7 +16,7 @@ def __init__(self, parent = None):
layout.addWidget(self.noSuitNEdit,2,0,1,2)

class QCardEdit(QtGui.QWidget):
def __init__(self, parent = None):
def __init__(self, parent = None, xmlobj=None):
super().__init__(parent)
layout = QtGui.QGridLayout(self)
layout.addWidget(QtGui.QLabel("Name:"),0,0)
Expand All @@ -41,13 +41,13 @@ def __init__(self, parent = None):


class QDeckEdit(QtGui.QWidget):
def __init__(self, parent = None):
def __init__(self, parent = None, xmlobj=None):
super().__init__(parent)
layout = QtGui.QGridLayout(self)
layout.addWidget(QtGui.QLabel("Author:"),0,0)
layout.addWidget(QtGui.QLabel("Source:"),1,0)
self.authorEdit=QtGui.QLineEdit()
self.sourceEdit=QtGui.QLineEdit()
self.sourceEdit=QtGui.QLineEdit()
layout.addWidget(self.authorEdit,0,1,1,2)
layout.addWidget(self.sourceEdit,1,1,1,2)
self.suitView=QtGui.QListView()
Expand All @@ -61,6 +61,11 @@ def __init__(self, parent = None):
self.stack.addWidget(self.cardedit)
self.stack.setCurrentIndex(1)
layout.addLayout(self.stack,3,0,1,2)

if xmlobj is None:
self.xmlobj = xmlobj
else:
self.xmlobj = objectify.parse('<deck />', parser=parser)


class QDeckBrowser(QtGui.QWidget):
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def finalize_options(self):

def run (self):
_install.run(self)

# Rewrite with constants if needed
for f in self.get_outputs():
# If is package __init__.py file holding some constants
Expand All @@ -45,10 +44,14 @@ def run (self):
replace_me = os.path.join(self.install_data,'share/qtarot')
elif self.prefix:
replace_me = os.path.join(self.prefix,'share/qtarot')
if self.root[-1] == '/':

if self.root == None:
consts = [['DATA_DIR', replace_me.replace(os.sep,'/')]]
elif self.root[-1] == '/':
consts = [['DATA_DIR', replace_me.replace(self.root[:-2],'')]]
else:
consts = [['DATA_DIR', replace_me.replace(self.root,'')]]

script = open(f, 'w', encoding='utf-8')
script.write(content[:const_begin] + \
"### CONSTANTS BEGIN ###")
Expand Down Expand Up @@ -85,6 +88,7 @@ def globby_decks():
author_email = EMAIL,
description = DESCRIPTION,
url = PAGE,
license = "GPLv3",
packages = ['qtarotlib'],
cmdclass={'install': install},
data_files = data_files,
Expand Down

0 comments on commit 419a0c3

Please sign in to comment.