78 lines
1.9 KiB
Python
Executable File
78 lines
1.9 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
|
|
|
|
cfg = {
|
|
'cfgfile': '~/.config/ymsgui.conf',
|
|
'host': 'localhost',
|
|
'db': 'yms',
|
|
'user': 'yms'
|
|
}
|
|
|
|
class Frontend(Gtk.Window):
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.connect("destroy", self.on_destroy)
|
|
|
|
def run(self):
|
|
self.show_all()
|
|
Gtk.main()
|
|
|
|
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
|