Skip to content

Commit 0bf3786

Browse files
authored
Merge pull request #876 from mathoudebine/dev/common-python-version-check
2 parents 71d1b8b + b07ca8f commit 0bf3786

File tree

7 files changed

+52
-42
lines changed

7 files changed

+52
-42
lines changed

configure.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
# This file is the system monitor configuration GUI
2323

24+
from library.pythoncheck import check_python_version
25+
check_python_version()
26+
2427
import glob
2528
import os
2629
import platform
@@ -30,14 +33,6 @@
3033
import requests
3134
import babel
3235

33-
MIN_PYTHON = (3, 9)
34-
if sys.version_info < MIN_PYTHON:
35-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
36-
try:
37-
sys.exit(0)
38-
except:
39-
os._exit(0)
40-
4136
try:
4237
import tkinter.ttk as ttk
4338
from tkinter import *

library/pythoncheck.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
#
3+
# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
4+
# https://github.com/mathoudebine/turing-smart-screen-python/
5+
#
6+
# Copyright (C) 2021 Matthieu Houdebine (mathoudebine)
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
# This file is used to check if Python version used is compatible
22+
import os
23+
import sys
24+
25+
# Oldest / newest version supported
26+
MIN_PYTHON = (3, 9)
27+
MAX_PYTHON = (3, 13)
28+
29+
30+
def check_python_version():
31+
current_version = sys.version_info[:2]
32+
33+
if current_version < MIN_PYTHON or current_version > MAX_PYTHON:
34+
print(f"[ERROR] Python {current_version[0]}.{current_version[1]} is not supported by this program. "
35+
f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}-{MAX_PYTHON[0]}.{MAX_PYTHON[1]} required.")
36+
try:
37+
sys.exit(0)
38+
except:
39+
os._exit(0)

main.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,14 @@
2525
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2626

2727
# This file is the system monitor main program to display HW sensors on your screen using themes (see README)
28+
29+
from library.pythoncheck import check_python_version
30+
check_python_version()
31+
2832
import glob
2933
import os
3034
import sys
3135

32-
MIN_PYTHON = (3, 9)
33-
if sys.version_info < MIN_PYTHON:
34-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
35-
try:
36-
sys.exit(0)
37-
except:
38-
os._exit(0)
39-
4036
try:
4137
import atexit
4238
import locale

res/fonts/font-preview.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
# This file generate PNG previews for available fonts
2323

2424
import os
25-
import sys
26-
27-
MIN_PYTHON = (3, 9)
28-
if sys.version_info < MIN_PYTHON:
29-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
30-
try:
31-
sys.exit(0)
32-
except:
33-
os._exit(0)
34-
3525
from PIL import Image, ImageDraw, ImageFont
3626
import math
3727
from pathlib import Path

simple-program.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
# This file is a simple Python test program using the library code to display custom content on screen (see README)
2323

24+
from library.pythoncheck import check_python_version
25+
check_python_version()
26+
2427
import os
2528
import signal
2629
import sys

theme-editor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# theme-editor.py: Allow to easily edit themes for System Monitor (main.py) in a preview window on the computer
2323
# The preview window is refreshed as soon as the theme file is modified
2424

25+
from library.pythoncheck import check_python_version
26+
check_python_version()
27+
2528
import locale
2629
import logging
2730
import os
@@ -30,14 +33,6 @@
3033
import sys
3134
import time
3235

33-
MIN_PYTHON = (3, 8)
34-
if sys.version_info < MIN_PYTHON:
35-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
36-
try:
37-
sys.exit(0)
38-
except:
39-
os._exit(0)
40-
4136
try:
4237
import tkinter
4338
from PIL import ImageTk, Image

tools/turing-theme-extractor.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
PNG_SIGNATURE = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'
3030
PNG_IEND = b'\x49\x45\x4E\x44\xAE\x42\x60\x82'
3131

32-
MIN_PYTHON = (3, 8)
33-
if sys.version_info < MIN_PYTHON:
34-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
35-
try:
36-
sys.exit(0)
37-
except:
38-
os._exit(0)
39-
4032
if len(sys.argv) != 2:
4133
print("Usage :")
4234
print(" turing-theme-extractor.py path/to/theme-file.data")

0 commit comments

Comments
 (0)