-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_handler.py
More file actions
124 lines (106 loc) · 5.73 KB
/
Copy pathenv_handler.py
File metadata and controls
124 lines (106 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# env_handler.py
import os
import tkinter as tk
from tkinter import simpledialog, messagebox, filedialog
from event_bus import EventBus
class EnvHandler:
def __init__(self, app):
self.app = app
def update_status(self):
self.app.ui.status_bar.config(text=f"Ortam: [{self.app.env_mgr.current_env}] | Python: {self.app.env_mgr.python_path}")
def refresh_env_list(self):
self.app.ui.env_combo['values'] = self.app.env_mgr.get_environment_list()
self.app.ui.env_combo.set(self.app.env_mgr.current_env)
def on_env_selected(self, event):
selection = self.app.ui.env_combo.get()
if selection == "+ Yeni Ortam Oluştur...":
env_name = simpledialog.askstring("Yeni Ortam", "Sanal ortam için bir isim girin:")
if env_name:
EventBus.publish("ui:start_progress")
self.app.ui.env_combo.config(state="disabled")
self.app.env_mgr.create_venv_async(
env_name,
lambda n: self.app.root.after(0, self._venv_success, n),
lambda e: self.app.root.after(0, self._venv_error, e)
)
else:
self.app.ui.env_combo.set(self.app.env_mgr.current_env)
else:
success, err_path = self.app.env_mgr.select_environment(selection)
if success:
self.update_status()
self.refresh_libraries_list()
else:
messagebox.showerror("Hata", f"Ortam bozuk veya python.exe bulunamad!\n{err_path}")
self.app.ui.env_combo.set(self.app.env_mgr.current_env)
def _venv_success(self, env_name):
EventBus.publish("ui:stop_progress")
self.app.ui.env_combo.config(state="readonly")
self.refresh_env_list()
self.app.ui.env_combo.set(env_name)
self.on_env_selected(None)
def _venv_error(self, err_msg):
EventBus.publish("ui:stop_progress")
self.app.ui.env_combo.config(state="readonly")
messagebox.showerror("Hata", err_msg)
self.app.ui.env_combo.set(self.app.env_mgr.current_env)
def show_env_context(self, event):
selection = self.app.ui.env_combo.get()
if selection not in ["Yerel", "+ Yeni Ortam Oluştur...", "Manuel", ""]:
menu = tk.Menu(self.app.root, tearoff=0)
menu.add_command(label=f"'{selection}' Ortamını Sil", command=lambda: self.delete_env(selection))
menu.tk_popup(event.x_root, event.y_root)
def delete_env(self, env_name):
if messagebox.askyesno("Onay", f"'{env_name}' ortamını tamamen silmek istediğinize emin misiniz?"):
EventBus.publish("ui:start_progress")
self.app.ui.env_combo.config(state="disabled")
self.app.env_mgr.delete_venv_async(
env_name,
lambda n: self.app.root.after(0, self._delete_env_success, n),
lambda e: self.app.root.after(0, self._venv_error, e)
)
def _delete_env_success(self, env_name):
EventBus.publish("ui:stop_progress")
self.app.ui.env_combo.config(state="readonly")
if self.app.env_mgr.current_env == env_name:
self.app.ui.env_combo.set("Yerel")
self.on_env_selected(None)
self.refresh_env_list()
messagebox.showinfo("Başarılı", f"'{env_name}' ortamı silindi.")
def refresh_libraries_list(self):
self.app.ui.lib_combo['values'] = ["Yükleniyor..."]
self.app.ui.lib_combo.current(0)
self.app.env_mgr.fetch_libraries_async(lambda libs: self.app.root.after(0, lambda: self._update_lib_combo(libs)))
def _update_lib_combo(self, lib_list):
self.app.ui.lib_combo['values'] = lib_list
self.app.ui.lib_combo.current(0)
def on_lib_selected(self, event):
if self.app.ui.lib_combo.current() == 0:
lib_name = simpledialog.askstring("Pip Install", f"[{self.app.env_mgr.current_env}] ortamına kurulacak kütüphane adı:")
if lib_name:
self.install_lib_live(lib_name)
def install_lib_live(self, lib_name):
EventBus.publish("ui:start_progress")
EventBus.publish("ui:clear_output")
EventBus.publish("ui:write_output", f"--- '{lib_name}' Kurulumu Başlatılıyor... Lütfen Bekleyin ---\n")
cmd = [self.app.env_mgr.python_path, "-m", "pip", "install", lib_name]
EventBus.publish("process:run_pip", cmd)
def show_lib_context(self, event):
selection = self.app.ui.lib_combo.get()
if selection not in ["+ Kütüphane Ekle", "Yükleniyor...", "Hata!", ""]:
menu = tk.Menu(self.app.root, tearoff=0)
menu.add_command(label=f"'{selection}' Kaldır", command=lambda: self.uninstall_lib(selection))
menu.tk_popup(event.x_root, event.y_root)
def uninstall_lib(self, lib_name):
if messagebox.askyesno("Onay", f"'{lib_name}' kütüphanesini kaldırmak istediğinize emin misiniz?"):
EventBus.publish("ui:start_progress")
EventBus.publish("ui:clear_output")
EventBus.publish("ui:write_output", f"--- '{lib_name}' Kaldırılıyor... ---\n")
cmd = [self.app.env_mgr.python_path, "-m", "pip", "uninstall", "-y", lib_name]
EventBus.publish("process:run_pip", cmd)
def change_python_path(self, event):
new_path = filedialog.askopenfilename(title="Derleyici Seçin", filetypes=[("Yürütülebilir Dosya", "*.exe"), ("Tüm Dosyalar", "*.*")])
if new_path:
self.app.env_mgr.python_path = new_path
self.app.env_mgr.current_env = "Manuel"
self.update_status()