22ArduinoLogique.py
33Main module for the ArduinoLogique program. This module provides a graphical interface for
44simulating logic circuits using Tkinter. It includes functionality to initialize a canvas,
5- draw a breadboard, and zoom in and out on the circuit diagram .
5+ draw a breadboard, etc .
66"""
77
88import tkinter as tk
1414from toolbar import Toolbar
1515
1616
17- def zoom (canvas : tk .Canvas , scale : float , sketcher : ComponentSketcher ) -> None :
18- """
19- Adjusts the zoom level of the given canvas by scaling the board and updating the scale factor.
20-
21- Parameters:
22- - canvas (tk.Canvas): The canvas on which the board is drawn.
23- - scale (float): The scale factor to apply to the board.
24- - sketcher (ComponentSketcher): The ComponentSketcher instance used to draw the circuit.
25-
26- Returns:
27- - None
28- """
29- # Calculate the scaling factor
30- new_scale_factor = scale / 10.0
31- scale_ratio = new_scale_factor / sketcher .scale_factor
32-
33- # Update the scale factor in the existing ComponentSketcher instance
34- sketcher .scale_factor = new_scale_factor
35-
36- # Scale all items on the canvas
37- canvas .scale ("all" , 0 , 0 , scale_ratio , scale_ratio )
38-
39- # Optionally, you may need to adjust the canvas scroll region or other properties
40- canvas .configure (scrollregion = canvas .bbox ("all" ))
41-
42-
4317def main ():
4418 """
4519 Main function for the ArduinoLogique program. This function initializes the main window,
@@ -48,7 +22,8 @@ def main():
4822 # Creating main window
4923 win = tk .Tk ()
5024 win .title ("Laboratoire virtuel de circuit logique - GIF-1002" )
51- win .geometry ("1600x900" ) # Initial window size
25+ win .geometry ("1400x800" ) # Initial window size
26+ win .resizable (False , False ) # Disabling window resizing
5227 win .configure (bg = "#333333" ) # Setting consistent background color
5328
5429 # Configuring grid layout for the main window
@@ -105,34 +80,10 @@ def refresh_sidebar():
10580 canvas = canvas ,
10681 board = board ,
10782 current_dict_circuit = sketcher .current_dict_circuit ,
108- zoom_function = zoom ,
10983 )
11084 # Placing the menu_bar in row=0, spanning both columns
11185 menus .menu_bar .grid (row = 0 , column = 0 , columnspan = 2 , sticky = "nsew" )
11286
113- # Assigning the references to menus
114- menus .zoom_function = zoom
115-
116- # Creating a slider and placing it in row=3, spanning both columns
117- h_slider = tk .Scale (
118- win ,
119- from_ = 10 ,
120- to = 30 ,
121- orient = "horizontal" ,
122- command = lambda scale : zoom (canvas , float (scale ), sketcher ),
123- bg = "#333333" ,
124- fg = "white" ,
125- activebackground = "#444444" ,
126- troughcolor = "#555555" ,
127- highlightbackground = "#333333" ,
128- sliderrelief = "flat" ,
129- bd = 0 ,
130- highlightthickness = 0 ,
131- )
132- h_slider .set (10 ) # Setting initial slider value
133-
134- h_slider .grid (row = 3 , column = 0 , columnspan = 2 , sticky = "ew" , padx = 0 , pady = 0 )
135-
13687 # Setting default font for all widgets
13788 default_font = font .Font (family = "Arial" , size = 10 )
13889 win .option_add ("*Font" , default_font )
0 commit comments