-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
146 lines (120 loc) · 4.51 KB
/
main.py
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import sys, os
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
QPushButton,
QVBoxLayout,
QWidget,
QListWidget,
QListWidgetItem,
QMessageBox,
QTableWidget,
QTableWidgetItem,
)
from commands import (
conda_create,
conda_env_list,
conda_remove,
run_in_conda_env,
conda_env_exists,
)
home_dir = os.path.expanduser("~")
conda_shell = os.path.join(home_dir, "miniconda3/etc/profile.d/conda.sh")
class CondaGUI(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("iconda!")
self.setGeometry(2200, 600, 300, 200)
self.setAcceptDrops(True)
layout = QVBoxLayout()
self.list_widget = QListWidget()
curated_envs = ["cellpose_test", "napari_test", "jupyter_test"]
for env in curated_envs:
if conda_env_exists(conda_shell, env):
env += "\t[Installed]"
else:
env += "\t[Uninstalled]"
QListWidgetItem(env, self.list_widget)
layout.addWidget(self.list_widget)
self.list_widget.itemSelectionChanged.connect(self.on_change)
create_button = QPushButton("Create Environment")
create_button.clicked.connect(self.create_environment)
layout.addWidget(create_button)
list_button = QPushButton("List Environments")
list_button.clicked.connect(self.list_environments)
layout.addWidget(list_button)
remove_button = QPushButton("Remove Environment")
remove_button.clicked.connect(self.remove_environment)
layout.addWidget(remove_button)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dropEvent(self, event):
files = [u.toLocalFile() for u in event.mimeData().urls()]
for file in files:
QListWidgetItem(file, self.list_widget)
def get_selection(self, selected_item):
if selected_item:
return selected_item[0]
else:
QMessageBox.warning(self, "Warning", "Pick a selection first!")
return None
def on_change(self):
selected_item = self.list_widget.selectedItems()[0]
print(f"Selected {selected_item.text()}")
print(len(self.list_widget.selectedItems()))
# selected_item.setText(selected_item.text() + "\t[selected]")
# print([item.text() for item in self.list_widget.selectedItems()])
def create_environment(self):
# Add logic to get environment name from user
selected_item = self.get_selection(self.list_widget.selectedItems())
if not selected_item:
return
if "[Installed]" in selected_item.text():
QMessageBox.warning(
self, "Warning", "Environment is already installed!"
)
return
else:
env_name = selected_item.text().split("\t")[0]
print(f"Creating {env_name} environment")
print("Working on it...")
from_environment = False
if "cellpose" in env_name:
from_environment = True
result = conda_create(conda_shell, env_name, from_environment)
if "cellpose" in env_name:
print("Installing GUI")
result = run_in_conda_env(
conda_shell, env_name, "pip install cellpose[gui]"
)
print(f"{env_name} environment created!")
if conda_env_exists(conda_shell, env_name):
selected_item.setText(env_name + "\t[Installed]")
def list_environments(self):
envs = conda_env_list(conda_shell)
QMessageBox.information(self, "Installed Environments", envs)
def remove_environment(self):
selected_item = self.get_selection(self.list_widget.selectedItems())
if not selected_item:
return
env_name = selected_item.text().split("\t")[0]
print(f"Removing {env_name} environment")
result = conda_remove(conda_shell, env_name)
print(f"{env_name} removed")
if conda_env_exists(conda_shell, env_name):
print("Environment wasn't removed")
else:
selected_item.setText(env_name + "\t[Uninstalled]")
if result.returncode != 0:
print("something weird happened")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CondaGUI()
window.show()
sys.exit(app.exec_())