from kivymd.app import MDApp
from kivymd.uix.scrollview import MDScrollView
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.dialog import MDDialog
from kivy.core.window import Window
from kivy.utils import get_color_from_hex

class DoseCalculator(MDScrollView):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout = MDBoxLayout(orientation='vertical', padding=20, spacing=20, size_hint_y=None)
        self.layout.bind(minimum_height=self.layout.setter('height'))
        self.add_widget(self.layout)

        self.layout.add_widget(MDLabel(text='Dosage required (mg/kg):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#FF5722')))
        self.dosage_input = MDTextField(hint_text="Enter the required dosage", helper_text_mode="on_focus")
        self.layout.add_widget(self.dosage_input)

        self.layout.add_widget(MDLabel(text='Drug concentration (%):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#2196F3')))
        self.concentration_input = MDTextField(hint_text="Enter the drug concentration", helper_text_mode="on_focus")
        self.layout.add_widget(self.concentration_input)

        self.layout.add_widget(MDLabel(text='Animal weight (kg):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#4CAF50')))
        self.weight_input = MDTextField(hint_text="Enter the animal weight", helper_text_mode="on_focus")
        self.layout.add_widget(self.weight_input)

        calculate_button = MDRaisedButton(
            text='Calculate Dose',
            md_bg_color=get_color_from_hex('#9C27B0'),
            text_color=(1, 1, 1, 1),
            pos_hint={'center_x': 0.5}
        )
        calculate_button.bind(on_press=self.calculate_dose)
        self.layout.add_widget(calculate_button)

    def calculate_dose(self, instance):
        try:
            dosage_per_kg = float(self.dosage_input.text)
            concentration = float(self.concentration_input.text)
            weight = float(self.weight_input.text)

            concentration_mg_per_ml = concentration * 10  # 1% = 10 mg/ml
            total_dose_ml = (dosage_per_kg * weight) / concentration_mg_per_ml

            result_dialog = MDDialog(
                title='Calculation Result',
                text=f'Required dose: {total_dose_ml:.2f} ml',
                size_hint=(0.8, None),
                height=Window.height * 0.3,
            )
            result_dialog.open()
        except ValueError:
            error_dialog = MDDialog(
                title='Error',
                text='Please enter valid numbers.',
                size_hint=(0.8, None),
                height=Window.height * 0.3,
            )
            error_dialog.open()

class DoseApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = 'DeepPurple'
        self.theme_cls.accent_palette = 'Amber'
        self.theme_cls.theme_style = 'Light'

        Window.softinput_mode = 'below_target'

        return DoseCalculator()

if __name__ == '__main__':
    DoseApp().run()

from kivymd.app import MDApp
from kivymd.uix.scrollview import MDScrollView
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.dialog import MDDialog
from kivy.core.window import Window
from kivy.utils import get_color_from_hex

class DoseCalculator(MDScrollView):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout = MDBoxLayout(orientation='vertical', padding=20, spacing=20, size_hint_y=None)
        self.layout.bind(minimum_height=self.layout.setter('height'))
        self.add_widget(self.layout)

        self.layout.add_widget(MDLabel(text='Dosage required (mg/kg):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#FF5722')))
        self.dosage_input = MDTextField(hint_text="Enter the required dosage", helper_text_mode="on_focus")
        self.layout.add_widget(self.dosage_input)

        self.layout.add_widget(MDLabel(text='Drug concentration (%):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#2196F3')))
        self.concentration_input = MDTextField(hint_text="Enter the drug concentration", helper_text_mode="on_focus")
        self.layout.add_widget(self.concentration_input)

        self.layout.add_widget(MDLabel(text='Animal weight (kg):', halign='center', theme_text_color='Custom', text_color=get_color_from_hex('#4CAF50')))
        self.weight_input = MDTextField(hint_text="Enter the animal weight", helper_text_mode="on_focus")
        self.layout.add_widget(self.weight_input)

        calculate_button = MDRaisedButton(
            text='Calculate Dose',
            md_bg_color=get_color_from_hex('#9C27B0'),
            text_color=(1, 1, 1, 1),
            pos_hint={'center_x': 0.5}
        )
        calculate_button.bind(on_press=self.calculate_dose)
        self.layout.add_widget(calculate_button)

    def calculate_dose(self, instance):
        try:
            dosage_per_kg = float(self.dosage_input.text)
            concentration = float(self.concentration_input.text)
            weight = float(self.weight_input.text)

            concentration_mg_per_ml = concentration * 10  # 1% = 10 mg/ml
            total_dose_ml = (dosage_per_kg * weight) / concentration_mg_per_ml

            result_dialog = MDDialog(
                title='Calculation Result',
                text=f'Required dose: {total_dose_ml:.2f} ml',
                size_hint=(0.8, None),
                height=Window.height * 0.3,
            )
            result_dialog.open()
        except ValueError:
            error_dialog = MDDialog(
                title='Error',
                text='Please enter valid numbers.',
                size_hint=(0.8, None),
                height=Window.height * 0.3,
            )
            error_dialog.open()

class DoseApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = 'DeepPurple'
        self.theme_cls.accent_palette = 'Amber'
        self.theme_cls.theme_style = 'Light'

        Window.softinput_mode = 'below_target'

        return DoseCalculator()

if __name__ == '__main__':
    DoseApp().run()


الكود ده شغال زي الفل، بس انا عايز تعديل بسيط عليه بنفس الاسلوب، عايز اضيف صفحة تانية فالتطبيق تشتغل مستقلة، يكون في الاتي، ساعات مثلا يكون عارف ان الحيوان جرعته مثلا 1ml/25kg تمام، انا بقي عايز اكبر دماغي من حساب الجرعة للحيوان ككل، يعني مثلا هنفرض ان الحيوان كان ٤٠٠ كيلو، انا مش عايز اضرب واعمل، كل اللي عايزه اني يبقي فيه خانة احط فيه الجرعة لعدد كيلوهات معين، وخانة لوزن الحيوان ككل  والناتج يطلع الجرعة كلها اللي الحيوان المفروض ياخدها، مثلا 2ml/20kg وبالتالي حيوان ٤٥٠ كيلو هياخد 45ml