Skip to content

Commit 8556504

Browse files
committed
[fix] Tkinter was still a dependency of crappy
1 parent e92d1e3 commit 8556504

File tree

10 files changed

+76
-27
lines changed

10 files changed

+76
-27
lines changed

crappy/blocks/dashboard.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
import threading
44
from queue import Queue
5-
from tkinter import Tk, Label
65
import numpy as np
76

87
from .block import Block
8+
from .._global import OptionalModule
9+
10+
try:
11+
from tkinter import Tk, Label
12+
except (ModuleNotFoundError, ImportError):
13+
Tk = OptionalModule("tkinter")
14+
Label = OptionalModule("tkinter")
915

1016

1117
class Dashboard(Block):

crappy/blocks/displayer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
from .block import Block
55
from .._global import CrappyStop
6-
import tkinter as tk
76
from .._global import OptionalModule
87

98
try:
@@ -22,6 +21,11 @@
2221
except (ModuleNotFoundError, ImportError):
2322
cv2 = OptionalModule("opencv-python")
2423

24+
try:
25+
import tkinter as tk
26+
except (ModuleNotFoundError, ImportError):
27+
tk = OptionalModule("tkinter")
28+
2529

2630
class Displayer(Block):
2731
"""Simple image displayer using :mod:`cv2` or :mod:`matplotlib`.
@@ -121,7 +125,7 @@ def check_resized(self):
121125
if new[0] > 0 and new[1] > 0:
122126
self.h, self.w = new
123127
ratio = min(self.h / self.img_shape[0],
124-
self.w / self.img_shape[1])
128+
self.w / self.img_shape[1])
125129
self.h = int(self.img_shape[0] * ratio)
126130
self.w = int(self.img_shape[1] * ratio)
127131

crappy/blocks/gui.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# coding: utf-8
22

3-
import tkinter as tk
43
from time import time
54

65
from .block import Block
76
from .._global import CrappyStop
7+
from .._global import OptionalModule
8+
9+
try:
10+
import tkinter as tk
11+
except (ModuleNotFoundError, ImportError):
12+
tk = OptionalModule("tkinter")
813

914

1015
class GUI(Block):

crappy/camera/cameralink.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
try:
66
from . import clModule as Cl
77
except ImportError:
8-
Cl = OptionalModule("clModule", "CameraLink module was not compiled. "
9-
"Please make sure /opt/SiliconSoftware/xxx/lib64 exists and reinstall Crappy")
8+
Cl = OptionalModule("clModule", "CameraLink module was not compiled. Please "
9+
"make sure /opt/SiliconSoftware/xxx/lib64 "
10+
"exists and reinstall Crappy")
1011
from time import time
1112

1213

crappy/inout/arduino.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# coding: utf-8
22

33
from threading import Thread
4-
import tkinter as tk
54
from queue import Queue as Queue_threading, Empty
65
from time import time
76
from collections import OrderedDict
87
from multiprocessing import Process, Queue
98
from ast import literal_eval
9+
from os.path import exists
1010

1111
from ..tool.GUI_Arduino.minitens import MinitensFrame
1212
from ..tool.GUI_Arduino.arduino_basics import MonitorFrame, SubmitSerialFrame
13-
1413
from .inout import InOut
1514
from .._global import CrappyStop
16-
from os.path import exists
1715

1816
from .._global import OptionalModule
1917

@@ -22,6 +20,11 @@
2220
except (ModuleNotFoundError, ImportError):
2321
serial = OptionalModule("pyserial")
2422

23+
try:
24+
import tkinter as tk
25+
except (ModuleNotFoundError, ImportError):
26+
tk = OptionalModule("tkinter")
27+
2528

2629
def collect_serial(arduino, queue):
2730
"""Collect serial information, in a parallel way."""

crappy/tool/GUI_Arduino/arduino_basics.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
Arduino IDE. One can see the serial port entrances, and can write in it.
66
"""
77

8-
import tkinter as tk
9-
from tkinter import font as tk_font
108
from queue import Empty
119

10+
from ..._global import OptionalModule
11+
12+
try:
13+
import tkinter as tk
14+
from tkinter import font as tk_font
15+
except (ModuleNotFoundError, ImportError):
16+
tk = OptionalModule("tkinter")
17+
tk_font = OptionalModule("tkinter")
18+
1219

1320
class MonitorFrame(tk.Frame):
1421
"""A frame that displays everything entering the serial port.
@@ -46,7 +53,7 @@ def create_widgets(self, **kwargs):
4653

4754
self.top_frame = tk.Frame(self)
4855
tk.Label(self.top_frame,
49-
text=kwargs.get('title', '')).grid(row=0, column=0)
56+
text=kwargs.get('title', '')).grid(row=0, column=0)
5057

5158
tk.Checkbutton(self.top_frame,
5259
variable=self.enabled_checkbox,
@@ -57,7 +64,7 @@ def create_widgets(self, **kwargs):
5764
height=int(self.total_width / 10),
5865
width=int(self.total_width),
5966
font=tk_font.Font(size=kwargs.get("fontsize",
60-
13)))
67+
13)))
6168

6269
self.top_frame.grid(row=0)
6370
self.serial_monitor.grid(row=1)

crappy/tool/GUI_Arduino/frame_objects.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# coding: utf-8
22

3-
import tkinter as tk
4-
from tkinter import ttk
3+
from ..._global import OptionalModule
4+
5+
try:
6+
import tkinter as tk
7+
from tkinter import ttk
8+
except (ModuleNotFoundError, ImportError):
9+
tk = OptionalModule("tkinter")
10+
ttk = OptionalModule("tkinter")
511

612

713
class FrameObjects(tk.Frame):
@@ -113,8 +119,9 @@ def add_entry(self, **kwargs):
113119
if not variable:
114120
setattr(self, entry_name + '_var', vartype)
115121
widgets_dict[entry_name] = tk.Entry(frame,
116-
textvariable=getattr(self, entry_name +
117-
'_var'),
122+
textvariable=getattr(self,
123+
entry_name +
124+
'_var'),
118125
width=width)
119126
else:
120127
widgets_dict[entry_name] = tk.Entry(frame,

crappy/tool/GUI_Arduino/minitens.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# coding: utf-8
22

3-
import tkinter as tk
4-
from tkinter import ttk
5-
63
from .frame_objects import FrameObjects
74
from collections import OrderedDict
85

6+
from ..._global import OptionalModule
7+
8+
try:
9+
import tkinter as tk
10+
from tkinter import ttk
11+
except (ModuleNotFoundError, ImportError):
12+
tk = OptionalModule("tkinter")
13+
ttk = OptionalModule("tkinter")
14+
915

1016
class MinitensPopups(FrameObjects):
1117
"""This class contains every popup. That means everything except the frames
@@ -42,8 +48,9 @@ def create_menubar(self):
4248
command=self.create_popup_limits)
4349
self.menu_exp_parameters.add_command(label='Vitesse',
4450
command=self.create_popup_speed)
45-
self.menu_exp_parameters.add_command(label='Paramètres échantillon',
46-
command=self.create_popup_sample_parameters)
51+
self.menu_exp_parameters.add_command(
52+
label='Paramètres échantillon',
53+
command=self.create_popup_sample_parameters)
4754

4855
# 2nd menu: tools to conduct the experience.
4956
self.menu_tools = tk.Menu(self.menubar, tearoff=0)
@@ -379,7 +386,8 @@ def create_popup_calibration(self):
379386
return
380387

381388
ok = tk.messagebox.askokcancel(title="Confirmation",
382-
message="Changer les paramètres de calibration?")
389+
message="Changer les paramètres de "
390+
"calibration?")
383391
if not ok:
384392
return
385393
else:

crappy/tool/cameraConfig.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# coding: utf-8
22

3-
import tkinter as tk
43
from time import time
54
import numpy as np
65
from multiprocessing import Process, Pipe
@@ -17,6 +16,11 @@
1716
except (ModuleNotFoundError, ImportError):
1817
cv2 = OptionalModule("opencv-python")
1918

19+
try:
20+
import tkinter as tk
21+
except (ModuleNotFoundError, ImportError):
22+
tk = OptionalModule("tkinter")
23+
2024

2125
class Hist_generator(Process):
2226
"""Process to generate the histogram of images.

crappy/tool/videoextensoConfig.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
"""More documentation coming soon !"""
44

5-
import tkinter as tk
65
import numpy as np
76
from .cameraConfig import Camera_config
87
from .._global import OptionalModule
@@ -18,6 +17,11 @@
1817
except (ModuleNotFoundError, ImportError):
1918
cv2 = OptionalModule("opencv-python")
2019

20+
try:
21+
import tkinter as tk
22+
except (ModuleNotFoundError, ImportError):
23+
tk = OptionalModule("tkinter")
24+
2125

2226
class VE_config(Camera_config):
2327
def __init__(self, camera, ve):
@@ -54,7 +58,7 @@ def update_box(self, event):
5458
def stop_select(self, event):
5559
self.ve.detect_spots(self.img[self.select_box[0]:self.select_box[2],
5660
self.select_box[1]:self.select_box[3]],
57-
self.select_box[0], self.select_box[1])
61+
self.select_box[0], self.select_box[1])
5862
self.select_box = (-1, -1, -1, -1)
5963
if hasattr(self.ve, "spot_list") and len(self.ve.spot_list) > 0:
6064
self.boxes = [x['bbox'] for x in self.ve.spot_list]
@@ -78,7 +82,7 @@ def draw_box(self, box, img):
7882

7983
def resize_img(self, sl):
8084
rimg = cv2.resize(self.img8[sl[1], sl[0]], tuple(reversed(self.img_shape)),
81-
interpolation=0)
85+
interpolation=0)
8286
if self.select_box[0] > 0:
8387
lbox = [0] * 4
8488
for i in range(4):

0 commit comments

Comments
 (0)