Skip to content

Commit

Permalink
configure feature on hold
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulShagri committed Mar 27, 2021
1 parent 0dd3f63 commit cb3dc40
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 21 deletions.
131 changes: 114 additions & 17 deletions CategoryHandlerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from DatabaseHandlerAPI import *
import threading
import win32gui
import re

categories = {}

Expand All @@ -16,7 +17,7 @@ def __init__(self, title: str):
self.parent = "Loaded scripts"
self.script_count = 0

with collapsing_header(name=self.title, parent=self.parent, default_open=True):
with collapsing_header(name=self.title, parent=self.parent):
add_dummy(name=f"{self.title}Dummy01", height=10)
add_image_button(name=f"add_script##{self.title}", value="icons/add_script_button_dark.png", width=150, height=26)
add_same_line(spacing=10)
Expand Down Expand Up @@ -67,14 +68,14 @@ def __init__(self, title: str):

add_dummy(name=f"{self.title}DummySeparator", height=10, parent=self.parent)

def close_popups(self, sender):
def close_popups(self, sender, data=""):
if sender == f"Cancel##AddScript??{self.title}":
set_value(f"script_name??{self.title}", "")
set_value(f"script_path??{self.title}", "")
set_value(f"Script uses virtual environment##{self.title}", False)
set_value(f"venv_path??{self.title}", "")
set_value(f"thumbnail_path??{self.title}", "")
self.enable_venv()
self.enable_venv(f"Script uses virtual environment##{self.title}")
clear_drawing(f"thumbnail??{self.title}")
draw_polyline(drawing=f"thumbnail??{self.title}", points=[[0, 0], [410, 0], [410, 231], [0, 231]],
color=[255, 0, 0], thickness=1, closed=True)
Expand All @@ -96,8 +97,12 @@ def close_popups(self, sender):
if sender == f"No##DeleteCategory{self.title}":
close_popup(f"Are you sure you want to delete this category?##{self.title}")

if re.search("Update", sender):
close_popup(f"Configure script##{self.title}??{data}")

def delete_category(self):
delete_item(self.title)
delete_item(f"{self.title}DummySeparator")
del categories[self.title]
delete_table(self.title)

Expand Down Expand Up @@ -210,7 +215,73 @@ def add_script(self):

with child(name=f"sub-child??{self.title}??{_temp_script_name_}", width=50, height=150):
add_image_button(name=f"delete??{self.title}??{_temp_script_name_}", value="icons/delete_script_button_dark.png", width=30, height=30, callback=self.delete_script)
add_image_button(name=f"configure??{self.title}??{_temp_script_name_}", value="icons/configure_script_button_dark.png", width=30, height=30)
#add_image_button(name=f"configure??{self.title}??{_temp_script_name_}", value="icons/configure_script_button_dark.png", width=30, height=30)

# # Popup for configuring script info
#
# with popup(popupparent=f"configure??{self.title}??{_temp_script_name_}",
# name=f"Configure script##{self.title}??{_temp_script_name_}", mousebutton=mvMouseButton_Left, modal=True):
#
# script_info = get_script_info(table=self.title, script=_temp_script_name_)
#
# set_item_style_var(item=f"Configure script##{self.title}??{_temp_script_name_}", style=mvGuiStyleVar_WindowPadding,
# value=[10, 10])
# add_dummy(name="addScriptDummy01", height=10)
#
# # script name
# add_input_text(name=f"configure_script_name??{self.title}??{_temp_script_name_}", label=" Enter script name",
# hint="Script name", tip="Leave blank to set it the same as the file name.",
# width=250)
#
# set_value(f"configure_script_name??{self.title}??{_temp_script_name_}", value=script_info[0])
#
# add_dummy(name="addScriptDummy02", height=20)
#
# # script path
# add_input_text(name=f"configure_script_path??{self.title}??{_temp_script_name_}", label="", hint="Script path", width=250,
# readonly=True)
#
# set_value(f"configure_script_path??{self.title}??{_temp_script_name_}", value=script_info[1])
#
# add_same_line(spacing=5)
# add_button(name=f"Find script##configure??{self.title}??{_temp_script_name_}", width=150, callback=self.find_script, callback_data=_temp_script_name_)
# add_dummy(name="addScriptDummy03", height=20)
#
# # venv
# add_checkbox(name=f"Script uses virtual environment##configure??{self.title}??{_temp_script_name_}", callback=self.enable_venv, callback_data=_temp_script_name_)
# add_dummy(name="addScriptDummy04", height=20)
# add_input_text(name=f"configure_venv_path??{self.title}??{_temp_script_name_}", label="", hint="Venv folder path", width=250,
# enabled=False, readonly=True)
#
# if script_info[2] == "":
# set_value(f"Script uses virtual environment##configure??{self.title}??{_temp_script_name_}", True)
# set_value(f"configure_venv_path??{self.title}??{_temp_script_name_}", script_info[3])
# else:
# set_value(f"Script uses virtual environment##configure??{self.title}??{_temp_script_name_}", False)
#
# add_same_line(spacing=5)
# add_button(name=f"Find venv folder##configure??{self.title}??{_temp_script_name_}", width=150, enabled=False,
# callback=self.find_venv, callback_data=_temp_script_name_)
# add_dummy(name="addScriptDummy05", height=20)
#
# #thumbnail
# add_input_text(name=f"configure_thumbnail_path??{self.title}??{_temp_script_name_}", label="", hint="Thumbnail file path",
# width=250, readonly=True)
#
# if script_info[4] == "icons/default_thumbnail.jpg": set_value(f"configure_thumbnail_path??{self.title}??{_temp_script_name_}", "")
# else: set_value(f"configure_thumbnail_path??{self.title}??{_temp_script_name_}", script_info[4])
#
# add_same_line(spacing=5)
# add_button(name=f"Add thumbnail##configure??{self.title}??{_temp_script_name_}", width=150,
# tip="Leave blank to set it to default.", callback=self.find_thumbnail, callback_data=_temp_script_name_)
# add_dummy(name="addScriptDummy06", height=20)
# add_drawing(name=f"configure_thumbnail??{self.title}??{_temp_script_name_}", width=410, height=231)
# draw_image(f"configure_thumbnail??{self.title}??{_temp_script_name_}", file=script_info[4], pmin=[0,0], pmax=[410, 232])
#
# add_dummy(name="addScriptDummy06", height=20)
# add_button(f"Update##UpdateScript??{self.title}??{_temp_script_name_}", width=210, callback=self.update_script, callback_data=lambda: self.update_script(data=_temp_script_name_, old_script_name=_temp_script_name_))
# add_same_line(spacing=5.0)
# add_button(f"Cancel##UpdateScript??{self.title}??{_temp_script_name_}", width=210, callback=self.close_popups, callback_data=_temp_script_name_)

add_text(f"{_temp_script_name_}", wrap=265)

Expand All @@ -223,7 +294,7 @@ def add_script(self):
set_value(f"Script uses virtual environment##{self.title}", False)
set_value(f"venv_path??{self.title}", "")
set_value(f"thumbnail_path??{self.title}", "")
self.enable_venv()
self.enable_venv(f"Script uses virtual environment##{self.title}")
clear_drawing(f"thumbnail??{self.title}")
draw_polyline(drawing=f"thumbnail??{self.title}", points=[[0, 0], [410, 0], [410, 231], [0, 231]],
color=[255, 0, 0], thickness=1, closed=True)
Expand Down Expand Up @@ -339,23 +410,37 @@ def delete_script(self, sender):
add_image_button(name=f"delete??{self.title}??{script_name}",
value="icons/delete_script_button_dark.png", width=30, height=30,
callback=self.delete_script)
add_image_button(name=f"configure??{self.title}??{script_name}", value="icons/configure_script_button_dark.png", width=30, height=30)
#add_image_button(name=f"configure??{self.title}??{script_name}", value="icons/configure_script_button_dark.png", width=30, height=30)

add_text(f"{script_name}", wrap=265)

# def configure_script(self):
# with popup(popupparent=)

def enable_venv(self):
if get_value(f"Script uses virtual environment##{self.title}"):
# def update_script(self, data, old_script_name):
# script_name = get_value(f"configure_script_name??{self.title}??{data}")
# script_path = get_value(f"configure_script_path??{self.title}??{data}")
# venv = get_value(f"Script uses virtual environment##configure??{self.title}??{data}")
# venv_path = get_value(f"configure_venv_path??{self.title}??{data}")
# thumbnail_path = get_value(f"configure_thumbnail_path??{self.title}??{data}")
#
# update_script(table=self.title, old_script_name=old_script_name, script_name=script_name, script_path=script_path, venv=venv, venv_path=venv_path, thumbnail_path=thumbnail_path)

def enable_venv(self, sender, data=""):
if get_value(sender):
configure_item(f"venv_path??{self.title}", enabled=True)
configure_item(f"Find venv folder##{self.title}", enabled=True)

if re.search("configure", sender):
configure_item(f"configure_venv_path??{self.title}??{data}", enabled=True)
configure_item(f"Find venv folder##configure??{self.title}??{data}", enabled=True)

else:
configure_item(f"venv_path??{self.title}", enabled=False)
configure_item(f"Find venv folder##{self.title}", enabled=False)

def find_script(self):
if re.search("configure", sender):
configure_item(f"configure_venv_path??{self.title}??{data}", enabled=False)
configure_item(f"Find venv folder##configure??{self.title}??{data}", enabled=False)

def find_script(self, sender, data=""):
Tk().withdraw()

file_path = askopenfilename(title="MultiPy find script window",
Expand All @@ -365,21 +450,27 @@ def find_script(self):
if file_path:
set_value(f"script_path??{self.title}", file_path)

if re.search("configure", sender):
set_value(f"configure_script_path??{self.title}??{data}", file_path)

if does_item_exist("Please select a script."):
delete_item("Please select a script.")

def find_venv(self):
def find_venv(self, sender, data=""):
Tk().withdraw()

folder_path = askdirectory(title="MultiPy find venv window")

if folder_path:
set_value(f"venv_path??{self.title}", folder_path)

if re.search("configure", sender):
set_value(f"configure_venv_path??{self.title}??{data}", folder_path)

if does_item_exist("Please select a venv path."):
delete_item("Please select a venv path.")

def find_thumbnail(self):
def find_thumbnail(self, sender, data=""):
Tk().withdraw()

file_path = askopenfilename(title="MultiPy find thumbnail window",
Expand All @@ -391,6 +482,13 @@ def find_thumbnail(self):
clear_drawing(f"thumbnail??{self.title}")
draw_image(drawing=f"thumbnail??{self.title}", file=get_value(f"thumbnail_path??{self.title}"), pmin=[0,0], pmax=[410,231])

if re.search("configure", sender):
set_value(f"configure_thumbnail_path??{self.title}??{data}", file_path)
clear_drawing(f"configure_thumbnail??{self.title}??{data}")
draw_image(drawing=f"configure_thumbnail??{self.title}??{data}", file=get_value(f"thumbnail_path??{self.title}"),
pmin=[0, 0], pmax=[410, 231])



def close_popups(sender):

Expand Down Expand Up @@ -551,7 +649,6 @@ def open_tool():
add_dummy(name="dummy03", height=20)
# add_text("You can find more information in the help menu.")


tables, all_scripts = read_all()

if not tables:
Expand Down Expand Up @@ -585,8 +682,8 @@ def open_tool():
add_image_button(name=f"delete??{table[0]}??{script_info[0]}",
value="icons/delete_script_button_dark.png", width=30, height=30,
callback=categories[table[0]].delete_script)
add_image_button(name=f"configure??{table[0]}??{script_info[0]}",
value="icons/configure_script_button_dark.png", width=30, height=30)
# add_image_button(name=f"configure??{table[0]}??{script_info[0]}",
# value="icons/configure_script_button_dark.png", width=30, height=30)

add_text(f"{script_info[0]}", wrap=265)

Expand Down
12 changes: 11 additions & 1 deletion DatabaseHandlerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,14 @@ def read_all():
conn.commit()
conn.close()

return tables, scripts
return tables, scripts

def update_script(table: str, old_script_name: str, script_name: str, script_path: str, thumbnail_path="icons/default_thumbnail.jpg", venv=str, venv_path=""):
conn = sqlite3.connect("_temp_.db")
c = conn.cursor()

c.execute(f"""UPDATE \"{table}\" SET script_name = ?, script_path = ?, venv = ?, venv_path = ?, thumbnail_path = ? WHERE script_name = \"{old_script_name}\")""", (script_name, script_path, venv, venv_path, thumbnail_path))


conn.commit()
conn.close()
6 changes: 3 additions & 3 deletions MultiPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
add_menu_item("Open dashboard", callback=open_tool)

with window(name="Add scripts button", no_title_bar=True, no_resize=True, no_close=True, no_collapse=True, no_move=True,
x_pos=1070, y_pos=630, autosize=True):
x_pos=1040, y_pos=630, autosize=True):

add_image_button(name="add_category", value="icons/add_category_button_dark.png", width=250, height=36)

Expand All @@ -45,13 +45,13 @@
add_button("Cancel##AddCategory", width=220, callback=close_popups)

with window(name="Tools", no_title_bar=True, no_resize=True, no_close=True, no_collapse=True, no_move=True,
x_pos=80, y_pos=630, autosize=True):
x_pos=50, y_pos=630, autosize=True):

add_image_button(name="view_button", value="icons/view_button_dark.png", width=36, height=36, tip="Switch to view-only mode", show=False, callback=show_edit_mode_switcher)
add_same_line(spacing=10, name="tools_line")

with window(name="Loaded scripts", no_title_bar=True, no_resize=True, no_close=True, no_collapse=True, no_move=True,
x_pos=80, y_pos=40, width=1260, height=590):
x_pos=50, y_pos=40, width=1260, height=590):

with child("Instructions", height=200):
add_dummy(name="loadedScriptsDummy01", height=15)
Expand Down

0 comments on commit cb3dc40

Please sign in to comment.