Commits

Ada Young committed 44fb2be

Added a file picker dialog to let users pick the dbfile location on first load. Version bumps.

Comments (0)

Files changed (3)

    purpose="Log Database"
    date_written="2012-12-05 12:00:00"
    requires="4.62"
-   version="1.2"
+   version="1.3"
    >
 <description trim="y">
 <![CDATA[
 
 <script>
 <![CDATA[
-import os
 import re
 import sqlite3
 from datetime import datetime, timedelta
 
+import Tkinter
+root = Tkinter.Tk()
+root.withdraw() # to hide the Tk GUI window as per http://stackoverflow.com/a/1796726
+
+from tkFileDialog import asksaveasfilename, askopenfilename
+
 def Note(message): # not writing world.Note everywhere ^_^
     world.Note(message)
 
-AppData = os.environ['APPDATA']
-DBPath = os.path.join(AppData, 'MUSHClient')
-if not os.path.isdir(DBPath):
-    os.mkdir(DBPath)
-DBFile = "logs_%s.db" % world.GetInfo(3) # Hope people set their char name
-DBFile = os.path.join(DBPath, DBFile)
+DBFile = world.GetVariable("dbpath")
+if not DBFile:
+    while not (DBFile and len(DBFile) > 0):
+        DBFile = asksaveasfilename(defaultextension=".db", filetypes=[("SQLite3 database file", "*.db")])
+    world.SetVariable("dbpath", DBFile)
+    world.SaveState
+
 db = sqlite3.connect(DBFile)
 cursor = db.cursor()
 
    purpose="Message Database"
    date_written="2012-12-03 12:00:00"
    requires="4.62"
-   version="1.1"
+   version="1.2"
    >
 <description trim="y">
 <![CDATA[
 
 <script>
 <![CDATA[
-import os
 import sqlite3
 from datetime import datetime
 
+import Tkinter
+root = Tkinter.Tk()
+root.withdraw() # to hide the Tk GUI window as per http://stackoverflow.com/a/1796726
+
+from tkFileDialog import asksaveasfilename, askopenfilename
+
 def Note(message): # not writing world.Note everywhere ^_^
     world.Note(message)
 
-AppData = os.environ['APPDATA']
-DBPath = os.path.join(AppData, 'MUSHClient')
-if not os.path.isdir(DBPath):
-    os.mkdir(DBPath)
-DBFile = "messages_%s.db" % world.GetInfo(3) # Hope people set their char name
-DBFile = os.path.join(DBPath, DBFile)
+DBFile = world.GetVariable("dbpath")
+if not DBFile:
+    while not (DBFile and len(DBFile) > 0):
+        DBFile = asksaveasfilename(defaultextension=".db", filetypes=[("SQLite3 database file", "*.db")])
+    world.SetVariable("dbpath", DBFile)
+    world.SaveState
+
 db = sqlite3.connect(DBFile)
 cursor = db.cursor()
 
    purpose="News Database"
    date_written="2012-12-06 12:00:00"
    requires="4.62"
-   version="1.5"
+   version="1.6"
    >
 <description trim="y">
 <![CDATA[
 
 <script>
 <![CDATA[
-import os
 import sqlite3
 import cPickle
 from datetime import datetime
 def Note(message): # not writing world.Note everywhere ^_^
     world.Note(message)
 
-AppData = os.environ['APPDATA']
-DBPath = os.path.join(AppData, 'MUSHClient')
-if not os.path.isdir(DBPath):
-    os.mkdir(DBPath)
-DBFile = "news_%s.db" % world.GetInfo(3) # Hope people set their char name
-DBFile = os.path.join(DBPath, DBFile)
+DBFile = world.GetVariable("dbpath")
+if not DBFile:
+    while not (DBFile and len(DBFile) > 0):
+        DBFile = asksaveasfilename(defaultextension=".db", filetypes=[("SQLite3 database file", "*.db")])
+    world.SetVariable("dbpath", DBFile)
+    world.SaveState
+
 db = sqlite3.connect(DBFile)
 cursor = db.cursor()