|
|
|
|
@ -337,8 +337,8 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
view_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 天气功能
|
|
|
|
|
weather_menu = view_menu.addMenu('天气信息')
|
|
|
|
|
# 附加工具功能
|
|
|
|
|
weather_menu = view_menu.addMenu('附加工具')
|
|
|
|
|
|
|
|
|
|
# 显示天气工具组
|
|
|
|
|
self.show_weather_tools_action = QAction('显示天气工具', self)
|
|
|
|
|
@ -612,7 +612,7 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
print(f"接收到天气数据: {weather_data}")
|
|
|
|
|
if 'error' in weather_data:
|
|
|
|
|
print(f"天气显示错误: {weather_data['error']}")
|
|
|
|
|
self.status_bar.showMessage(f"天气信息获取失败: {weather_data['error']}", 3000)
|
|
|
|
|
self.status_bar.showMessage(f"天气数据获取失败: {weather_data['error']}", 3000)
|
|
|
|
|
else:
|
|
|
|
|
city = weather_data.get('city', '未知城市')
|
|
|
|
|
temp = weather_data.get('temperature', 'N/A')
|
|
|
|
|
@ -654,9 +654,9 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
'forecast': weather_data['forecast']
|
|
|
|
|
}
|
|
|
|
|
self.update_weather_display(formatted_data)
|
|
|
|
|
self.status_bar.showMessage("天气信息已刷新", 2000)
|
|
|
|
|
self.status_bar.showMessage("天气数据已刷新", 2000)
|
|
|
|
|
else:
|
|
|
|
|
self.status_bar.showMessage("天气信息刷新失败,请检查API密钥", 3000)
|
|
|
|
|
self.status_bar.showMessage("天气数据刷新失败,请检查API密钥", 3000)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
self.status_bar.showMessage(f"天气刷新失败: {str(e)}", 3000)
|
|
|
|
|
|
|
|
|
|
@ -666,14 +666,14 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
# 检查是否有天气数据
|
|
|
|
|
if not hasattr(self, 'current_weather_data') or not self.current_weather_data:
|
|
|
|
|
QMessageBox.information(self, "天气信息", "暂无天气数据,请先刷新天气信息")
|
|
|
|
|
QMessageBox.information(self, "附加工具", "暂无天气数据,请先刷新天气信息")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
weather_data = self.current_weather_data
|
|
|
|
|
|
|
|
|
|
# 创建对话框
|
|
|
|
|
dialog = QDialog(self)
|
|
|
|
|
dialog.setWindowTitle("详细天气信息")
|
|
|
|
|
dialog.setWindowTitle("详细天气")
|
|
|
|
|
dialog.setMinimumWidth(400)
|
|
|
|
|
|
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
|
@ -765,11 +765,10 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.status_bar.showMessage("每日一言工具已隐藏", 2000)
|
|
|
|
|
|
|
|
|
|
def refresh_daily_quote(self):
|
|
|
|
|
"""刷新每日一言 - 使用线程获取"""
|
|
|
|
|
# 创建并启动获取名言的线程
|
|
|
|
|
self.quote_thread = QuoteFetchThread()
|
|
|
|
|
self.quote_thread.quote_fetched.connect(self.on_quote_fetched)
|
|
|
|
|
self.quote_thread.start()
|
|
|
|
|
"""刷新每日一言 - 使用WordRibbon中的API"""
|
|
|
|
|
if hasattr(self, 'ribbon'):
|
|
|
|
|
# 直接调用WordRibbon中的刷新方法
|
|
|
|
|
self.ribbon.on_refresh_quote()
|
|
|
|
|
|
|
|
|
|
def on_quote_fetched(self, quote_data):
|
|
|
|
|
"""处理名言获取成功"""
|
|
|
|
|
@ -779,23 +778,23 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
quote_text = f"{content} — {author}"
|
|
|
|
|
|
|
|
|
|
# 更新Ribbon中的每日一言显示
|
|
|
|
|
if hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"每日一言: {quote_text}")
|
|
|
|
|
if hasattr(self, 'ribbon') and hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"{quote_text}")
|
|
|
|
|
|
|
|
|
|
# 更新状态栏
|
|
|
|
|
self.status_bar.showMessage(f"每日名言: {quote_text}", 10000)
|
|
|
|
|
else:
|
|
|
|
|
# 处理错误情况
|
|
|
|
|
error_msg = quote_data.get('error', '获取名言失败')
|
|
|
|
|
if hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"每日一言: 获取失败")
|
|
|
|
|
if hasattr(self, 'ribbon') and hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"获取失败")
|
|
|
|
|
self.status_bar.showMessage(f"每日名言获取失败: {error_msg}", 5000)
|
|
|
|
|
|
|
|
|
|
def on_quote_error(self, error_data):
|
|
|
|
|
"""处理名言获取错误"""
|
|
|
|
|
error_msg = error_data.get('error', '获取名言失败') if isinstance(error_data, dict) else str(error_data)
|
|
|
|
|
if hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"每日一言: 获取失败")
|
|
|
|
|
if hasattr(self, 'ribbon') and hasattr(self.ribbon, 'quote_label'):
|
|
|
|
|
self.ribbon.quote_label.setText(f"获取失败")
|
|
|
|
|
self.status_bar.showMessage(f"每日名言获取失败: {error_msg}", 5000)
|
|
|
|
|
|
|
|
|
|
def update_quote_display(self, quote_data):
|
|
|
|
|
|