Hello again all. I’m having trouble with a clipboard keyboard ui that I made.
I’ll include my relevant code below, but I’ll share a short rundown of what I believe it might be.
I made a base clipboard ui that automatically resizes a scrollviews content size and adds buttons and delete buttons to the scrollview depending on how many items are in the json file supplied to the clipboard.
I had planned to reuse the same ui to save the snippets of code for js,python,etc so I made a separate subclass for my regular clipboard. I implemented a delete button for each clip that will delete the clip from the json and set its corresponding button text to “[clip text] (deleted)”. It definitely deletes the clip from the file, but when setting the button title to the new one it’s like I have two overlaying views because I can clearly see the old text under the new one.
I even switched it to the base view I was subclassing and it still does it, can anyone look at my code and tell me where I’m going wrong?
Base View
ScrollView
Buttons
I apologize for the length of my non-commented code, I’m posting this right before work
class clipboard_base(ui.View):
def __init__(self,name,clip_list):
self.name = name
self.clip_list = clip_list
if self.clip_list == None:
self.clip_list = ['There Was','an error']
self.gap = 4
self.button_height = 60
self.insert_before = []
button_container = ui.ScrollView()
button_container.frame = (0,0,self.width,self.height)
self.scrollview = button_container
self.add_subview(button_container)
def layout(self):
if len(self.insert_before) == 0:
starting_y = 0
else:
starting_y = self.insert_before[-1].height+2*self.gap
self.button1_width = self.width - 3*self.gap -50
total_button_height = len(self.clip_list)*self.button_height+(len(self.clip_list)+1)*self.gap
scrollview = self.scrollview
scrollview.height = self.height - starting_y
if total_button_height > scrollview.height:
scrollview.content_size=(self.width,total_button_height)
else:
scrollview.content_size = (scrollview.width,scrollview.height)
if len(self.insert_before) == 0:
scrollview.frame = self.bounds
else:
scrollview.frame = insert_before[0].height + self.gap
for i,clip in enumerate(self.clip_list):
button1 = ui.Button()
button1.title = clip
button1.name = clip+' button'
button1.width = self.button1_width
button1.height = self.button_height
button1.x = self.gap
button1.y = (i+1)*self.gap+i*self.button_height
button1.action = self.insert
button1.border_width = 1
button1.corner_radius = 2
scrollview.add_subview(button1)
button_2_x = button1.x+button1.width+self.gap
button2 = ui.Button()
button2.name = clip
button2.x = button_2_x
button2.y = button1.y
button2.height = 50
button2.width = 50
button2.border_width = 1
button2.corner_radius = 2
button2.flex = ''
button2.title = 'Delete'
button2.action = self.delete_clip
button2.height = self.button_height
scrollview.add_subview(button2)
else:
pass
def insert(self,button):
text = button.title
try:
keyboard.insert_text(text)
except:
clipboard.set(text)
def delete_clip(self,button):
clip = button.name
self.scrollview[clip+' button'].title = clip+' (deleted)'
delete_clip(self.name,clip)