added buttons

This commit is contained in:
2025-03-31 16:32:55 +03:00
parent 6467fbb56d
commit 1c504c7289
13 changed files with 274 additions and 9120 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

File diff suppressed because it is too large Load Diff

BIN
src/Resurse/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

BIN
src/Resurse/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

View File

@@ -18,17 +18,58 @@
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
opacity: 0
# Settings (Home) button
Button:
id: settings_button
size_hint: None, None
size: 90, 90
size: 75, 75
pos_hint: {'right': 0.98, 'bottom': 0.98}
background_normal: './Resurse/home_icon.png'
background_down: './Resurse/home_icon.png'
background_color: 10/255.0, 160/255.0, 255/255.0, 0.80
background_color: 1, 1, 1, 0.9 # Temporary red background for debugging
border: [0, 0, 0, 0] # Remove the default border
opacity: 1
on_release: app.open_settings()
# Right Arrow button
Button:
id: right_arrow_button
size_hint: None, None
size: 75, 75
pos_hint: {'right': 0.93, 'bottom': 0.98}
background_normal: './Resurse/left-arrow-blue.png'
background_down: './Resurse/left-arrow-green.png'
background_color: 1, 1, 1, 0.9 # Temporary green background for debugging
border: [0, 0, 0, 0] # Remove the default border
opacity: 1
on_release: root.next_media(None)
# Play/Pause button
Button:
id: play_pause_button
size_hint: None, None
size: 75, 75
pos_hint: {'right': 0.88, 'bottom': 0.98}
background_normal: './Resurse/play.png'
background_down: './Resurse/pause.png'
background_color: 1, 1, 1, 0.9 # Temporary blue background for debugging
border: [0, 0, 0, 0] # Remove the default border
opacity: 1
on_press: root.toggle_play_pause()
# Left Arrow button
Button:
id: left_arrow_button
size_hint: None, None
size: 75, 75
pos_hint: {'right': 0.83, 'bottom': 0.98}
background_normal: './Resurse/right-arrow-blue.png'
background_down: './Resurse/right-arrow-green.png'
background_color: 1, 1, 1, 0.9 # Temporary yellow background for debugging
border: [0, 0, 0, 0] # Remove the default border
opacity: 1
on_release: root.previous_media()
<SettingsScreen>:
BoxLayout:
orientation: 'vertical'

View File

@@ -33,26 +33,37 @@ class MediaPlayer(Screen):
self.video_player = self.ids.video_player # Reference to the Video widget
self.image_display = self.ids.image_display # Reference to the Image widget
self.log_file = os.path.join(os.path.dirname(__file__), 'Resurse', 'log.txt') # Path to the log file
self.is_paused = False # Track the state of the play/pause button
# Schedule periodic updates to check for playlist updates
Clock.schedule_interval(self.check_playlist_updates, 300) # Every 5 minutes
# Bind key events to handle fullscreen toggle
Window.bind(on_key_down=self.on_key_down)
# Start a timer to hide the settings button after 10 seconds
self.hide_button_timer = Clock.schedule_once(self.hide_settings_button, 10)
# Start a timer to hide the buttons after 10 seconds
self.hide_button_timer = Clock.schedule_once(self.hide_buttons, 10)
def on_touch_down(self, touch):
"""Handle touch events to reset the settings button visibility."""
self.ids.settings_button.opacity = 1 # Make the settings button visible
"""Handle touch events to reset the button visibility."""
self.show_buttons() # Make all buttons visible
if hasattr(self, 'hide_button_timer'):
Clock.unschedule(self.hide_button_timer) # Cancel the existing hide timer
self.hide_button_timer = Clock.schedule_once(self.hide_settings_button, 10) # Restart the hide timer
self.hide_button_timer = Clock.schedule_once(self.hide_buttons, 10) # Restart the hide timer
return super(MediaPlayer, self).on_touch_down(touch)
def hide_settings_button(self, *args):
"""Hide the settings button after inactivity."""
self.ids.settings_button.opacity = 0
def hide_buttons(self, *args):
"""Hide all buttons after inactivity."""
self.ids.settings_button.opacity = 0 # Hide the Home button
self.ids.right_arrow_button.opacity = 0 # Hide the Right Arrow button
self.ids.play_pause_button.opacity = 0 # Hide the Play/Pause button
self.ids.left_arrow_button.opacity = 0 # Hide the Left Arrow button
def show_buttons(self):
"""Show all buttons."""
self.ids.settings_button.opacity = 1 # Show the Home button
self.ids.right_arrow_button.opacity = 1 # Show the Right Arrow button
self.ids.play_pause_button.opacity = 1 # Show the Play/Pause button
self.ids.left_arrow_button.opacity = 1 # Show the Left Arrow button
def on_key_down(self, window, key, *args):
"""Handle key events for toggling fullscreen mode."""
@@ -65,6 +76,7 @@ class MediaPlayer(Screen):
download_media_files(self.playlist) # Download media files from the playlist
clean_unused_files(self.playlist) # Remove unused files from the resource folder
self.play_media() # Start playing media
self.show_buttons() # Ensure buttons are visible when the screen is entered
def log_event(self, file_name, event):
"""Log the start or stop event of a media file and clean up old logs."""
@@ -182,15 +194,33 @@ class MediaPlayer(Screen):
# Schedule the next media after the duration
Clock.schedule_once(self.next_media, duration)
def next_media(self, dt):
def next_media(self, dt=None):
"""Move to the next media in the playlist."""
# Log the stop of the current media
current_media = self.playlist[self.current_index].get('file_name', '')
self.log_event(current_media, "STOPPED")
Logger.info("Navigating to the next media.")
self.current_index = (self.current_index + 1) % len(self.playlist)
self.play_media()
# Move to the next media
self.current_index = (self.current_index + 1) % len(self.playlist) # Increment the index
self.play_media() # Play the next media
def previous_media(self):
"""Go to the previous media in the playlist."""
Logger.info("Navigating to the previous media.")
self.current_index = (self.current_index - 1) % len(self.playlist)
self.play_media()
def toggle_play_pause(self):
"""Toggle the play/pause button state and update its appearance."""
if self.is_paused:
Logger.info("Resuming media playback.")
self.video_player.state = 'play'
# Update the button to indicate the playing state
self.ids.play_pause_button.background_down = './Resurse/play.png'
else:
Logger.info("Pausing media playback.")
self.video_player.state = 'pause'
# Update the button to indicate the paused state
self.ids.play_pause_button.background_down = './Resurse/pause.png'
# Toggle the state
self.is_paused = not self.is_paused
def check_playlist_updates(self, dt):
"""Check for updates to the playlist."""