Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin Autoplot gui #10

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import asyncio
import os
import datetime
from typing import List

from amiga_package import ops
Expand All @@ -24,9 +25,11 @@
# kivy imports
from kivy.app import App # noqa: E402
from kivy.lang.builder import Builder # noqa: E402
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button


class TemplateApp(App):
class AutoPlot(App):
"""Base class for the main Kivy app."""

def __init__(self) -> None:
Expand All @@ -43,6 +46,40 @@ def on_exit_btn(self) -> None:
"""Kills the running kivy application."""
App.get_running_app().stop()

def show_button(self,button):
print(button.id)

def on_toggle_button_press(self, instance, directory):
print('Button pressed:', instance.text, directory)
try:
# Get the list of all files in the directory
file_list = os.listdir(directory)

# Loop through each file
for filename in file_list:
# Create the full file path by joining the directory and the filename
filepath = os.path.join(directory, filename)

# Check if it's a file, not a directory
if os.path.isfile(filepath):
# Get file info
file_info = os.stat(filepath)

# Get file size
file_size = file_info.st_size

# Get file modification time
modification_time = datetime.datetime.fromtimestamp(file_info.st_mtime).strftime('%Y-%m-%d %H:%M:%S')

# Print the information
print(f"File Name: {filename}, File Size: {file_size} bytes, Last Modified: {modification_time}")
except FileNotFoundError:
print(f"The directory '{directory}' does not exist.")
except PermissionError:
print(f"Permission denied for directory '{directory}'.")



async def app_func(self):
async def run_wrapper() -> None:
# we don't actually need to set asyncio as the lib because it is
Expand All @@ -61,14 +98,14 @@ async def template_function(self) -> None:
while self.root is None:
await asyncio.sleep(0.01)

while True:
await asyncio.sleep(1.0)
# while True:
# await asyncio.sleep(1.0)

# increment the counter using internal libs and update the gui
self.counter = ops.add(self.counter, 1)
self.root.ids.counter_label.text = (
f"{'Tic' if self.counter % 2 == 0 else 'Tac'}: {self.counter}"
)
# # increment the counter using internal libs and update the gui
# self.counter = ops.add(self.counter, 1)
# self.root.ids.counter_label.text = (
# f"{'Tic' if self.counter % 2 == 0 else 'Tac'}: {self.counter}"
# )


if __name__ == "__main__":
Expand All @@ -80,7 +117,7 @@ async def template_function(self) -> None:

loop = asyncio.get_event_loop()
try:
loop.run_until_complete(TemplateApp().app_func())
loop.run_until_complete(AutoPlot().app_func())
except asyncio.CancelledError:
pass
loop.close()
40 changes: 36 additions & 4 deletions src/res/main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,39 @@ RelativeLayout:
source: "assets/back_button_normal.png" if self.parent.state == "normal" else "assets/back_button_down.png"
pos: self.parent.pos
size: self.parent.size
Label:
id: counter_label
text: "Tic: 0"
font_size: 40

BoxLayout:
size_hint_y: .1
size_hint_x: .5
pos_hint: {'top': .85}
padding: 5, 5
spacing: '5dp'
ToggleButton:
group: 'toggle_group'
id: guide_line
text: 'Guidance Line'
font_size: '25'
allow_no_selection: False
on_state: if self.state == 'down': app.on_toggle_button_press(self,"/data/")

ToggleButton:
group: 'toggle_group'
id: path
text: 'Path'
font_size: '25'
allow_no_selection: False
on_state: if self.state == 'down': app.on_toggle_button_press(self,"/data/farm_ng/paths")

ToggleButton:
group: 'toggle_group'
id: field_bound
text: 'Field Boundry'
font_size: '25'
allow_no_selection: False
on_state: if self.state == 'down': app.on_toggle_button_press(self,"/data/")

RecycleView:
id: recycleview
viewclass: 'Label'