Skip to content

Commit

Permalink
don't multiply utf-8 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebig committed Jun 9, 2014
1 parent 04af0c0 commit 9a06d9e
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions examples/sqlite_py_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self):

self.font_size = 10
self.font_wheight = 0
# self.chg_size()
# With a Menubar and Toolbar
self.create_menu()
self.create_toolbar()
Expand Down Expand Up @@ -87,7 +86,7 @@ def create_menu(self):
self.menu_help.add_command(label='about',
command=lambda: messagebox.showinfo(message="""
\nSqlite_py_manager : a graphic SQLite Client in 1 Python file
\nversion 2014-06-09a : 'The magic 8th PEP'
\nversion 2014-06-09b : 'The magic 8th PEP'
\n(https://github.com/stonebig/baresql/blob/master/examples)"""))

def create_toolbar(self):
Expand All @@ -96,7 +95,7 @@ def create_toolbar(self):
self.toolbar.pack(side=TOP, fill=X)
self.tk_icon = self.get_tk_icons()

# list of image, action, tootip :
# list of (image, action, tooltip) :
to_show = [
('refresh_img', self.actualize_db, "Actualize Databases"),
('run_img', self.run_tab, "Run Script Selection"),
Expand Down Expand Up @@ -170,11 +169,10 @@ def savdb_script(self):
title="save database structure in a text file",
filetypes=[("default", "*.sql"), ("other", "*.txt"),
("all", "*.*")])
if filename == '':
return
with io.open(filename, 'w', encoding='utf-8') as f:
for line in self.conn.iterdump():
f.write('%s\n' % line)
if filename != '':
with io.open(filename, 'w', encoding='utf-8') as f:
for line in self.conn.iterdump():
f.write('%s\n' % line)

def sav_script(self):
"""save a script in a file"""
Expand All @@ -188,11 +186,11 @@ def sav_script(self):
title="save script in a sql file",
filetypes=[("default", "*.sql"), ("other", "*.txt"),
("all", "*.*")])
if filename == "":
return
with io.open(filename, 'w', encoding='utf-8') as f:
f.write("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
f.write(script)
if filename != "":
with io.open(filename, 'w', encoding='utf-8') as f:
if "你好 мир Artisou à croute" not in script:
f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
f.write(script)

def attach_db(self):
"""attach an existing database"""
Expand Down Expand Up @@ -283,7 +281,8 @@ def exsav_script(self):
if filename == "":
return
with io.open(filename, 'w', encoding='utf-8') as f:
f.write("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
if "你好 мир Artisou à croute" not in script:
f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
self.create_and_add_results(script, active_tab_id, limit=99, log=f)
fw.focus_set() # workaround bug http://bugs.python.org/issue17511

Expand Down Expand Up @@ -329,7 +328,7 @@ def get_tk_icons(self):
# to create this base 64 from a toto.gif image of 24x24 size do :
# import base64
# b64 = base64.encodestring(open(r"toto.gif","rb").read())
# print("'gif_img':'''\\\n" + b64.decode("utf8") + "'''")
# print("'gif_img': '''\\\n" + b64.decode("utf8") + "'''")
icons = {
'run_img': '''\
R0lGODdhGAAYAJkAADOqM////wCqMwAAACwAAAAAGAAYAAACM4SPqcvt7wJ8oU5W8025b9OFW0hO
Expand Down Expand Up @@ -404,10 +403,7 @@ def get_tk_icons(self):
xlzceksqu6ET7JwtLRrhwNt+1HdDUQAAOw==
'''
}
# transform 'in place' base64 icons into tk_icons
for key, value in icons.items():
icons[key] = PhotoImage(data=value)
return icons
return {k: PhotoImage(data=v) for k, v in icons.items()}

def createToolTip(self, widget, text):
"""create a tooptip box for a widget."""
Expand Down Expand Up @@ -1123,8 +1119,8 @@ def close(self):

def iterdump(self):
"""dump the database (add tweaks over the default dump)"""
# force detection of utf-8
yield("/*utf-8 bug safety : 你好 мир Artisou à croute blonde*/\n")
# force detection of utf-8 by placing an only utf-8 comment at top
yield("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
# add the Python functions pydef
for k in self.conn_def.values():
yield(k['pydef'] + ";\n")
Expand All @@ -1141,7 +1137,7 @@ def iterdump(self):
for row in self.conn.execute("PRAGMA foreign_keys"):
flag = 'ON' if row[0] == 1 else 'OFF'
yield("PRAGMA foreign_keys = %s;/*if SQlite*/;" % flag)
yield("PRAGMA foreign_keys = %s;/*if SQlite, twice*/;" % flag)
yield("PRAGMA foreign_keys = %s;/*if SQlite bug*/;" % flag)
yield("PRAGMA foreign_key_check;/*if SQLite, check*/;")
yield("\n/*SET foreign_key_checks = %s;/*if Mysql*/;\n" % row[0])

Expand Down

0 comments on commit 9a06d9e

Please sign in to comment.