mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Better usability of INI configuration.
This commit is contained in:
parent
aca5f16e28
commit
024c1f9a72
@ -1,3 +1,5 @@
|
||||
Various utilities.
|
||||
|
||||
## License: GPL v3
|
||||
Requires Python 3, versions below 3.4 might work but are not tested.
|
||||
|
||||
## License: GPL v3
|
||||
|
7
captureviewer.ini
Normal file
7
captureviewer.ini
Normal file
@ -0,0 +1,7 @@
|
||||
[paths]
|
||||
db_path=<path to cdclient.sqlite>
|
||||
[parse]
|
||||
creations=True
|
||||
serializations=True
|
||||
game_messages=True
|
||||
normal_packets=True
|
@ -2,7 +2,9 @@ import configparser
|
||||
import math
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
import tkinter.filedialog as filedialog
|
||||
import tkinter.messagebox as messagebox
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from collections import OrderedDict
|
||||
@ -111,7 +113,12 @@ class CaptureViewer(viewer.Viewer):
|
||||
super().__init__()
|
||||
config = configparser.ConfigParser()
|
||||
config.read("captureviewer.ini")
|
||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
||||
try:
|
||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
||||
except:
|
||||
messagebox.showerror("Can not open database", "Make sure db_path in the INI is set correctly.")
|
||||
sys.exit()
|
||||
|
||||
self.enable_game_messages = "gamemessages_path" in config["paths"]
|
||||
if self.enable_game_messages:
|
||||
gamemsg_xml = ET.parse(config["paths"]["gamemessages_path"])
|
||||
@ -122,13 +129,13 @@ class CaptureViewer(viewer.Viewer):
|
||||
|
||||
self.objects = []
|
||||
self.lot_data = {}
|
||||
self.parse_creations = BooleanVar(value=config["parse"].get("creations", True))
|
||||
self.parse_serializations = BooleanVar(value=config["parse"].get("serializations", True))
|
||||
self.parse_creations = BooleanVar(value=config["parse"]["creations"])
|
||||
self.parse_serializations = BooleanVar(value=config["parse"]["serializations"])
|
||||
if self.enable_game_messages:
|
||||
self.parse_game_messages = BooleanVar(value=config["parse"].get("game_messages", True))
|
||||
self.parse_game_messages = BooleanVar(value=config["parse"]["game_messages"])
|
||||
else:
|
||||
self.parse_game_messages = BooleanVar(value=False)
|
||||
self.parse_normal_packets = BooleanVar(value=config["parse"].get("normal_packets", True))
|
||||
self.parse_normal_packets = BooleanVar(value=config["parse"]["normal_packets"])
|
||||
self.create_widgets()
|
||||
|
||||
def create_widgets(self):
|
||||
|
2
luzviewer.ini
Normal file
2
luzviewer.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[paths]
|
||||
db_path=<path to cdclient.sqlite>
|
@ -1,8 +1,10 @@
|
||||
import configparser
|
||||
import os.path
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
import tkinter.filedialog as filedialog
|
||||
import tkinter.messagebox as messagebox
|
||||
from tkinter import END, Menu
|
||||
|
||||
import viewer
|
||||
@ -13,7 +15,11 @@ class LUZViewer(viewer.Viewer):
|
||||
super().__init__()
|
||||
config = configparser.ConfigParser()
|
||||
config.read("luzviewer.ini")
|
||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
||||
try:
|
||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
||||
except:
|
||||
messagebox.showerror("Can not open database", "Make sure db_path in the INI is set correctly.")
|
||||
sys.exit()
|
||||
self.create_widgets()
|
||||
|
||||
def create_widgets(self):
|
||||
|
Loading…
Reference in New Issue
Block a user