Skip to content

Commit

Permalink
Start making a rought draft for the deck editor and change any
Browse files Browse the repository at this point in the history
type specific supers to just plain super() functions.
  • Loading branch information
ShadowKyogre committed Jan 15, 2013
1 parent 23991cf commit 62f99d9
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 5 deletions.
2 changes: 1 addition & 1 deletion qtarotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## METADATA ##
APPNAME="QTarot"
APPVERSION="0.5.7"
APPVERSION="0.5.8"
AUTHOR="ShadowKyogre"
DESCRIPTION="A simple tarot fortune teller."
YEAR="2013"
Expand Down
217 changes: 217 additions & 0 deletions qtarotlib/deckedit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#!/usr/bin/python

import os
import argparse
from PyQt4 import QtGui,QtCore
from urllib.parse import urlparse
from random import sample,random

from .guiconfig import QTarotConfig
from .utilities import QDeckEdit
from . import APPNAME,APPVERSION,AUTHOR,DESCRIPTION,YEAR,PAGE,EMAIL

#http://www.sacred-texts.com/tarot/faq.htm#US1909

class QTarotDeckEdit(QtGui.QMainWindow):

def __init__(self):
super().__init__()
self.initUI()

def saveReadingAsIMG(self,filename,fmt):
pixMap = QtGui.QPixmap(self.scene.sceneRect().width(),self.scene.sceneRect().height())

c = QtGui.QColor(0)
c.setAlpha(0)
pixMap.fill(c)

painter=QtGui.QPainter(pixMap)
self.scene.render(painter)
painter.end()
pixMap.save(filename,format=fmt)

def saveReadingAsHTML(self,filename):
store_here="{}.files".format(filename.replace(".html",""))
if not os.path.exists(store_here):
os.makedirs(store_here)
reading_px=os.path.join(store_here,"reading.png")
reading_pxh=os.path.join(os.path.basename(store_here),"reading.png")
self.saveReadingAsIMG(reading_px,'png')

f=open(filename,'w')
import shutil
htmltpl=QtCore.QDir("htmltpl:/").absoluteFilePath('export_read.html')
f2=open(htmltpl)
template=f2.read()
f2.close()

cards=""
layout="<Unknown>"
deck_def_credits=""
layout_credits=""
deck=""
for item in list(self.scene.items()):
if isinstance(item,QTarotItem):
if layout == "<Unknown>":
layout=item.posData.getparent().get('name')
layout_credits=self.generateCredits(item.posData)
if not deck_def_credits:
deck_def_credits=self.generateCredits(item.card)
deck=item.card.getroottree().getroot().get('name')
text,copy_from,save_file=self.generateCardText(item.card,\
item.rev,item.posData.purpose.text,newfp=store_here)
shutil.copy(copy_from,save_file)
cards=''.join([cards,text])

f.write(template.format(cards=cards,deck=deck,
layout=layout,reading_px=reading_pxh,layout_credits=layout_credits,\
deck_def_credits=deck_def_credits))
f.close()

def saveReading(self,filename=None):
if not filename:
filename=str(QtGui.QFileDialog.getSaveFileName(self, caption="Save Current Reading",
filter="Images (%s);;HTML (*.html)" %(' '.join(formats))))
if filename:
fmt=filename.split(".",1)[-1]
if fmt == 'html':
self.saveReadingAsHTML(filename)
elif "*.{}".format(fmt) in formats:
self.saveReadingAsIMG(filename,fmt)
else:
QtGui.QMessageBox.critical(self, "Save Current Reading", \
"Invalid format ({}) specified for {}!".format(fmt,filename))

def about(self):
QtGui.QMessageBox.about (self, "About {}".format(APPNAME),
("<center><big><b>{0} Deck Editor {1}</b></big>"
"<br />{2}<br />(C) <a href=\"mailto:{3}\">{4}</a> {5}<br />"
"<a href=\"{6}\">{0} Homepage</a></center>")\
.format(APPNAME,APPVERSION,DESCRIPTION,EMAIL,AUTHOR,YEAR,PAGE))

def initUI(self):
self.setWindowTitle(app.applicationName())
self.view = QDeckEdit(self)

self.setCentralWidget(self.view)
self.setDockNestingEnabled(True)

exitAction = QtGui.QAction(QtGui.QIcon.fromTheme('application-exit'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)

newLayAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-new'), 'Create a new deck definition', self)
newLayAction.setShortcut('Ctrl+N')
newLayAction.setStatusTip('Create a new deck definition')
#newLayAction.triggered.connect(self.newReading)

saveAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-save'), 'Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.setStatusTip('Save')
#saveAction.triggered.connect(self.saveReading)

openAction = QtGui.QAction(QtGui.QIcon.fromTheme('document-open'), 'Edit another deck definition', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Edit another deck definition')
#openAction.triggered.connect(self.pickTable)
#self.findChildren(QtGui.QDockWidget, QString name = QString())

'''
settingsAction = QtGui.QAction(QtGui.QIcon.fromTheme('preferences-other'), 'Settings', self)
settingsAction.setStatusTip('Settings')
settingsAction.triggered.connect(self.settings)
browsingAction = QtGui.QAction(QtGui.QIcon.fromTheme('applications-graphics'), 'Browse Decks', self)
browsingAction.setStatusTip('Browse all deck definitions and deck skins you have')
browsingAction.triggered.connect(self.browseDecks)
'''

aboutAction=QtGui.QAction(QtGui.QIcon.fromTheme('help-about'), 'About', self)
aboutAction.triggered.connect(self.about)

st=self.statusBar()

menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
fileMenu.addAction(newLayAction)
#fileMenu.addAction(newChooseAction)
fileMenu.addAction(openAction)
fileMenu.addAction(saveAction)
#fileMenu.addAction(settingsAction)

toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
toolbar.addAction(newLayAction)
toolbar.addAction(openAction)
toolbar.addAction(saveAction)
#toolbar.addAction(browsingAction)
#toolbar.addAction(settingsAction)
toolbar.addAction(aboutAction)

#self.resize(500, 400)
self.setWindowTitle('QTarot')

def main():
global formats
global app
global qtrcfg

formats=set(["*."+''.join(i).lower() for i in \
QtGui.QImageWriter.supportedImageFormats()])

formats=sorted(list(formats),key=str.lower)
try:
formats.remove('*.bw')
except ValueError:
pass
try:
formats.remove('*.rgb')
except ValueError:
pass
try:
formats.remove('*.rgba')
except ValueError:
pass

app = QtGui.QApplication(os.sys.argv)

app.setApplicationName(APPNAME)
app.setApplicationVersion(APPVERSION)
app.setWindowIcon(QtGui.QIcon.fromTheme("qtarot"))

#qtrcfg = QTarotConfig()
'''
parser = argparse.ArgumentParser(prog='qtarot',description="A simple tarot fortune teller")
parser.add_argument('-l','--layout', help='The layout to use.',default=qtrcfg.default_layout,choices=list(qtrcfg.layouts.keys()))
parser.add_argument('-t','--table', help='File to use as table',default=qtrcfg.table)
parser.add_argument('-n','--negativity', help='How often cards are reversed', default=qtrcfg.negativity,type=float)
parser.add_argument('-o','--output', help='Save the reading to this file', default=None)
parser.add_argument('-d','--deck', help='Deck definition to use', default=qtrcfg.deck_def, choices=list(qtrcfg.deck_defs.keys()))
parser.add_argument('-s','--skin', help='Deck skin to use (valid values depend on deck definition)',default=qtrcfg.deck_skin)
args = parser.parse_args(os.sys.argv[1:])
'''

ex = QTarotDeckEdit()
'''
ex.updateTable(fn=args.table)
if args.deck != qtrcfg.deck_def or args.skin != qtrcfg.deck_skin:
if args.skin not in qtrcfg.deck_defs[args.deck]['skins']:
print(("Invalid skin \"{}\" for {}!\n"
"Valid skins: {}").format(args.skin,args.deck,qtrcfg.deck_defs[args.deck]['skins']))
exit(1)
ex.newReading(item=args.layout,neg=args.negativity,skin=args.skin,deck=args.deck)
if args.output:
ex.saveReading(filename=args.output)
#os.sys.exit(app.exec_())
else:
ex.show()
os.sys.exit(app.exec_())
'''
ex.show()
os.sys.exit(app.exec_())

if __name__ == "__main__":
main()
69 changes: 65 additions & 4 deletions qtarotlib/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,70 @@
from lxml import objectify
from .xmlobjects import TarotCard

class QSuitEdit(QtGui.QWidget):
def __init__(self, parent = None):
super().__init__(parent)
layout = QtGui.QGridLayout(self)
layout.addWidget(QtGui.QLabel("Name:"),0,0)
layout.addWidget(QtGui.QLabel("Affinity:"),1,0)
self.nameEdit=QtGui.QLineEdit(self)
self.affnEdit=QtGui.QLineEdit(self)
self.noSuitNEdit=QtGui.QCheckBox("No suit name in card name?:",self)
layout.addWidget(self.nameEdit,0,1)
layout.addWidget(self.affnEdit,1,1)
layout.addWidget(self.noSuitNEdit,2,0,1,2)

class QCardEdit(QtGui.QWidget):
def __init__(self, parent = None):
super().__init__(parent)
layout = QtGui.QGridLayout(self)
layout.addWidget(QtGui.QLabel("Name:"),0,0)
layout.addWidget(QtGui.QLabel("Number:"),1,0)
layout.addWidget(QtGui.QLabel("Filepath:"),2,0)
layout.addWidget(QtGui.QLabel("Source:"),3,0)
self.nameEdit=QtGui.QLineEdit()
self.numberEdit=QtGui.QLineEdit()
self.fpEdit=QtGui.QLineEdit()
self.srcEdit=QtGui.QLineEdit()
layout.addWidget(self.nameEdit,0,1)
layout.addWidget(self.numberEdit,1,1)
layout.addWidget(self.fpEdit,2,1)
layout.addWidget(self.srcEdit,3,1)

tabs=QtGui.QTabWidget()
self.nmeaningEdit=QtGui.QTextEdit()
self.rmeaningEdit=QtGui.QTextEdit()
tabs.addTab(self.nmeaningEdit,"Normal")
tabs.addTab(self.rmeaningEdit,"Reversed")
layout.addWidget(tabs,4,0,1,2)


class QDeckEdit(QtGui.QWidget):
def __init__(self, parent = 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()
layout.addWidget(self.authorEdit,0,1,1,2)
layout.addWidget(self.sourceEdit,1,1,1,2)
self.suitView=QtGui.QListView()
self.cardView=QtGui.QListView()
layout.addWidget(self.suitView,2,0)
layout.addWidget(self.cardView,2,1)
self.stack=QtGui.QStackedLayout()
self.suitedit=QSuitEdit()
self.cardedit=QCardEdit()
self.stack.addWidget(self.suitedit)
self.stack.addWidget(self.cardedit)
self.stack.setCurrentIndex(1)
layout.addLayout(self.stack,3,0,1,2)


class QDeckBrowser(QtGui.QWidget):
def __init__(self, parent = None, deck_source = None):
QtGui.QWidget.__init__(self, parent)
super().__init__(parent)
layout = QtGui.QGridLayout(self)
self.deckPicker=QtGui.QComboBox(self)
self.skinPicker=QtGui.QComboBox(self)
Expand Down Expand Up @@ -73,7 +134,7 @@ def populatePreview(self, new_skin):

class QTarotScene(QtGui.QGraphicsScene):
def __init__(self,*args):
QtGui.QGraphicsScene.__init__(self, *args)
super().__init__(*args)
self.tableitem=self.addPixmap(QtGui.QPixmap())
self.tableitem.setZValue(-1000.0)
def calculateOffset(self):
Expand Down Expand Up @@ -116,7 +177,7 @@ class QTarotItemEmitter(QtCore.QObject):
clearName=QtCore.pyqtSignal([])

def __init__(self, card, pos_data, reverse, parent=None, scene=None):
QtGui.QGraphicsPixmapItem.__init__(self, parent=None, scene=None)
super().__init__(parent=None, scene=None)
#QtGui.QGraphicsObject.__init__(self, parent)
self.setAcceptHoverEvents(True)
self.card=card
Expand Down Expand Up @@ -203,7 +264,7 @@ def mouseDoubleClickEvent(self, event):

class ZPGraphicsView(QtGui.QGraphicsView):
def __init__(self, *args):
QtGui.QGraphicsView.__init__(self, *args)
super().__init__(*args)
self.lastPanPoint=QtCore.QPoint()
self.setCenter(QtCore.QPointF(self.sceneRect().width()/2.0, \
self.sceneRect().height()/2.0))
Expand Down

0 comments on commit 62f99d9

Please sign in to comment.