2015-02-19 05:42:41 +07:00
|
|
|
#!/usr/bin/env python3
|
2008-07-24 10:08:55 +07:00
|
|
|
# Relational
|
|
|
|
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2010-02-23 18:46:58 +07:00
|
|
|
# Relational is free software: you can redistribute it and/or modify
|
2008-07-24 10:08:55 +07:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
2008-07-23 08:20:49 +07:00
|
|
|
|
|
|
|
import sys
|
2009-07-05 17:26:51 +07:00
|
|
|
import os
|
2010-06-21 07:33:43 +07:00
|
|
|
import os.path
|
2010-03-21 07:55:32 +07:00
|
|
|
import getopt
|
2015-06-02 05:35:47 +07:00
|
|
|
|
2009-02-26 07:18:02 +07:00
|
|
|
from relational import relation, parser
|
2015-09-14 18:58:17 +07:00
|
|
|
version = "2.2"
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
|
2010-06-21 16:02:47 +07:00
|
|
|
def printver(exit=True):
|
2015-02-19 05:42:41 +07:00
|
|
|
print ("Relational %s" % version)
|
|
|
|
print ("Copyright (C) 2008 Salvo 'LtWorf' Tomaselli.")
|
|
|
|
print ()
|
|
|
|
print ("This program comes with ABSOLUTELY NO WARRANTY.")
|
|
|
|
print ("This is free software, and you are welcome to redistribute it")
|
|
|
|
print ("under certain conditions.")
|
|
|
|
print ("For details see the GPLv3 Licese.")
|
|
|
|
print ()
|
|
|
|
print ("Written by Salvo 'LtWorf' Tomaselli <tiposchi@tiscali.it>")
|
|
|
|
print ()
|
|
|
|
print ("http://ltworf.github.io/relational/")
|
2010-06-21 16:02:47 +07:00
|
|
|
if exit:
|
|
|
|
sys.exit(0)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
def printhelp(code=0):
|
2015-02-19 05:42:41 +07:00
|
|
|
print ("Relational")
|
|
|
|
print ()
|
|
|
|
print ("Usage: %s [options] [files]" % sys.argv[0])
|
|
|
|
print ()
|
|
|
|
print (" -v Print version and exits")
|
|
|
|
print (" -h Print this help and exits")
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-04 06:18:22 +07:00
|
|
|
if sys.argv[0].endswith('relational-cli'):
|
2015-02-19 05:42:41 +07:00
|
|
|
print (" -q Uses QT user interface")
|
|
|
|
print (" -r Uses readline user interface (default)")
|
2011-03-04 06:18:22 +07:00
|
|
|
else:
|
2015-02-19 05:42:41 +07:00
|
|
|
print (" -q Uses QT user interface (default)")
|
|
|
|
print (" -r Uses readline user interface")
|
2010-03-21 07:55:32 +07:00
|
|
|
sys.exit(code)
|
2008-07-24 10:08:55 +07:00
|
|
|
|
2008-07-23 08:20:49 +07:00
|
|
|
if __name__ == "__main__":
|
2011-03-04 06:18:22 +07:00
|
|
|
if sys.argv[0].endswith('relational-cli'):
|
2013-12-26 17:31:43 +07:00
|
|
|
x11 = False
|
2011-03-04 06:18:22 +07:00
|
|
|
else:
|
2013-12-26 17:31:43 +07:00
|
|
|
x11 = True # Will try to use the x11 interface
|
|
|
|
|
|
|
|
# Getting command line
|
2010-03-21 07:55:32 +07:00
|
|
|
try:
|
2013-12-26 17:31:43 +07:00
|
|
|
switches, files = getopt.getopt(sys.argv[1:], "vhqr")
|
2010-03-21 07:55:32 +07:00
|
|
|
except:
|
|
|
|
printhelp(1)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
for i in switches:
|
2013-12-26 17:31:43 +07:00
|
|
|
if i[0] == '-v':
|
2010-03-21 07:55:32 +07:00
|
|
|
printver()
|
2013-12-26 17:31:43 +07:00
|
|
|
elif i[0] == '-h':
|
2010-03-21 07:55:32 +07:00
|
|
|
printhelp()
|
2013-12-26 17:31:43 +07:00
|
|
|
elif i[0] == '-q':
|
|
|
|
x11 = True
|
|
|
|
elif i[0] == '-r':
|
|
|
|
x11 = False
|
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
if x11:
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2013-12-26 17:56:57 +07:00
|
|
|
import sip # needed on windows
|
2015-02-19 07:00:47 +07:00
|
|
|
from PyQt5 import QtGui, QtWidgets
|
2011-03-21 02:43:57 +07:00
|
|
|
try:
|
2015-09-11 06:57:34 +07:00
|
|
|
from relational_gui import maingui, guihandler, about, surveyForm, resources
|
2011-03-21 02:43:57 +07:00
|
|
|
except:
|
2015-07-14 04:01:35 +07:00
|
|
|
print (
|
|
|
|
"Module relational_gui is missing.\nPlease install relational package.",
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
2013-12-26 17:56:57 +07:00
|
|
|
sys.exit(3)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
|
|
|
about.version = version
|
|
|
|
surveyForm.version = version
|
|
|
|
guihandler.version = version
|
2009-08-18 06:52:33 +07:00
|
|
|
|
2015-02-19 07:00:47 +07:00
|
|
|
app = QtWidgets.QApplication(sys.argv)
|
2013-12-26 17:31:43 +07:00
|
|
|
app.setOrganizationName('None')
|
|
|
|
app.setApplicationName('relational')
|
2015-05-31 17:02:32 +07:00
|
|
|
app.setOrganizationDomain("None")
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
ui = maingui.Ui_MainWindow()
|
2015-03-12 04:21:01 +07:00
|
|
|
form = guihandler.relForm(ui)
|
|
|
|
ui.setupUi(form)
|
2015-06-06 18:46:47 +07:00
|
|
|
f = QtGui.QFont()
|
2015-07-14 04:01:35 +07:00
|
|
|
size = f.pointSize()
|
2015-06-04 15:30:39 +07:00
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
winFont = 'Cambria'
|
2015-06-06 11:51:29 +07:00
|
|
|
symbolFont = 'Segoe UI Symbol'
|
2015-06-06 18:46:47 +07:00
|
|
|
increment = 4
|
|
|
|
else:
|
|
|
|
winFont = f.family()
|
|
|
|
symbolFont = f.family()
|
|
|
|
increment = 2
|
|
|
|
|
2015-07-14 04:01:35 +07:00
|
|
|
ui.lstHistory.setFont(QtGui.QFont(winFont, size + increment))
|
|
|
|
ui.txtMultiQuery.setFont(QtGui.QFont(winFont, size + increment))
|
|
|
|
ui.txtQuery.setFont(QtGui.QFont(winFont, size + increment))
|
|
|
|
ui.groupOperators.setFont(QtGui.QFont(winFont, size + increment))
|
2015-06-06 18:46:47 +07:00
|
|
|
ui.cmdClearMultilineQuery.setFont(QtGui.QFont(symbolFont))
|
|
|
|
ui.cmdClearQuery.setFont(QtGui.QFont(symbolFont))
|
2015-06-04 15:30:39 +07:00
|
|
|
|
2015-03-12 04:21:01 +07:00
|
|
|
form.restore_settings()
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2015-06-02 05:35:47 +07:00
|
|
|
m = enumerate(map(os.path.isfile, files))
|
2015-07-14 04:01:35 +07:00
|
|
|
invalid = ' '.join(
|
|
|
|
(files[i[0]] for i in (filter(lambda x: not x[1], m)))
|
|
|
|
)
|
2015-06-02 05:35:47 +07:00
|
|
|
if invalid:
|
2015-07-14 04:01:35 +07:00
|
|
|
print ("%s: not a file" % invalid, file=sys.stderr)
|
2015-06-02 05:35:47 +07:00
|
|
|
printhelp(12)
|
|
|
|
if len(files):
|
|
|
|
form.loadRelation(files)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
2015-03-12 04:21:01 +07:00
|
|
|
form.show()
|
2010-03-21 07:55:32 +07:00
|
|
|
sys.exit(app.exec_())
|
2010-06-21 12:05:31 +07:00
|
|
|
else:
|
2010-06-21 16:02:47 +07:00
|
|
|
printver(False)
|
2011-03-21 02:43:57 +07:00
|
|
|
try:
|
|
|
|
import relational_readline.linegui
|
|
|
|
except:
|
2015-07-14 04:01:35 +07:00
|
|
|
print (
|
|
|
|
"Module relational_readline is missing.\nPlease install relational-cli package.",
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
2011-03-21 02:43:57 +07:00
|
|
|
sys.exit(3)
|
2013-12-26 17:31:43 +07:00
|
|
|
relational_readline.linegui.version = version
|
2010-06-21 09:30:27 +07:00
|
|
|
relational_readline.linegui.main(files)
|