Advertisement
peachyontop

hfgtdfshhf

Apr 4th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. # ... [Keep all previous imports] ...
  2.  
  3. # Update the Builder string with loading indicators
  4. Builder.load_string('''
  5. <WeatherScreen>:
  6. MDScrollViewRefreshLayout:
  7. # ... [Keep previous layout structure] ...
  8.  
  9. MDCard:
  10. id: current_weather_card
  11. # ... [Keep previous content] ...
  12.  
  13. MDBoxLayout:
  14. spacing: dp(20)
  15. adaptive_size: True
  16. center_x: self.parent.center_x
  17.  
  18. MDLabel:
  19. id: weather_icon
  20. text: ""
  21. font_style: "Icon"
  22. size_hint: None, None
  23. size: dp(48), dp(48)
  24. theme_text_color: "Custom"
  25. text_color: 1, 0.8, 0, 1
  26.  
  27. MDLabel:
  28. id: temperature_label
  29. text: "--°C"
  30. font_style: "H2"
  31. halign: "center"
  32. bold: True
  33.  
  34. MDBoxLayout:
  35. id: loading_indicator
  36. size_hint_y: None
  37. height: dp(20)
  38. spacing: dp(5)
  39. pos_hint: {'center_x': 0.5}
  40.  
  41. MDSpinner:
  42. size_hint: None, None
  43. size: dp(20), dp(20)
  44. active: False
  45. palette: [
  46. app.theme_cls.primary_color,
  47. app.theme_cls.accent_color,
  48. app.theme_cls.primary_light,
  49. ]
  50.  
  51. # ... [Keep rest of the layout] ...
  52. ''')
  53.  
  54. class WeatherScreen(MDScreen):
  55. def show_loading(self, show):
  56. # Update loading state with spinner
  57. spinner = self.ids.loading_indicator.children[0]
  58. spinner.active = show
  59. for widget_id in ['current_weather_card', 'location_card', 'hourly_forecast_card', 'details_card']:
  60. self.ids[widget_id].opacity = 0.3 if show else 1
  61. self.ids.refresh_layout.refreshing = show
  62.  
  63. def get_location_and_fetch_weather(self):
  64. try:
  65. if platform == "android":
  66. from android.permissions import Permission, request_permissions
  67. request_permissions([
  68. Permission.ACCESS_FINE_LOCATION,
  69. Permission.ACCESS_COARSE_LOCATION,
  70. Permission.INTERNET
  71. ])
  72.  
  73. # ... [Rest of location code] ...
  74.  
  75. except Exception as e:
  76. print(f"Permission error: {e}")
  77. self.fetch_weather(48.4, 10.0, False)
  78.  
  79. def reverse_geocode(self, lat, lon, used_gps):
  80. try:
  81. # Add proper user agent for Nominatim
  82. headers = {
  83. "User-Agent": "MyWeatherApp/1.0 ([email protected])"
  84. }
  85. # ... [Rest of geocode code] ...
  86.  
  87. except Exception as e:
  88. print(f"Geocode error: {e}")
  89. Clock.schedule_once(lambda dt: setattr(
  90. self.ids.location_label,
  91. 'text',
  92. f"Approximate Location\n({lat:.2f}, {lon:.2f})"
  93. ))
  94.  
  95. def update_hourly_forecast(self, times, temps):
  96. try:
  97. # Limit to 12 hours for better mobile performance
  98. times = times[:12]
  99. temps = temps[:12]
  100.  
  101. # ... [Rest of forecast code] ...
  102.  
  103. except Exception as e:
  104. print(f"Forecast error: {e}")
  105. self.ids.hourly_forecast_container.clear_widgets()
  106.  
  107. def show_error(self, message):
  108. Clock.schedule_once(lambda dt: super().show_error(message))
  109. with open("weather_errors.log", "a") as f:
  110. f.write(f"{datetime.now()} - {message}\n")
  111.  
  112. # ... [Keep rest of the class] ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement