Skip to content

Commit

Permalink
v1.4.1: finished version checker + cleaned up code (useless Style and…
Browse files Browse the repository at this point in the history
… remove wildcard imports)
  • Loading branch information
j4321 committed Apr 9, 2017
1 parent d413cc2 commit fcf230a
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 189 deletions.
12 changes: 2 additions & 10 deletions BraceletGenerator/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"""

from tkinter import Text, Toplevel
from tkinter.ttk import Button, Label, Style
from BraceletGenerator.constantes import open_image, BG_COLOR, STYLE, VERSION, IM_ICON48, set_icon, webOpen
from tkinter.ttk import Button, Label
from BraceletGenerator.constantes import open_image, BG_COLOR, VERSION, IM_ICON48, set_icon, webOpen


class About(Toplevel):
Expand All @@ -40,10 +40,6 @@ def __init__(self, master, **options):

set_icon(self)

self.style = Style(self)
self.style.theme_use(STYLE)
self.style.configure('TButton', background=BG_COLOR)
self.style.configure('TLabel', background=BG_COLOR)
self.image = open_image(file=IM_ICON48, master=self)
Label(self, image=self.image).grid(row=0, columnspan=2, pady=10)

Expand Down Expand Up @@ -84,10 +80,6 @@ def close():
fen.grab_set()
fen.configure(bg=BG_COLOR)
set_icon(fen)
style = Style(fen)
style.theme_use(STYLE)
style.configure('TButton', background=BG_COLOR)
style.configure('TLabel', background=BG_COLOR)

texte = Text(fen, width=50, height=18)
texte.pack()
Expand Down
10 changes: 5 additions & 5 deletions BraceletGenerator/bicolore.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def __init__(self, master, row_nb=10, string_nb=8,
self.log_nb_ligne = 2 # nombre de lignes du fichier log

# style
style = Style(self)
style.theme_use(cst.STYLE)
style.configure('TButton', background=cst.BG_COLOR)
style.configure('TLabel', background=cst.BG_COLOR)
style.configure('TFrame', background=cst.BG_COLOR)
# style = Style(self)
# style.theme_use(cst.STYLE)
# style.configure('TButton', background=cst.BG_COLOR)
# style.configure('TLabel', background=cst.BG_COLOR)
# style.configure('TFrame', background=cst.BG_COLOR)

# menu
self.m_plus = cst.open_image(file=cst.IM_PLUS_M, master=self)
Expand Down
19 changes: 19 additions & 0 deletions BraceletGenerator/bracelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from BraceletGenerator.couleurs import Couleurs
from BraceletGenerator.bicolore import Bicolore
from BraceletGenerator.about import About
from BraceletGenerator.version_check import UpdateChecker


class Bracelet(Tk):
Expand All @@ -61,10 +62,16 @@ def __init__(self, row_nb=4, string_nb=4, color="#ff0000", fichier=""):
self.style = Style(self)
self.style.theme_use(cst.STYLE)
self.style.configure('TButton', background=cst.BG_COLOR)
self.style.configure('TCheckbutton', background=cst.BG_COLOR)
self.style.configure('TLabel', background=cst.BG_COLOR)
self.style.configure('TFrame', background=cst.BG_COLOR)
self.style.configure('flat.TButton', relief="flat",
background=cst.BG_COLOR)
self.style.map('flat.TButton',
background=[("disabled", cst.BG_COLOR),
("active", "!disabled",
self.style.lookup("TButton", "background",
state=("active", "!disabled")))])
self.style.configure("test.TButton", padding=2)

### menu
Expand Down Expand Up @@ -194,6 +201,10 @@ def __init__(self, row_nb=4, string_nb=4, color="#ff0000", fichier=""):
self.menu_help.add_command(label=_("Online Help"), image=self.m_help,
command=cst.help_web, compound="left",
accelerator="Ctrl+F1")
self.menu_help.add_separator()
self.menu_help.add_command(label=_("Check for updates"),
command=lambda: UpdateChecker(self))
self.menu_help.add_separator()
self.menu_help.add_command(label=_("About"), image=self.m_about,
command=self.about, compound="left")

Expand Down Expand Up @@ -357,6 +368,10 @@ def __init__(self, row_nb=4, string_nb=4, color="#ff0000", fichier=""):
else:
self.path_save = "" # saved pattern path

### Update check
if cst.CONFIG.getboolean("General", "check_update"):
UpdateChecker(self)

def __setattr__(self, name, value):
""" gestion de la modification attributs, en particulier
les nombres de fils et de lignes ainsi que la sauvegarde """
Expand All @@ -370,6 +385,10 @@ def __setattr__(self, name, value):
dico = {"True":"disabled", "False":"normal"}
self.save_button.configure(state=dico[str(value)])
self.menu_file.entryconfigure(5, state=dico[str(value)])
elif name == "path_save":
if not value:
self.save_button.configure(state="disabled")
self.menu_file.entryconfigure(5, state="disabled")

object.__setattr__(self, name, value)

Expand Down
34 changes: 31 additions & 3 deletions BraceletGenerator/constantes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
IM_QUESTION_DATA was taken from "icons.tcl":
IM_QUESTION_DATA and IM_WARNING_DATA was taken from "tk8.6/icons.tcl":
A set of stock icons for use in Tk dialogs. The icons used here
were provided by the Tango Desktop project which provides a
Expand All @@ -31,7 +31,7 @@
Copyright (c) 2009 Pat Thoyts <patthoyts@users.sourceforge.net>
Most of the other icons are modified versions of icons from the elementary project
Copyright 2007-2013 elementary LLC, except a few I made myself.
Copyright 2007-2013 elementary LLC, except a few I designed myself.
Constants and global functions of Bracelet Generator
Expand Down Expand Up @@ -247,6 +247,34 @@ def save_config():
SUVORK5CYII=
"""

IM_WARNING_DATA = """
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAABSZJREFU
WIXll1toVEcYgL+Zc87u2Yu7MYmrWRuTJuvdiMuqiJd4yYKXgMQKVkSjFR80kFIVJfWCWlvpg4h9
8sXGWGof8iKNICYSo6JgkCBEJRG8ImYThNrNxmaTeM7pQ5IlJkabi0/9YZhhZv7///4z/8zPgf+7
KCNRLgdlJijXwRyuDTlcxV9hbzv8nQmxMjg+XDtiOEplkG9PSfkztGmTgmFQd+FCVzwa3fYN/PHZ
AcpBaReicW5xcbb64IEQqko8Lc26d/58cxS+/BY6hmJvyEfQBoUpwWCmW1FErKaGWHU13uRk4QkE
UtxQNFR7QwIoB4eiKD9PWbVKbb10CZmaCqmpxCormRYO26QQx85B0mcD+AeK0xYvHqu1tNDx+DH6
gQM4jh0j3tCA3tGBLyfHLuD7zwJwAcYqun44sHy51nr5MsqsWWj5+djCYdS5c4ldvUr24sU2qarf
lUL6qAN0wqH0vDy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Yt/fNlxGK8eUNSerryHEJHQT8K8V4A5ztojty8OeaLzZul
1DSwLCzDANPEMozusWFgmWZ33288YK3/nGlixuM0v3xpWfDX0Z4i1VupXEWwIgRnJfhGPfQ+YsLr
+7DzNFwCuvqWyiRg7DSYoIBu9smPkYqEd4AwIN4ITUAL0A4Da7UC6ICdEfy2fUBMoAvo7GnWKNoe
mfwLcAuinuFNL7QAAAAASUVORK5CYII=
"""

### colors
if platform == 'darwin' or PL == 'nt':
BG_COLOR = '#F0F0F0'
Expand Down Expand Up @@ -343,7 +371,7 @@ def help_web(event=None):
from PIL import Image, ImageTk
from BraceletGenerator.custom_messagebox import ob_checkbutton
if not CONFIG.has_option("General", "old_tcl_warning") or CONFIG.getboolean("General", "old_tcl_warning"):
ans = ob_checkbutton(title=_("Information"), style=STYLE,
ans = ob_checkbutton(title=_("Information"), image=IM_WARNING_DATA,
message=_("This software has been developped using Tcl/Tk 8.6, but you are using an older version. Please consider upgrading your Tcl/Tk version."),
checkmessage=_("Do not show this message again."))
CONFIG.set("General", "old_tcl_warning", str(not ans))
Expand Down
11 changes: 2 additions & 9 deletions BraceletGenerator/couleurs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"""

from tkinter import Toplevel, Canvas, PhotoImage
from tkinter.ttk import Button, Label, Style, Separator, Frame
from BraceletGenerator.constantes import BG_COLOR, STYLE, MOUSEWHEEL, set_icon, mouse_wheel, fill, askcolor, LANG
from tkinter.ttk import Button, Label, Separator, Frame
from BraceletGenerator.constantes import BG_COLOR, MOUSEWHEEL, set_icon, mouse_wheel, fill, askcolor, LANG
from BraceletGenerator.scrollbar import AutoScrollbar as Scrollbar

class Couleurs(Toplevel):
Expand Down Expand Up @@ -54,13 +54,6 @@ def __init__(self, master, coul_def, colors, **options):
# Icône
set_icon(self)

### Style
style = Style(self)
style.theme_use(STYLE)
style.configure('TButton', background=BG_COLOR)
style.configure('TLabel', background=BG_COLOR)
style.configure('TFrame', background=BG_COLOR)

### Contenu :
self.can = Canvas(self,bg=BG_COLOR) # pour utiliser une scrollbar
self.can.grid(row=0, column=0, sticky="nswe")
Expand Down
43 changes: 27 additions & 16 deletions BraceletGenerator/custom_messagebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
"""


from tkinter import Toplevel, BooleanVar, Tk
from tkinter.ttk import Label, Button, Style, Checkbutton
from tkinter import BooleanVar, Tk, PhotoImage, TclError
from tkinter.ttk import Label, Button, Checkbutton, Style
from BraceletGenerator.constantes import STYLE

class OBCheckbutton(Tk):
""" Messagebox with only one button and a checkbox below the button
for instance to add a 'Do not show this again' option """

def __init__(self, title="", message="", button="Ok", image=None,
checkmessage="", style="clam", **options):
checkmessage="", **options):
"""
Create a messagebox with one button and a checkbox below the button:
parent: parent of the toplevel window
Expand All @@ -44,28 +45,38 @@ def __init__(self, title="", message="", button="Ok", image=None,
Tk.__init__(self, **options)
self.title(title)
self.resizable(False, False)
s = Style(self)
s.theme_use(style)
if image:
Label(self, text=message, wraplength=335,
font="Sans 11", compound="left", image=image).grid(row=0, padx=10, pady=(10,0))
else:
Label(self, text=message, wraplength=335,
font="Sans 11").grid(row=0, padx=10, pady=(10,0))
self.columnconfigure(1, weight=1)
self.rowconfigure(0, weight=1)

style = Style(self)
style.theme_use(STYLE)
self.img = None
if isinstance(image, str):
try:
self.img = PhotoImage(file=image)
except TclError:
self.img = PhotoImage(data=image)
elif image:
self.img = image
if self.img:
Label(self, image=self.img).grid(row=0, column=0, padx=10, pady=(10,0))
Label(self, text=message, wraplength=335,
font="TkDefaultFont 10 bold").grid(row=0, column=1,
padx=10, pady=(10,0))
b = Button(self, text=button, command=self.destroy)
b.grid(row=2, padx=10, pady=10)
b.grid(row=2, padx=10, pady=10, columnspan=2)
self.var = BooleanVar(self)
c = Checkbutton(self, text=checkmessage, variable=self.var)
c.grid(row=1, padx=10, pady=0, sticky="e")
c.grid(row=1, padx=10, pady=4, sticky="e", columnspan=2)
self.grab_set()
b.focus_set()
self.wait_window(self)

def get_check(self):
return self.var.get()

def ob_checkbutton(title="", message="", button="Ok", image=None,
checkmessage="", style="clam", **options):
checkmessage="", **options):
""" Open a OBCheckbutton and return the value of the checkbutton when closed. """
ob = OBCheckbutton(title, message, button, image, checkmessage, style, **options)
ob = OBCheckbutton(title, message, button, image, checkmessage, **options)
ob.wait_window(ob)
return ob.get_check()
Binary file modified BraceletGenerator/locale/en_US/LC_MESSAGES/BraceletGenerator.mo
Binary file not shown.
Binary file modified BraceletGenerator/locale/fr_FR/LC_MESSAGES/BraceletGenerator.mo
Binary file not shown.
14 changes: 8 additions & 6 deletions BraceletGenerator/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from webbrowser import open as webOpen
from tkinter import Toplevel, PhotoImage
from tkinter.ttk import Label, Button, Frame, Checkbutton
from BraceletGenerator.constants import VERSION, CONFIG, save_config, IM_QUESTION_DATA
from BraceletGenerator.constantes import VERSION, CONFIG, save_config
from BraceletGenerator.constantes import BG_COLOR, IM_QUESTION_DATA


class VersionParser(HTMLParser):
Expand Down Expand Up @@ -66,26 +67,27 @@ def __init__(self, master):
self.columnconfigure(1, weight=1)
self.protocol("WM_DELETE_WINDOW", self.quit)

self.configure(background=BG_COLOR)

self.img = PhotoImage(data=IM_QUESTION_DATA, master=self)

frame = Frame(self)
frame.grid(row=0, columnspan=2, sticky="ewsn")
Label(frame, image=self.img).pack(side="left", padx=(10, 4), pady=(10, 4))
Label(frame,
text=_("A new version of Bracelet Generator is available.\
\nDo you want to download it?"),
text=_("A new version of Bracelet Generator is available. Do you want to download it?"),
font="TkDefaultFont 10 bold",
wraplength=335).pack(side="left", padx=(4, 10), pady=(10, 4))

self.b1 = Button(self, text=_("Yes"), command=self.download)
self.b1.grid(row=1, column=0, padx=10, pady=10, sticky="e")
Button(self, text=_("No"), command=self.quit).grid(row=1, column=1,
padx=10, pady=10,
sticky="w")
padx=10, pady=10,
sticky="w")
self.ch = Checkbutton(self, text=_("Check for updates on startup."))
if CONFIG.getboolean("General", "check_update"):
self.ch.state(("selected", ))
self.ch.grid(row=2, columnspan=2, sticky='w')
self.ch.grid(row=2, columnspan=2, sticky='e')
self.update = None

self.thread = Thread(target=self.update_available, daemon=True)
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
include *.txt *.rst *.py bracelet-generator.*
include BraceletGenerator/locale/fr_FR/LC_MESSAGES/BraceletGenerator.mo
include BraceletGenerator/locale/en_US/LC_MESSAGES/BraceletGenerator.mo
recursive-include examples *
recursive-include BraceletGenerator/images *
recursive-include BraceletGenerator/doc *
Expand Down
3 changes: 3 additions & 0 deletions bracelet-generator
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ try:
finally: # remove logs even if the app crashed to avoid accumulation
try:
os.remove(BRACELET_LOG)
except FileNotFoundError:
pass
try:
os.remove(BICOLOR_LOG)
except FileNotFoundError:
pass
Expand Down
19 changes: 13 additions & 6 deletions bracelet-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@
main
"""


import sys
import os
from BraceletGenerator.constantes import CONFIG, BRACELET_LOG, BICOLOR_LOG, save_config
from BraceletGenerator.bracelet import Bracelet

try:
if len(sys.argv) == 1:
Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"),
row_nb=CONFIG.getint("Bracelet", "row_nb"),
color=CONFIG.get("Bracelet", "default_color"))
app = Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"),
row_nb=CONFIG.getint("Bracelet", "row_nb"),
color=CONFIG.get("Bracelet", "default_color"))
else:
fichier = os.path.realpath(sys.argv[1])
app = Bracelet(fichier=fichier)
app.mainloop()
app.mainloop()
finally: # remove logs even if the app crashed to avoid accumulation
os.remove(BRACELET_LOG)
os.remove(BICOLOR_LOG)
try:
os.remove(BRACELET_LOG)
except FileNotFoundError:
pass
try:
os.remove(BICOLOR_LOG)
except FileNotFoundError:
pass
save_config()
9 changes: 5 additions & 4 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Copyright 2014-2017 Juliette Monsel <j_4321@protonmail.com>

- Update checker

2. Bug correction
2. Bug corrections

- Log not removed when app crashes
- App was not runnable locally on linux
- Save button not disabled when new bracelet started
- Changed symmetrize icons for license reason

- Version 1.4.0

Expand All @@ -22,8 +23,8 @@ Copyright 2014-2017 Juliette Monsel <j_4321@protonmail.com>

2. Bug correction

- mouse-scrolling in Windows
- mouse button bindings in OS X
- Mouse-scrolling in Windows
- Mouse button bindings in OS X
- Added script to add Ghostscript path to the system path variable
in Windows because PIL cannot always find it.

Expand Down
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bracelet-generator (1.4.1-1) unstable; urgency=low
* New feature: update checker
* Bug correction: log not removed when app crashes
* Bug correction: app was not runnable locally on linux
* Bug correction: save button not disabled when new bracelet started

-- Juliette Monsel <j_4321@protonmail.com> Sat, 14 Jan 2017 17:57:54 +0100

Expand Down
Loading

0 comments on commit fcf230a

Please sign in to comment.