Work on native gui code
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import MySQLdb.cursors
|
||||
|
||||
class Equipment():
|
||||
|
||||
fields = ('vid' 'ename', 'shortname', 'model', 'ecat', 'serial', 'supplier',
|
||||
'manufacturer', 'purchdate', 'price', 'weight', 'remarks', 'flags')
|
||||
|
||||
def __init__(self, dbconn, eid=None):
|
||||
self.conn = dbconn
|
||||
self.dcur = dbconn.cursor(MySQLdb.cursors.DictCursor)
|
||||
|
||||
self.remarks = None
|
||||
self.data = {} # for old/new checks
|
||||
|
||||
def load(self):
|
||||
sql = (
|
||||
"SELECT {}".format(', '.join(self.fields))
|
||||
"FROM equipment "
|
||||
"WHERE eid=%s"
|
||||
)
|
||||
self.dcur.execute(sql, (self.eid,))
|
||||
self.data = self.dcur.fetchone()
|
||||
if self.data:
|
||||
for field in self.fields:
|
||||
setattr(self, field, self.data.get(field))
|
||||
else:
|
||||
for field in self.fields:
|
||||
setattr(self, field, None)
|
||||
|
||||
def save(self):
|
||||
pass
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import MySQLdb.cursors
|
||||
|
||||
class User(object):
|
||||
|
||||
def __init__(self, dbconn, user_id=None):
|
||||
self.conn = dbconn
|
||||
self.cur = dbconn.cursor(MySQLdb.cursors.DictCursor)
|
||||
if user_id:
|
||||
self.user_id = int(user_id)
|
||||
self.load()
|
||||
else:
|
||||
self.login = None
|
||||
self.displayname = None
|
||||
self.language = 'en'
|
||||
self.role = 'undef'
|
||||
self.flags = ''
|
||||
|
||||
def load(self):
|
||||
sql = (
|
||||
"SELECT login, displayname, language, role, flags "
|
||||
"FROM user "
|
||||
"WHERE user_id=%s")
|
||||
self.cur.execute(sql, (self.user_id, ))
|
||||
row = self.cur.fetchone()
|
||||
if row:
|
||||
self.data = row
|
||||
self.login = row['login']
|
||||
self.displayname = row['displayname']
|
||||
self.language = row['language']
|
||||
self.role = row['role']
|
||||
self.flags = row['flags']
|
||||
else:
|
||||
self.data = None
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
Speichern eines Benutzers ist momentan nicht vorgesehen
|
||||
"""
|
||||
pass
|
||||
|
||||
""" unused at the moment
|
||||
def mark_login(self):
|
||||
sql = "UPDATE user SET last_login=NOW() WHERE username=%s"
|
||||
self.cur.execute(sql, (self.username, ))
|
||||
self.conn.commit()
|
||||
|
||||
def mark_logout(self):
|
||||
sql = "UPDATE user SET last_logout=NOW() WHERE username=%s"
|
||||
self.cur.execute(sql, (self.username, ))
|
||||
self.conn.commit()
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
# Unique description
|
||||
out = "User(%d)" % self.user_id
|
||||
return out
|
||||
|
||||
def __str__(self):
|
||||
# Prettyprint
|
||||
out = "User(%d) - %s\n" % (self.user_id, self.displayname)
|
||||
out += " F: %s\n" % self.flags
|
||||
out += " R: %s\n" % self.role
|
||||
out += " L: %s\n" % self.language
|
||||
return out
|
||||
|
||||
+4
-3
@@ -5,12 +5,13 @@ import MySQLdb.cursors
|
||||
|
||||
class Vessel():
|
||||
|
||||
fields = ('vid', 'vtype', 'vesselname', 'model', 'loa', 'lwl',
|
||||
'beam', 'draught', 'draught_min', 'displacement', 'ballast',
|
||||
'beltpos_aft', 'beltpos_bow', 'shapefile', 'remarks')
|
||||
|
||||
def __init__(self, dbconn, vessel_id=None):
|
||||
self.conn = dbconn
|
||||
self.dcur = dbconn.cursor(MySQLdb.cursors.DictCursor)
|
||||
self.fields = ('vid', 'vtype', 'vesselname', 'model', 'loa', 'lwl',
|
||||
'beam', 'draught', 'draught_min', 'displacement', 'ballast',
|
||||
'beltpos_aft', 'beltpos_bow', 'shapefile', 'remarks')
|
||||
if vessel_id:
|
||||
self.vid = long(vessel_id)
|
||||
self.load()
|
||||
|
||||
@@ -23,6 +23,7 @@ import locale
|
||||
import gettext
|
||||
import configparser
|
||||
|
||||
os.environ["NO_AT_BRIDGE"] = "1" # fix dbus warnings
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GLib, Gtk
|
||||
@@ -61,7 +62,7 @@ class Frontend():
|
||||
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'])
|
||||
print(self.vessel['vesselname'])
|
||||
else:
|
||||
self.vname = "Ghost(0)"
|
||||
|
||||
@@ -69,7 +70,7 @@ class Frontend():
|
||||
db.cur.execute("SELECT vid, vesselname, model FROM vessel ORDER BY vid")
|
||||
for row in db.cur.fetchall():
|
||||
print(row)
|
||||
print(type(self.combo['vessel']))
|
||||
#print(type(self.combo['vessel']))
|
||||
|
||||
def run(self):
|
||||
self.label['vessel'].set_text(self.vname)
|
||||
|
||||
Reference in New Issue
Block a user