109 lines
3.0 KiB
Python
Executable File
109 lines
3.0 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
"""
|
|
|
|
Configuration file located at ~/.config/ymsgui.conf:
|
|
[DB]
|
|
host = localhost
|
|
db = yms
|
|
user = yms
|
|
pass = topsecret
|
|
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import locale
|
|
import configparser
|
|
|
|
import gi
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import GLib, Gtk
|
|
|
|
from yms import database
|
|
from yms import gtkutils
|
|
|
|
cfg = {
|
|
'cfgfile': '~/.config/ymsgui.conf',
|
|
'host': 'localhost',
|
|
'db': 'yms',
|
|
'user': 'yms'
|
|
}
|
|
|
|
class Frontend():
|
|
|
|
def __init__(self):
|
|
builder = Gtk.Builder()
|
|
builder.add_from_file("yms/ui/main.ui")
|
|
builder.connect_signals(self)
|
|
self.window = builder.get_object("wnd_main")
|
|
gtkutils.init_named_controls(self, builder)
|
|
|
|
# get current vessel id
|
|
db.cur.execute("SELECT valint FROM settings WHERE userid=0 AND sno=1")
|
|
row = db.cur.fetchone()
|
|
if not row:
|
|
self.vid = 0
|
|
self.vname = "Ghost"
|
|
db.cur.execute("INSERT INTO settings (userid, sno, valint) VALUES (0, 1, 0)")
|
|
db.conn.commit()
|
|
else:
|
|
self.vid = row[0]
|
|
# get vessel infos
|
|
if self.vid > 0:
|
|
db.cur.execute("SELECT vesselname, model FROM vessel WHERE vid=%s", (self.vid, ))
|
|
self.vessel = db.cur.fetchone()
|
|
print(self.vessel['sesselname'])
|
|
else:
|
|
self.vname = "Ghost(0)"
|
|
|
|
def run(self):
|
|
self.label['vessel'].set_text(self.vname)
|
|
self.window.show_all()
|
|
Gtk.main()
|
|
|
|
def on_but_info_clicked(self, widget):
|
|
|
|
# Userlist
|
|
sql = ("SELECT userid, login FROM user ORDER BY login")
|
|
db.cur.execute(sql)
|
|
for row in db.cur.fetchall():
|
|
print(row)
|
|
|
|
def on_destroy(self, widget, data=None):
|
|
Gtk.main_quit()
|
|
|
|
def messagebox(messagetext, symbol=None, title=None, parent=None):
|
|
if not symbol:
|
|
symbol = Gtk.MessageType.INFO
|
|
if parent:
|
|
symbol |= Gtk.DIALOG_DESTROY_WITH_PARENT
|
|
md = Gtk.MessageDialog(parent=parent, flags=0, message_type=symbol, buttons=Gtk.ButtonsType.CLOSE)
|
|
md.set_markup(messagetext)
|
|
if title:
|
|
md.set_title(title)
|
|
if not parent:
|
|
md.set_position(Gtk.WindowPosition.CENTER)
|
|
md.run()
|
|
md.destroy()
|
|
|
|
if __name__ == "__main__":
|
|
locale.setlocale(locale.LC_ALL, '')
|
|
config = configparser.ConfigParser()
|
|
if not config.read(os.path.expanduser(cfg['cfgfile'])):
|
|
messagebox("Configuration file not found", title="YMS")
|
|
else:
|
|
cfg['host'] = config.get('DB', 'host')
|
|
cfg['db'] = config.get('DB', 'db')
|
|
cfg['user'] = config.get('DB', 'user')
|
|
cfg['pass'] = config.get('DB', 'pass')
|
|
db = database.Database(cfg['host'], cfg['db'])
|
|
if db.connect(cfg['user'], cfg['pass']):
|
|
app = Frontend()
|
|
app.run()
|
|
db.disconnect()
|
|
else:
|
|
messagebox("Database connection cannot be established", title="YMS")
|
|
|
|
# Another fine product of the sirius cybernetics corporation
|