benim ui kodum bu import flet as ft from flet import IconButton, TextStyle, icons,…
- User
benim ui kodum bu import flet as ft from flet import IconButton, TextStyle, icons, Dropdown, MainAxisAlignment, CrossAxisAlignment, colors, BoxShadow, Offset, RoundedRectangleBorder, padding from flet import TextField, TextAlign, ButtonStyle, DataTable, DataColumn, DataRow, DataCell, Divider, SnackBar, NavigationBar, NavigationDestination
def main(page: ft.Page): page.title = "Ballistik Hesaplayıcı" page.bgcolor = "#121619" page.padding = 3 page.window_width = 400 page.window_height = 800 page.scroll = "always"
def create_neumorphic_container(content, width=None, height=None): return ft.Container( content=content, width=width, height=height, bgcolor="#121619", border_radius=15, padding=10, shadow=ft.BoxShadow( spread_radius=1, blur_radius=15, color=ft.colors.with_opacity(0.5, "#000000"), offset=ft.Offset(5, 5), ), gradient=ft.LinearGradient( begin=ft.alignment.top_left, end=ft.alignment.bottom_right, colors=[ "#1e2328", "#0a0c0e", ], ), ) def edit_value(text_container, text_field, save_button, cancel_button): def toggle_edit_mode(edit=True): text_container.visible = not edit text_field.visible = edit save_button.visible = edit cancel_button.visible = edit page.update() def save_changes(e): text_container.content.value = text_field.value toggle_edit_mode(False) def cancel_changes(e): text_field.value = text_container.content.value toggle_edit_mode(False) def start_editing(e): toggle_edit_mode(True) text_container.on_click = start_editing save_button.on_click = save_changes cancel_button.on_click = cancel_changes return toggle_edit_mode def create_input_row(label, value, unit, key=None): # Key parametresi eklendi text_container = ft.Container( content=ft.Text( value, color=ft.colors.WHITE, text_align="center", size=16, ), bgcolor="#1e2328", border_radius=5, alignment=ft.alignment.center, padding=5, expand=True, ) text_field = ft.TextField( value=value, text_align="center", border=ft.InputBorder.NONE, bgcolor="#1e2328", color=ft.colors.WHITE, visible=False, ) save_button = ft.IconButton( icon=ft.icons.CHECK, icon_color="#09814A", visible=False, ) cancel_button = ft.IconButton( icon=ft.icons.CLOSE, icon_color="#FF0000", visible=False, ) toggle_edit_mode = edit_value( text_container, text_field, save_button, cancel_button ) return ft.Container( content=ft.Row( [ ft.Container( content=ft.Text(label, color=ft.colors.WHITE70), width=120, alignment=ft.alignment.center_left, ), ft.Stack([text_container, text_field], expand=True), ft.Container( content=ft.Text(unit, color=ft.colors.WHITE70), width=100, alignment=ft.alignment.center, ), ] ), height=50, border=ft.border.only(bottom=ft.border.BorderSide(1, "#2a2e35")), key=key, # Key parametresi eklendi ) def get_drag_tables_names(): return ["TableG1", "TableG7", "TableG2", "TableG5", "TableG6", "TableG8", "TableGI", "TableGS"] def unit_changed(e): input_field = e.control.parent.controls[2] # TextField'a erişim yolu güncellendi selected_unit = e.control.value try: input_field.value = str(_parse_value(input_field.value, selected_unit).unit_value) except UnitAliasError as err: print(f"Hata: {err}") page.update() def create_unit_options(unit_types: list[Unit]) -> list[ft.dropdown.Option]: return [ft.dropdown.Option(unit.key) for unit in unit_types] def create_unit_input(label: str, value: str, unit_types: list[Unit], default_unit: Unit) -> ft.Row: return ft.Row( controls=[ ft.Container( content=ft.Text(label), width=150, ), ft.Container( content=ft.TextField(value=value, width=150, text_align=ft.TextAlign.RIGHT), ), ft.Dropdown(width=100, options=create_unit_options(unit_types), value=default_unit.key, on_change=unit_changed), ], alignment=MainAxisAlignment.SPACE_BETWEEN, ) def drag_model_changed(e): page.update() # Main page components target_velocity = create_unit_input("Hedef Hızı", "5", [Velocity.MPS, Velocity.KMH], Velocity.MPS) target_direction = create_unit_input("Hedef Yönü", "9", [Angular.Degree, Angular.OClock], Angular.OClock) altitude = create_unit_input("Yükseklik", "0", [Distance.Meter, Distance.Foot], Distance.Meter) pressure = create_unit_input("Basınç", "29.8", [Pressure.InHg, Pressure.hPa], Pressure.InHg) temperature = create_unit_input("Sıcaklık", "15", [Temperature.Celsius, Temperature.Fahrenheit], Temperature.Celsius) humidity = ft.Row( controls=[ ft.Container( content=ft.Text("Nem (%)"), width=150, ), ft.TextField(value="72", width=150, text_align=ft.TextAlign.RIGHT), ft.Container(width=100), # Boş birim alanı ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN, ) wind_velocity = create_unit_input("Rüzgar Hızı", "2", [Velocity.MPH, Velocity.MPS], Velocity.MPH) wind_velocity2 = create_unit_input("2. Rüzgar Hızı", "0", [Velocity.MPH, Velocity.MPS], Velocity.MPH) wind_direction = create_unit_input("Rüzgar Yönü", "9", [Angular.Degree, Angular.OClock], Angular.OClock) max_ord_range = create_unit_input("Maksimum Ordinat Mesafesi", "100", [Distance.Meter, Distance.Yard], Distance.Meter) trajectory_range = create_unit_input("Yörünge Mesafesi", "1000", [Distance.Meter, Distance.Yard], Distance.Meter) trajectory_step = create_unit_input("Yörünge Adımı", "100", [Distance.Meter, Distance.Yard], Distance.Meter) look_angle = create_unit_input("Eğim", "0", [Angular.Degree, Angular.Mil], Angular.Degree) target_distance = create_unit_input("Hedef Mesafesi", "300", [Distance.Meter, Distance.Yard], Distance.Meter) # Equipment page components powder_temp = create_unit_input("Barut Sıcaklığı", "15", [Temperature.Celsius, Temperature.Fahrenheit], Temperature.Celsius) other_velocity = create_unit_input("Diğer Hız", "2723", [Velocity.FPS, Velocity.MPS], Velocity.FPS) other_temperature = create_unit_input("Diğer Sıcaklık", "0", [Temperature.Celsius, Temperature.Fahrenheit], Temperature.Celsius) weight = create_unit_input("Mermi Ağırlığı", "168", [Weight.Grain, Weight.Gram], Weight.Grain) diameter = create_unit_input("Mermi Çapı", "0.308", [Distance.Inch, Distance.Millimeter], Distance.Inch) length = create_unit_input("Mermi Uzunluğu", "1.282", [Distance.Inch, Distance.Millimeter], Distance.Inch) bc = ft.Row( controls=[ ft.Row( controls=[ ft.Text("Balistik Katsayısı "), ft.TextField(value="0.3", width=150, text_align=ft.TextAlign.RIGHT), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN, ), ft.Dropdown( width=100, options=[ft.dropdown.Option(table_name) for table_name in get_drag_tables_names()], value="TableG7", on_change=drag_model_changed ) ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN, ) sight_height = create_unit_input("Nişangah Yüksekliği", "9", [Distance.Centimeter, Distance.Inch], Distance.Centimeter) zero_distance = create_unit_input("Sıfırlama Mesafesi", "100", [Distance.Meter, Distance.Yard], Distance.Meter) mv = create_unit_input("Namlu Hızı", "2750", [Velocity.FPS, Velocity.MPS], Velocity.FPS) twist = create_unit_input("Yiv Burgusu", "12", [Distance.Inch, Distance.Millimeter], Distance.Inch) table = ft.DataTable( columns=[ ft.DataColumn(ft.Text("Mesafe")), ft.DataColumn(ft.Text("Hız")), ft.DataColumn(ft.Text("Mach")), ft.DataColumn(ft.Text("Süre")), ft.DataColumn(ft.Text("Hedef Düşüşü")), ft.DataColumn(ft.Text("Düşüş Ayarı")), ft.DataColumn(ft.Text("Rüzgar Sürüklenmesi")), ft.DataColumn(ft.Text("Rüzgar Ayarı")), ], rows=[], ) output_area = ft.Text() target_distance_main = None elevation_text = ft.Text("0.00", color=colors.CYAN, size=24, weight="bold") wind_drift_text = ft.Text("0.00 / 0.00", color=colors.ORANGE, size=24, weight="bold") wind_drift_info = ft.Text("0.0 / 0.0 @ 0.00c", color=colors.BLACK) # Yeni widget distance_text = ft.Text("Mesafe: 0", color=colors.BLACK) bullet_weight_text = ft.Text("BW: 0", color=colors.BLACK, size=10) diameter_text = ft.Text("BD: 0", color=colors.BLACK, size=10) bc_text = ft.Text("BC: 0", color=colors.BLACK, size=10) length_text = ft.Text("BL: 0", color=colors.BLACK, size=10) twist_text = ft.Text("TW: 0", color=colors.BLACK, size=10) sg_text = ft.Text("SG: 0.00", color=colors.BLACK, size=10) Mach_text = ft.Text("Mach: 0.00", color=colors.BLACK, size=10) tof_text = ft.Text("TOF= 0.000s", color=colors.BLACK, size=10) mv_text = ft.Text("MV= ", color=colors.BLACK, size=10) lead_text=ft.Text("0.00", color=colors.CYAN, size=24, weight="bold") lead_info = ft.Text("0 @ 0.00c", color=colors.BLACK) scope_info = ft.Text("0m/0.0/0.0 Mrad", color=colors.BLACK, size=10) def calculate_trajectory(e): try: # GUI'den değerleri al ve doğru türlere dönüştür weight_value = float(weight.controls[1].content.value) diameter_value = float(diameter.controls[1].content.value) length_value = float(length.controls[1].content.value) bc_value = float(bc.controls[0].controls[1].value) # bc farklı bir yapıya sahip mv_value = float(mv.controls[1].content.value) powder_temp_value = float(powder_temp.controls[1].content.value) other_velocity_value = float(other_velocity.controls[1].content.value) other_temperature_value = float(other_temperature.controls[1].content.value) sight_height_value = float(sight_height.controls[1].content.value) twist_value = float(twist.controls[1].content.value) altitude_value = float(altitude.controls[1].content.value) pressure_value = float(pressure.controls[1].content.value) temperature_value = float(temperature.controls[1].content.value) humidity_value = float(humidity.controls[1].value) # humidity farklı bir yapıya sahip wind_velocity_value = float(wind_velocity.controls[1].content.value) wind_velocity2_value = float(wind_velocity2.controls[1].content.value) # 2. rüzgar hızı wind_direction_value = float(wind_direction.controls[1].content.value) zero_distance_value = float(zero_distance.controls[1].content.value) max_ord_range_value = float(max_ord_range.controls[1].content.value) trajectory_range_value = float(trajectory_range.controls[1].content.value) trajectory_step_value = float(trajectory_step.controls[1].content.value) look_angle_value = float(look_angle.controls[1].content.value) target_distance_value = float(target_distance.controls[1].content.value) target_velocity_value = float(target_velocity.controls[1].content.value) target_direction_value = float(target_direction.controls[1].content.value) # Seçilen birimleri al weight_unit = _parse_unit(weight.controls[2].value) diameter_unit = _parse_unit(diameter.controls[2].value) length_unit = _parse_unit(length.controls[2].value) mv_unit = _parse_unit(mv.controls[2].value) powder_temp_unit = _parse_unit(powder_temp.controls[2].value) other_velocity_unit = _parse_unit(other_velocity.controls[2].value) other_temperature_unit = _parse_unit(other_temperature.controls[2].value) sight_height_unit = _parse_unit(sight_height.controls[2].value) twist_unit = _parse_unit(twist.controls[2].value) altitude_unit = _parse_unit(altitude.controls[2].value) pressure_unit = _parse_unit(pressure.controls[2].value) temperature_unit = _parse_unit(temperature.controls[2].value) wind_velocity_unit = _parse_unit(wind_velocity.controls[2].value) wind_velocity2_unit = _parse_unit(wind_velocity2.controls[2].value) # 2. rüzgar birimi wind_direction_unit = _parse_unit(wind_direction.controls[2].value) zero_distance_unit = _parse_unit(zero_distance.controls[2].value) max_ord_range_unit = _parse_unit(max_ord_range.controls[2].value) trajectory_range_unit = _parse_unit(trajectory_range.controls[2].value) trajectory_step_unit = _parse_unit(trajectory_step.controls[2].value) look_angle_unit = _parse_unit(look_angle.controls[2].value) target_distance_unit = _parse_unit(target_distance.controls[2].value) target_velocity_unit = _parse_unit(target_velocity.controls[2].value) target_direction_unit = _parse_unit(target_direction.controls[2].value) # Seçilen sürükleme tablosunu al selected_drag_table = globals()[bc.controls[1].value] # bc farklı bir yapıya sahip # Mermi modeli, mühimmat, silah, atmosfer, rüzgar ve atışı tanımla dm = DragModel( bc_value, selected_drag_table, weight_unit(weight_value), diameter_unit(diameter_value), length_unit(length_value), ) ammo = Ammo(dm, mv_unit(mv_value), powder_temp_unit(powder_temp_value)) ammo.calc_powder_sens( other_velocity_unit(other_velocity_value), other_temperature_unit(other_temperature_value), ) gun = Weapon( sight_height=sight_height_unit(sight_height_value), twist=twist_unit(twist_value), ) current_atmo = Atmo( altitude=altitude_unit(altitude_value), pressure=pressure_unit(pressure_value), temperature=temperature_unit(temperature_value), humidity=humidity_value, ) zeroing_shot = Shot(weapon=gun, ammo=ammo, atmo=current_atmo) zero_range = zero_distance_unit(zero_distance_value) calculator = Calculator() zero_elevation = calculator.set_weapon_zero(zeroing_shot, zero_range) # Hedef mesafesini al nonlocal target_distance_main target_distance_main = target_distance_unit(target_distance_value) target_distance_feet = target_distance_main >> Distance.Foot # Rüzgarı tanımla current_winds = [Wind(wind_velocity_unit(wind_velocity_value), wind_direction_unit(wind_direction_value))] # Sıfırlama atışını güncelle zeroing_shot.winds = current_winds # Yeni bir atış oluştur, hedef mesafesini, hedef eğimini ve rüzgarı kullan new_target = Shot( weapon=gun, ammo=ammo, atmo=current_atmo, look_angle=look_angle_unit(look_angle_value), winds=current_winds ) # TrajectoryCalc objesini oluştur calc = TrajectoryCalc(new_target.ammo) # _init_trajectory fonksiyonunu çağırarak gerekli değerleri ayarla calc._init_trajectory(new_target) # İstenen mesafe için _trajectory fonksiyonunu çağır, sadece son noktayı al trajectory_point = calc._trajectory(new_target, target_distance_feet, target_distance_feet, TrajFlag.NONE)[0] # İstenen mesafedeki düşüş ayarını al target_drop_adj = trajectory_point.drop_adj # Hedef mesafesindeki Mach değerini al target_mach = trajectory_point.mach # Rüzgar ayarını al wind_drift = trajectory_point.windage_adj wind_angle = wind_direction_unit(wind_direction_value) # İkinci rüzgar etkisi current_winds2 = [Wind(wind_velocity2_unit(wind_velocity2_value), wind_direction_unit(wind_direction_value))] zeroing_shot.winds = current_winds2 new_target.winds = current_winds2 calc._init_trajectory(new_target) trajectory_point2 = calc._trajectory(new_target, target_distance_feet, target_distance_feet, TrajFlag.NONE)[0] wind_drift2 = trajectory_point2.windage_adj << PreferredUnits.adjustment # Yükseklik değerini güncelle elevation_text.value = f"{(target_drop_adj << PreferredUnits.adjustment)}" distance_value = f"{target_distance_main << PreferredUnits.distance}" distance_text.value = f"Mesafe: {distance_value}" # TOF bilgisini güncelle target_tof = trajectory_point.time tof_text.value = f"TOF= {target_tof:.3f}s" # stability_coefficient değerine eriş stability_coefficient = calc.stability_coefficient # sg_text widget'ını güncelle sg_text.value = f"SG: {stability_coefficient:.2f}" # Çıkış hızı bilgisini güncelle calculated_mv = ammo.get_velocity_for_temp(current_atmo.temperature) >> Velocity.MPS mv_text.value = f"MV= {calculated_mv:.1f}mps" lead = calculate_lead( target_tof, # TOF bilgisini kullan target_velocity_unit(target_velocity_value), target_direction_unit(target_direction_value), target_distance_main, # Hedef mesafesi ) lead_text.value = f"{lead}" if target_direction_unit == Angular.Degree: lead_info.value = f"{target_velocity_value} @ {target_direction_value:.0f}°" # Derece işareti else: lead_info.value = f"{target_velocity_value} @ {target_direction_value:.2f}c" if wind_direction_unit == Angular.Degree: wind_drift_info.value = f"{wind_velocity_value} / {wind_velocity2_value} @ {wind_direction_value:.0f}°" # Derece işareti else: wind_drift_info.value = f"{wind_velocity_value} / {wind_velocity2_value} @ {wind_direction_value:.2f}c" # Ekranı güncelle bullet_weight_text.value = f"BW: {weight_value}{weight_unit.key}" diameter_text.value = f"BD: {diameter_value}{diameter_unit.key}" bc_model = bc.controls[1].value bc_text.value = f"BC: {bc_value}({bc_model})" length_text.value = f"BL: {length_value}{length_unit.key}" twist_text.value = f"TW: {twist_value}{twist_unit.key}" wind_drift_text.value = f"{wind_drift << PreferredUnits.adjustment} / {wind_drift2}{'L' if wind_drift > 0 else 'R'}" Mach_text.value = f"Mach: {target_mach:.2f}" scope_info.value =f"{zero_distance_value}{zero_distance_unit.key} / {sight_height_value}{sight_height.key}" # Çıktıyı oluştur output_text = f"Silah sıfırlama yüksekliği {zero_range} için: {zero_elevation << PreferredUnits.angular}\n" output_text += f"{current_atmo.temperature} sıcaklıktaki namlu hızı: {ammo.get_velocity_for_temp(current_atmo.temperature) << Velocity.MPS}\n" output_text += f"{(target_distance_main << PreferredUnits.distance)} mesafedeki hedefi vurmak için nişangah ayarı:\n" output_text += f" Yükseklik: {(target_drop_adj << PreferredUnits.adjustment) if target_drop_adj else 'Mesafe yörünge aralığında değil'}\n" output_text += f" Rüzgar: {(wind_drift << PreferredUnits.adjustment)} {'sağ' if wind_angle >> Angular.OClock < 6 else 'sol'}\n" output_area.value = output_text page.update() except Exception as e: page.snack_bar = ft.SnackBar(ft.Text(f"Hata: {e}")) page.snack_bar.open = True page.update() def create_table(e): try: # GUI'den değerleri al ve doğru türlere dönüştür weight_value = float(weight.controls[1].content.value) diameter_value = float(diameter.controls[1].content.value) length_value = float(length.controls[1].content.value) bc_value = float(bc.controls[0].controls[1].value) mv_value = float(mv.controls[1].content.value) powder_temp_value = float(powder_temp.controls[1].content.value) other_velocity_value = float(other_velocity.controls[1].content.value) other_temperature_value = float(other_temperature.controls[1].content.value) sight_height_value = float(sight_height.controls[1].content.value) twist_value = float(twist.controls[1].content.value) altitude_value = float(altitude.controls[1].content.value) pressure_value = float(pressure.controls[1].content.value) temperature_value = float(temperature.controls[1].content.value) humidity_value = float(humidity.controls[1].value) wind_velocity_value = float(wind_velocity.controls[1].content.value) wind_direction_value = float(wind_direction.controls[1].content.value) zero_distance_value = float(zero_distance.controls[1].content.value) max_ord_range_value = float(max_ord_range.controls[1].content.value) look_angle_value = float(look_angle.controls[1].content.value) trajectory_range_value = float(trajectory_range.controls[1].content.value) trajectory_step_value = float(trajectory_step.controls[1].content.value) # Seçilen birimleri al weight_unit = _parse_unit(weight.controls[2].value) diameter_unit = _parse_unit(diameter.controls[2].value) length_unit = _parse_unit(length.controls[2].value) mv_unit = _parse_unit(mv.controls[2].value) powder_temp_unit = _parse_unit(powder_temp.controls[2].value) other_velocity_unit = _parse_unit(other_velocity.controls[2].value) other_temperature_unit = _parse_unit(other_temperature.controls[2].value) sight_height_unit = _parse_unit(sight_height.controls[2].value) twist_unit = _parse_unit(twist.controls[2].value) altitude_unit = _parse_unit(altitude.controls[2].value) pressure_unit = _parse_unit(pressure.controls[2].value) temperature_unit = _parse_unit(temperature.controls[2].value) wind_velocity_unit = _parse_unit(wind_velocity.controls[2].value) wind_direction_unit = _parse_unit(wind_direction.controls[2].value) zero_distance_unit = _parse_unit(zero_distance.controls[2].value) max_ord_range_unit = _parse_unit(max_ord_range.controls[2].value) look_angle_unit = _parse_unit(look_angle.controls[2].value) trajectory_range_unit = _parse_unit(trajectory_range.controls[2].value) trajectory_step_unit = _parse_unit(trajectory_step.controls[2].value) # Seçilen sürükleme tablosunu al selected_drag_table = globals()[bc.controls[1].value] # Mermi modeli, mühimmat, silah, atmosfer, rüzgar ve atışı tanımla dm = DragModel( bc_value, selected_drag_table, weight_unit(weight_value), diameter_unit(diameter_value), length_unit(length_value), ) ammo = Ammo(dm, mv_unit(mv_value), powder_temp_unit(powder_temp_value)) ammo.calc_powder_sens( other_velocity_unit(other_velocity_value), other_temperature_unit(other_temperature_value), ) gun = Weapon( sight_height=sight_height_unit(sight_height_value), twist=twist_unit(twist_value), ) current_atmo = Atmo( altitude=altitude_unit(altitude_value), pressure=pressure_unit(pressure_value), temperature=temperature_unit(temperature_value), humidity=humidity_value, ) zeroing_shot = Shot(weapon=gun, ammo=ammo, atmo=current_atmo) zero_range = zero_distance_unit(zero_distance_value) calculator = Calculator() calculator.set_weapon_zero(zeroing_shot, zero_range) # Rüzgarı tanımla current_winds = [Wind(wind_velocity_unit(wind_velocity_value), wind_direction_unit(wind_direction_value))] # Sıfırlama atışını güncelle zeroing_shot.winds = current_winds # Yörünge kartını hesapla trajectory_card = calculator.fire( zeroing_shot, trajectory_range=trajectory_range_unit(trajectory_range_value), trajectory_step=trajectory_step_unit(trajectory_step_value), ) # Tabloyu güncelle table.rows = [ ft.DataRow( cells=[ ft.DataCell(ft.Text(value=str(p.distance << Distance.Meter))), # Mesafe ft.DataCell(ft.Text(value=str(p.velocity << Velocity.MPS))), # Hız ft.DataCell(ft.Text(value=f"{p.mach:.2f}")), # Mach ft.DataCell(ft.Text(value=f"{p.time:.3f}")), # Süre ft.DataCell(ft.Text(value=str(p.target_drop << Distance.Centimeter))), # Hedef Düşüşü ft.DataCell(ft.Text(value=str(p.drop_adj << Angular.Mil))), # Düşüş Ayarı ft.DataCell(ft.Text(value=str(p.windage << Distance.Centimeter))), # Rüzgar Sürüklenmesi ft.DataCell(ft.Text(value=str(p.windage_adj << Angular.Mil))), # Rüzgar Ayarı ] ) for p in trajectory_card.trajectory ] page.update() except Exception as e: page.snack_bar = ft.SnackBar(ft.Text(f"Hata: {e}")) page.snack_bar.open = True page.update() bg_color = colors.GREY_900 card_color = colors.GREY_800 text_color = colors.WHITE accent_color = colors.BLUE_400 def create_top_bottom_section(): return ft.Container( padding=10, bgcolor=card_color, border_radius=10, content=ft.Column( controls=[ # Neumorphic Container ile sarılmış Top Info Row ve diğer bilgiler create_neumorphic_container( ft.Column( [ ft.Row( [ ft.Column( [ ft.Text("DÜZELTME", size=12, color=ft.colors.WHITE70), elevation_text, distance_text, ], alignment=ft.MainAxisAlignment.CENTER, horizontal_alignment=ft.CrossAxisAlignment.CENTER, ), ft.VerticalDivider(width=1, thickness=1, color=ft.colors.WHITE24), ft.Column( [ ft.Text("RÜZGAR 1/2", size=12, color=ft.colors.WHITE70), wind_drift_text, wind_drift_info, ], alignment=ft.MainAxisAlignment.CENTER, horizontal_alignment=ft.CrossAxisAlignment.CENTER, ), ft.VerticalDivider(width=1, thickness=1, color=ft.colors.WHITE24), ft.Column( [ ft.Text("ÖNLEME", size=12, color=ft.colors.WHITE70), lead_text, lead_info, ], alignment=ft.MainAxisAlignment.CENTER, horizontal_alignment=ft.CrossAxisAlignment.CENTER, ), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN, ), ft.Divider(height=10, color=ft.colors.WHITE24), # Alt çizgi (1) ft.Row( controls=[ mv_text, sg_text, tof_text, scope_info, Mach_text, ], alignment=MainAxisAlignment.SPACE_BETWEEN, ), ft.Row( controls=[ bullet_weight_text, diameter_text, bc_text, length_text, twist_text, ], alignment=MainAxisAlignment.SPACE_BETWEEN, ), ] ), width=360, # Genişlik ayarı height=220, # Yükseklik ayarı (artırıldı) ), ], spacing=10, ), ) def main_page(): return ft.Container( padding=20, bgcolor=bg_color, content=ft.Column( [ create_top_bottom_section(), ft.Container( content=ft.Column( [ target_velocity, target_direction, altitude, pressure, temperature, humidity, wind_velocity, wind_velocity2, wind_direction, max_ord_range, trajectory_range, trajectory_step, look_angle, target_distance, ft.Row( controls=[ ft.ElevatedButton("Hesapla", on_click=calculate_trajectory, style=ButtonStyle(shape=RoundedRectangleBorder(radius=10), color=accent_color)), ft.ElevatedButton("Tablo", on_click=create_table, style=ButtonStyle(shape=RoundedRectangleBorder(radius=10), color=accent_color)), ], alignment=MainAxisAlignment.CENTER, ), ft.Divider(color=colors.GREY_700), output_area, table, ], scroll=ft.ScrollMode.AUTO, horizontal_alignment=CrossAxisAlignment.CENTER, ), padding=20, expand=True, ), ], horizontal_alignment=CrossAxisAlignment.CENTER, expand=True, ), ) def equipment_page(): return ft.Container( bgcolor=bg_color, content=ft.Column( [ ft.Container( content=ft.Column( [ powder_temp, other_velocity, other_temperature, weight, diameter, length, bc, sight_height, zero_distance, mv, twist, ], scroll=ft.ScrollMode.AUTO, horizontal_alignment=CrossAxisAlignment.CENTER, ), padding=20, bgcolor=card_color, border_radius=10, expand=True, ), ], horizontal_alignment=CrossAxisAlignment.CENTER, expand=True, ), ) def toolbox_page(): toolbox_content = ft.Column( [ ft.Container(height=0), ft.Column( [ ft.Container( content=ft.TextButton("Artıkıl", on_click=lambda e: print("Artıkıl tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Tablo", on_click=lambda e: print("Tablo tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Atış Grubu Analizi", on_click=lambda e: print("Grafikler tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Grafikler", on_click=lambda e: print("Grafikler tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Birim Çevirici", on_click=lambda e: print("Birim Çevirici tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Vuruş Olasılığı", on_click=lambda e: print("WEZ tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Sürüklenme Kalibrasyonu", on_click=lambda e: print("DSF Kalibrasyon tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Mesafe Hesaplama", on_click=lambda e: print("Mesafe Hesaplama tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Hedef Listesi", on_click=lambda e: print("Hedef Listesi tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Atış Yolu Doğrulama", on_click=lambda e: print("Atış Yolu Doğrulama tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Harita", on_click=lambda e: print("Harita tıklandı"), width=200), alignment=ft.alignment.center, ), ft.Divider(height=1, thickness=1, color=ft.colors.WHITE24), ft.Container( content=ft.TextButton("Ek Bilgiler", on_click=lambda e: print("Ek Bilgiler tıklandı"), width=200), alignment=ft.alignment.center, ), ], spacing=10, horizontal_alignment=ft.CrossAxisAlignment.CENTER, ), ], scroll=ft.ScrollMode.AUTO, spacing=0, ) return ft.Container( content=toolbox_content, alignment=ft.alignment.center, bgcolor=bg_color, expand=True, ) def settings_page(): settings_content = ft.Column( [ ft.Container(height=210), ft.Container( content=ft.Column( [ ft.Row([ ft.Text("Renk Teması", color=ft.colors.WHITE), ft.Checkbox(value=True, fill_color=ft.colors.GREEN), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN), ft.Row([ ft.Text("Aerodinamik Zıplamayı Hesaba Kat", color=ft.colors.WHITE), ft.Checkbox(value=True, fill_color=ft.colors.GREEN), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN), ft.Row([ ft.Text("Spin Sapmasını Hesaba Kat", color=ft.colors.WHITE), ft.Checkbox(value=True, fill_color=ft.colors.GREEN), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN), ft.Row([ ft.Text("Coriolisi Hesaba Kat", color=ft.colors.WHITE), ft.Checkbox(value=False, fill_color=ft.colors.GREEN), ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN), ft.ElevatedButton("Hakkında", bgcolor="#2a2e35", color=ft.colors.WHITE), ], spacing=10, ), padding=20, bgcolor="#2a2e35", border_radius=10, ), ], scroll=ft.ScrollMode.AUTO, spacing=0, ) def toggle_theme(e): page.theme_mode = "light" if page.theme_mode == "dark" else "dark" theme_icon_button.icon = icons.LIGHT_MODE if page.theme_mode == "dark" else icons.DARK_MODE page.update() theme_icon_button = IconButton( icon=icons.LIGHT_MODE if page.theme_mode == "dark" else icons.DARK_MODE, tooltip="Temayı değiştir", on_click=toggle_theme, ) return ft.Container( content=ft.Column( [ theme_icon_button, settings_content, ], alignment=ft.alignment.center, ), alignment=ft.alignment.center, bgcolor=bg_color, expand=True, ) def change_page(e): selected_index = e.control.selected_index if selected_index == 0: content.content = main_page() elif selected_index == 1: content.content = equipment_page() elif selected_index == 2: content.content = toolbox_page() elif selected_index == 3: content.content = settings_page() page.update() navigation_bar = NavigationBar( destinations=[ NavigationDestination(icon=icons.HOME, label="Ana Sayfa"), NavigationDestination(icon=icons.SETTINGS_APPLICATIONS, label="Ekipman"), NavigationDestination(icon=icons.WORK, label="Toolbox"), NavigationDestination(icon=icons.SETTINGS, label="Ayarlar"), ], on_change=change_page, bgcolor=card_color, ) content = ft.Container(content=main_page(), expand=True) page.add( ft.Column( [ content, navigation_bar, ], expand=True, ) )ft.app(target=main)
- Assistant
Merhaba! Paylaştığınız Ballistik Hesaplayıcı uygulaması için Flet kullanarak oldukça kapsamlı bir kullanıcı arayüzü oluşturmuşsunuz. Size daha iyi yardımcı olabilmem için hangi konularda desteğe ihtiyacınız olduğunu belirtir misiniz? Aşağıda, kodunuzla ilgili bazı genel gözlemler ve potansiyel iyileştirmeler paylaşıyorum:
1. Eksik Tanımlamalar ve İçe Aktarmalar
Kodunuzda aşağıdaki sınıflar ve fonksiyonlar kullanılmış, ancak bunların tanımları göremedim:
- Sınıflar:
DragModel,Ammo,Weapon,Atmo,Shot,Calculator,TrajectoryCalc,Wind - Fonksiyonlar:
_parse_value,_parse_unit,calculate_lead,_parse_value, vs. - Enumerasyonlar:
Velocity,Angular,Distance,Pressure,Temperature,Weight,TrajFlag,PreferredUnits
Bu bileşenlerin tanımlarını eklemeniz veya doğru modüllerden içe aktardığınızdan emin olmanız gerekiyor. Aksi takdirde, uygulamanız çalıştığında
NameErrorveya benzeri hatalar alabilirsiniz.2. Hata Yönetimi
calculate_trajectoryvecreate_tablefonksiyonlarında genel birexcept Exception as ebloğu kullanıyorsunuz. Bu, hataları yakalamak için iyi bir yöntem olabilir, ancak daha spesifik hataları yakalamak ve kullanıcıya daha anlamlı geri bildirimler sağlamak için özel hata türlerini kullanmayı düşünebilirsiniz.3. Performans ve Optimize Edilebilirlik
- State Yönetimi: Büyük sayıda kontrol ve widget kullandığınız için, belirli bölümlerin güncellenmesi uygulamanın performansını etkileyebilir. Flet'in State Management özelliklerini kullanarak sadece gerekli bileşenleri güncelleyebilirsiniz.
- Kod Tekrarını Azaltma:
create_unit_inputve benzeri yardımcı fonksiyonlar kullanarak kodunuzda tekrar eden yapıları daha modüler hale getirmişsiniz, bu güzel bir yaklaşım.
4. Kullanıcı Deneyimi (UX) İyileştirmeleri
- Görsel Tutarlılık: Renk paletiniz koyu tonlarda ve nötr renkler kullanmışsınız. Kullanıcıların rahatça okuyabileceği ve göz yormayan bir tasarım sağlamak adına kontrastları ve metin boyutlarını gözden geçirebilirsiniz.
- İletişim: Hata mesajlarınızı Türkçe olarak verdiniz ki bu kullanıcı deneyimini artırır. Geri bildirim mekanizmalarınızı genişleterek başarılı işlemleri de bildirebilirsiniz.
5. Navigasyon ve Sayfa Yönetimi
change_pagefonksiyonunda sayfalar arasındaki geçişi yönetiyorsunuz. Daha karmaşık uygulamalarda, sayfaların birbirine bağımlılığını azaltmak için Routing sistemlerini kullanabilirsiniz. Flet'in bu konuda sunduğu özellikleri inceleyebilirsiniz.6. Tema Yönetimi
Tema değiştirme fonksiyonunuz var, ancak tüm bileşenlerin tema değişikliklerine duyarlı olup olmadığını kontrol etmenizde fayda var. Özellikle dinamik olarak değişen bileşenlerin (örneğin, dinamik olarak oluşturulan veri tabloları) temaya uygun renklere sahip olduğundan emin olun.
7. Belgeleme ve Kod Yorumları
Kodunuzda bazı açıklamalar bulunuyor, ancak daha fazla açıklayıcı yorum eklemek, gelecekte kodu gözden geçiren veya geliştiren kişiler (veya siz kendiniz) için faydalı olabilir.
Yardımcı Olabileceğim Konular
- Hata Ayıklama: Belirli bir hata alıyorsanız, hata mesajını ve hangi kısımda aldığınızı paylaşabilirsiniz.
- Fonksiyonellik Geliştirme: Yeni bir özellik eklemek istiyorsanız, ne tür bir özellik olduğunu belirtin.
- Kod Optimizasyonu: Belirli bir kısmın daha verimli nasıl yazılabileceği hakkında öneriler isteyebilirsiniz.
- UI/UX İyileştirmeleri: Arayüzünüzü daha kullanıcı dostu hale getirmek için tavsiyeler verebilirim.
Lütfen hangi konuda daha fazla yardımcı olmamı istediğinizi belirtin, böylece size en iyi şekilde destek olabilirim!
- Sınıflar: