Skip to content

Commit

Permalink
Merge pull request #17 from ch00f/master
Browse files Browse the repository at this point in the history
Added keyboard controls, L+R to select and A+S to move.
  • Loading branch information
Trekky12 authored Mar 23, 2024
2 parents b9a0348 + 7457538 commit c49e1f2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"sync_titles_to_slides": false,
"save": false,
"test": false
}
}
2 changes: 1 addition & 1 deletion gui/ScrollFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, parent, height=100, create_vertical_scrollbar=True, bg=None):
# create horizontal scrollbar
hsbar = tk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.canvas.xview)
hsbar.grid(row=1, column=0, sticky=tk.EW)
self.canvas.configure(xscrollcommand=hsbar.set)
self.canvas.configure(xscrollcommand=hsbar.set, xscrollincrement=1)

def addFrame(self, frame, anchor=tk.NW):
self.frame = frame
Expand Down
50 changes: 49 additions & 1 deletion gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


class App(tk.Tk):

def __init__(self, title="", *args, **kwargs):
super().__init__()

Expand Down Expand Up @@ -194,6 +195,53 @@ def __init__(self, title="", *args, **kwargs):

self.overlayTitleEntry = None
self.padColorEntry = None
self.bindings()

def centerSlidesAroundSelected(self):
if ((self.buttons[self.slide_selected].winfo_rootx() - self.winfo_rootx() +
self.buttons[self.slide_selected].winfo_width()) / self.winfo_width() > 0.8):
diff = int((self.buttons[self.slide_selected].winfo_rootx() - self.winfo_rootx() +
self.buttons[self.slide_selected].winfo_width()) - 0.8*self.winfo_width())
self.frameSlides.canvas.xview("scroll", "+" + str(diff), "units")
if ((self.buttons[self.slide_selected].winfo_rootx() - self.winfo_rootx()) / self.winfo_width() < 0):
diff = int((self.buttons[self.slide_selected].winfo_rootx() - self.winfo_rootx()) - 0.2 * self.winfo_width())
self.frameSlides.canvas.xview("scroll", str(diff), "units")

def moveRight(self):
if self.slide_selected < len(self.buttons) - 1:
self.buttons.insert(self.slide_selected+1, self.buttons.pop(self.slide_selected))
self.sm.moveSlide(self.slide_selected, self.slide_selected + 1)
self.slide_selected += 1
# rearrange buttons in grid
for i, btn in enumerate(self.buttons):
btn.grid(column=i)
self.centerSlidesAroundSelected()

def moveLeft(self):
if self.slide_selected > 0:
self.buttons.insert(self.slide_selected-1, self.buttons.pop(self.slide_selected))
self.sm.moveSlide(self.slide_selected, self.slide_selected - 1)
self.slide_selected -= 1
# rearrange buttons in grid
for i, btn in enumerate(self.buttons):
btn.grid(column=i)
self.centerSlidesAroundSelected()

def selectRight(self):
if self.slide_selected < len(self.buttons) - 1:
self.onSlideClicked(self.slide_selected + 1)
self.centerSlidesAroundSelected()

def selectLeft(self):
if self.slide_selected > 0:
self.onSlideClicked(self.slide_selected - 1)
self.centerSlidesAroundSelected()

def bindings(self):
self.bind("<Right>", lambda event: self.selectRight())
self.bind("<Left>", lambda event: self.selectLeft())
self.bind("s", lambda event: self.moveRight())
self.bind("a", lambda event: self.moveLeft())

def hasSlides(self):
return self.sm and (len(self.sm.getSlides()) > 0 or len(self.sm.getBackgroundTracks()) > 0)
Expand Down Expand Up @@ -558,7 +606,7 @@ def loadSlideshowImagesRow(self):

def onSlideClicked(self, button_id):
for btn in self.buttons:
btn.state(['!pressed', '!disabled'])
btn.state(['!pressed', '!disabled', '!focus'])

for btn in self.buttonsAudio:
btn.state(['!pressed', '!disabled'])
Expand Down

0 comments on commit c49e1f2

Please sign in to comment.