Skip to content

Commit

Permalink
version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
j4321 committed Apr 8, 2017
1 parent 6ffa8e4 commit d413cc2
Show file tree
Hide file tree
Showing 23 changed files with 949 additions and 686 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
build
*.egg-info
deb_dist
.spyproject
263 changes: 132 additions & 131 deletions BraceletGenerator/bicolore.py

Large diffs are not rendered by default.

288 changes: 130 additions & 158 deletions BraceletGenerator/bracelet.py

Large diffs are not rendered by default.

210 changes: 133 additions & 77 deletions BraceletGenerator/constantes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
IM_QUESTION_DATA was taken from "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
unified set of high quality icons licensed under the
Creative Commons Attribution Share-Alike license
(http://creativecommons.org/licenses/by-sa/3.0/)
See http://tango.freedesktop.org/Tango_Desktop_Project
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.
Constants and global functions of Bracelet Generator
"""

VERSION = "1.4.0"
VERSION = "1.4.1"

STYLE = 'clam'

Expand All @@ -39,53 +55,46 @@
from tkinter import filedialog
from tkinter import colorchooser

# Traduction

APP_NAME = "BraceletGenerator"

# Get the local directory
if platform == 'linux' and os.path.exists("/usr/share/bracelet-generator"):
# the app has been installed
### paths
PATH = os.path.split(__file__)[0]
if platform == 'linux' and (not os.access(PATH, os.W_OK) or not os.path.exists(os.path.join(PATH, "images"))):
IMAGES_LOCATION = '/usr/share/bracelet-generator/images'
PATH_LOCALE = "/usr/share/locale"
DOC = '/usr/share/doc/bracelet-generator/doc_install_linux.html'
DOC_FR = '/usr/share/doc/bracelet-generator/doc_fr_install_linux.html'
else:
PATH = os.path.split(__file__)[0]
IMAGES_LOCATION = os.path.join(PATH, 'images')
PATH_LOCALE = os.path.join(PATH, "locale")
DOC = os.path.join(PATH, "doc", "doc.html")
DOC_FR = os.path.join(PATH, "doc", "doc_fr.html")

LOCAL_PATH = os.path.expanduser("~")
LOCAL_PATH = os.path.join(LOCAL_PATH, "BraceletGenerator")
LOCAL_PATH = os.path.join(os.path.expanduser("~"), "BraceletGenerator")
if not os.path.exists(LOCAL_PATH):
os.mkdir(LOCAL_PATH)

# temporary file
TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps")
# config file
PATH_CONFIG = os.path.join(LOCAL_PATH, 'BraceletGenerator.ini')
# bracelet log file
BRACELET_LOG = os.path.join(LOCAL_PATH, "BraceletGenerator%i.log")
i = 0
while os.path.exists(BRACELET_LOG % (i)):
i += 1
BRACELET_LOG %= i

# temporary file
TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps")

# bicolore log file
BICOLOR_LOG = os.path.join(LOCAL_PATH, "Bicolor%i.log")
i = 0
while os.path.exists(BICOLOR_LOG % (i)):
i += 1
BICOLOR_LOG %= i

PATH_CONFIG = os.path.join(LOCAL_PATH, 'BraceletGenerator.ini')

# configuration file
### configuration file
CONFIG = ConfigParser()
if os.path.exists(PATH_CONFIG):
CONFIG.read(PATH_CONFIG)
LANGUE = CONFIG.get("General","language")
if not CONFIG.has_option("General", "check_update"):
CONFIG.set("General", "check_update", "True")
else:
LANGUE = ""

Expand All @@ -94,12 +103,23 @@
CONFIG.set("General", "recent_files", "")
CONFIG.set("General", "recent_bicolor", "")
CONFIG.set("General", "language", "en")
CONFIG.set("General", "check_update", "True")

CONFIG.add_section("Bracelet")
CONFIG.set("Bracelet", "row_nb", "4")
CONFIG.set("Bracelet", "string_nb", "4")
CONFIG.set("Bracelet", "default_color", "#ff0000")

def save_config():
""" sauvegarde du dictionnaire contenant la configuration du logiciel (langue ...) """
CONFIG.set("General", "recent_files", ",".join(RECENT_FILES))
CONFIG.set("General", "recent_bicolor", ",".join(RECENT_BICOLOR))
with open(PATH_CONFIG, 'w') as fichier:
CONFIG.write(fichier)

### Translation
APP_NAME = "BraceletGenerator"

if LANGUE not in ["en", "fr"]:
# Check the default locale
lc = getdefaultlocale()[0][:2]
Expand All @@ -118,15 +138,15 @@
languages=[LANGUE], fallback=True)
LANG.install()

# get recent files
### get recent files
RECENT_FILES = CONFIG.get("General", "recent_files").split(",")
if RECENT_FILES == [""]:
RECENT_FILES = []
RECENT_BICOLOR = CONFIG.get("General", "recent_bicolor").split(",")
if RECENT_BICOLOR == [""]:
RECENT_BICOLOR = []

# pictures
### pictures
IM_EXIT_M = os.path.join(IMAGES_LOCATION, "exit_m.png")
IM_EXIT = os.path.join(IMAGES_LOCATION, "exit.png")
IM_EXPORT_M = os.path.join(IMAGES_LOCATION, "export_m.png")
Expand Down Expand Up @@ -184,7 +204,50 @@
IM_SYM_HORIZ_M = os.path.join(IMAGES_LOCATION, "sym_horizontal_m.png")
IM_SYM_VERT_M = os.path.join(IMAGES_LOCATION, "sym_vertical_m.png")

# colors
IM_QUESTION_DATA = """
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAACG5JREFU
WIXFl3twVdUVxn97n3Nubm7euZcghEdeBBICEQUFIgVECqIo1uJMp3WodqyjMzpjZ7TTh20cK31N
/2jL2FYdKXaqRcbnDKGpoBFaAY1BHgHMgyRKQkJy87yv3Nyzd/84594k1RlppzPumTXn3Dl3r/Wd
b31rrbPhS17iSv+4bl2t2ZFhrRGI7QKxRkMAyHEfjwgYEOgjNnpfcXjiSENDbeL/AqBoW22uGE/7
MYL7yubN4MYVpVkrquaKqwJZ+LPTARgcjdIbHKOx+aI+9EH7WGvnZdA8q9PGf9b5eu3w/wygaPPO
h6Uhntxcsyj9/q+vtMrnBa6Is7ZPgzzzyvGJ/YfPRpWWj3fWff93/xWAonW1Xu3z/nVx6cxNTz74
1YzK4gIQjuN/nfyEEx9fIjgaYXAkhhAQyE3Hn5PBsvJZrF46l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RL8QAOADsgvXfu9B
b3bgkTs3LPN+52srzPlX5V7RUerTy6M8/0Zj4uUDH45Hg13PdB/9425gzLUhQH0RgDQgC8hKLyid
7a/c9oCV4d9WVTpLbF5TmX5tRaGYkecjJ8MLAkZD4wyMRGg636PrDjfHzrT26NhYT33w1Kt/Hh/u
6XUDh4BBIHwlDIBTohlANpBhWb6s7PKNK30FCzZa6dnVYORoIX2OExVF26Px8NCZSN/5d0bb3mlK
JGIhHLpDwLAL4jPnxSs9nBqABXhddrw4XdRygSrABuKuxYBx9/6KDqlf2vo3PYe56vmkuwMAAAAA
SUVORK5CYII=
"""

### colors
if platform == 'darwin' or PL == 'nt':
BG_COLOR = '#F0F0F0'
CANVAS_COLOR = "#ffffff"
Expand All @@ -193,7 +256,50 @@
CANVAS_COLOR = '#E8E8E8'


# platform dependent mouse events
def active_color(color):
""" pâlit la color (en format hexadécimal "#000000") """
coul = color[1:]
rouge = int(coul[:2], 16)
vert = int(coul[2:4], 16)
bleu = int(coul[4:], 16)
if bleu > rouge:
rouge2 = min(rouge + 40, 255)
if bleu > vert:
vert2 = min(vert + 40, 255)
bleu2 = bleu
else:
bleu2 = min(bleu + 40, 255)
vert2 = vert
elif rouge > bleu:
bleu2 = min(bleu + 40, 255)
if rouge > vert:
vert2 = min(vert + 40, 255)
rouge2 = rouge
else:
rouge2 = min(rouge + 40, 255)
vert2 = vert
elif vert > bleu:
vert2 = vert
bleu2 = min(bleu + 40, 255)
rouge2 = min(rouge + 40, 255)
elif vert < bleu:
vert2 = min(vert + 40, 255)
bleu2 = bleu
rouge2 = min(rouge + 40, 255)
else: # rouge = vert = bleu
rouge2 = min(rouge + 40, 255)
vert2 = rouge2
bleu2 = rouge2
return "#" + hex(rouge2)[2:] + hex(vert2)[2:] + hex(bleu2)[2:]

def fill(image, color):
"""Fill image with a color=#hex."""
width = image.width()
height = image.height()
horizontal_line = "{" + " ".join([color]*width) + "}"
image.put(" ".join([horizontal_line]*height))

### platform dependent mouse events
if PL == "nt":
def mouse_wheel(event):
""" gestion de la molette de la souris sous windows """
Expand All @@ -216,30 +322,22 @@ def mouse_wheel(event):
MOUSEWHEEL = ["<Button - 4>", "<Button - 5>"]
RIGHT_CLICK = '<Button-3>'



def save_config():
""" sauvegarde du dictionnaire contenant la configuration du logiciel (langue ...) """
CONFIG.set("General", "recent_files", ",".join(RECENT_FILES))
CONFIG.set("General", "recent_bicolor", ",".join(RECENT_BICOLOR))
with open(PATH_CONFIG, 'w') as fichier:
CONFIG.write(fichier)

### display help
def help(event=None):
""" ouvre l'aide en .html dans la langue de l'interface """
if LANGUE[:2] == "fr":
webOpen(DOC_FR)
else:
webOpen(DOC)


def help_web(event=None):
""" ouvre l'aide en ligne dans la langue de l'interface """
if LANGUE[:2] == "fr":
webOpen("https://braceletgenerator.sourceforge.io/index_fr.html")
else:
webOpen("https://braceletgenerator.sourceforge.io/")

### compatibility with tcl8.5
if TclVersion < 8.6:
# then tkinter cannot import PNG files directly, we need to use PIL
from PIL import Image, ImageTk
Expand All @@ -258,6 +356,7 @@ def open_image(file, master=None):
def open_image(file, master=None):
return PhotoImage(file=file, master=master)

### icon
def set_icon(fen):
""" icône de l'application """
if PL == 'nt':
Expand All @@ -266,50 +365,7 @@ def set_icon(fen):
icon = open_image(file=IM_ICON16, master=fen)
fen.iconphoto(True, icon)


def active_color(color):
""" pâlit la color (en format hexadécimal "#000000") """
coul = color[1:]
rouge = int(coul[:2], 16)
vert = int(coul[2:4], 16)
bleu = int(coul[4:], 16)
if bleu > rouge:
rouge2 = min(rouge + 40, 255)
if bleu > vert:
vert2 = min(vert + 40, 255)
bleu2 = bleu
else:
bleu2 = min(bleu + 40, 255)
vert2 = vert
elif rouge > bleu:
bleu2 = min(bleu + 40, 255)
if rouge > vert:
vert2 = min(vert + 40, 255)
rouge2 = rouge
else:
rouge2 = min(rouge + 40, 255)
vert2 = vert
elif vert > bleu:
vert2 = vert
bleu2 = min(bleu + 40, 255)
rouge2 = min(rouge + 40, 255)
elif vert < bleu:
vert2 = min(vert + 40, 255)
bleu2 = bleu
rouge2 = min(rouge + 40, 255)
else: # rouge = vert = bleu
rouge2 = min(rouge + 40, 255)
vert2 = rouge2
bleu2 = rouge2
return "#" + hex(rouge2)[2:] + hex(vert2)[2:] + hex(bleu2)[2:]

def fill(image, color):
"""Fill image with a color=#hex."""
width = image.width()
height = image.height()
horizontal_line = "{" + " ".join([color]*width) + "}"
image.put(" ".join([horizontal_line]*height))

### filebrowser
ZENITY = False
if PL != "nt":
paths = os.environ['PATH'].split(":")
Expand Down
Loading

0 comments on commit d413cc2

Please sign in to comment.