|
|
|
|
@ -13,6 +13,9 @@ from datetime import datetime
|
|
|
|
|
class WordRibbonTab(QWidget):
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
self.weather_group = None # 天气组件组
|
|
|
|
|
self.weather_visible = False # 天气组件显示状态
|
|
|
|
|
self.ribbon_layout = None # 功能区布局
|
|
|
|
|
self.setup_ui()
|
|
|
|
|
|
|
|
|
|
def setup_ui(self):
|
|
|
|
|
@ -24,6 +27,11 @@ class WordRibbonTab(QWidget):
|
|
|
|
|
class WordRibbon(QFrame):
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
self.weather_visible = False # 天气组件显示状态
|
|
|
|
|
self.weather_group = None # 天气组件组
|
|
|
|
|
self.quote_visible = False # 每日一言组件显示状态
|
|
|
|
|
self.quote_group = None # 每日一言组件组
|
|
|
|
|
self.ribbon_layout = None # 功能区布局
|
|
|
|
|
self.setup_ui()
|
|
|
|
|
|
|
|
|
|
def setup_ui(self):
|
|
|
|
|
@ -45,42 +53,16 @@ class WordRibbon(QFrame):
|
|
|
|
|
}
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
ribbon_layout = QHBoxLayout()
|
|
|
|
|
ribbon_layout.setContentsMargins(10, 5, 10, 5)
|
|
|
|
|
ribbon_layout.setSpacing(15)
|
|
|
|
|
self.ribbon_layout = QHBoxLayout() # 保存为实例变量
|
|
|
|
|
self.ribbon_layout.setContentsMargins(10, 5, 10, 5)
|
|
|
|
|
self.ribbon_layout.setSpacing(15)
|
|
|
|
|
|
|
|
|
|
# 开始标签的内容(最常用的功能)
|
|
|
|
|
self.setup_home_tab(ribbon_layout)
|
|
|
|
|
self.setup_home_tab(self.ribbon_layout)
|
|
|
|
|
|
|
|
|
|
# 添加天气工具组
|
|
|
|
|
weather_group = self.create_ribbon_group("天气")
|
|
|
|
|
weather_layout = QVBoxLayout()
|
|
|
|
|
|
|
|
|
|
# 城市选择 - 添加所有省会城市
|
|
|
|
|
self.city_combo = QComboBox()
|
|
|
|
|
self.city_combo.setFixedWidth(120) # 增加宽度以显示完整城市名
|
|
|
|
|
self.city_combo.addItems([
|
|
|
|
|
'自动定位',
|
|
|
|
|
'北京', '上海', '广州', '深圳', '杭州', '南京', '武汉', '成都', '西安', # 一线城市
|
|
|
|
|
'天津', '重庆', '苏州', '青岛', '大连', '宁波', '厦门', '无锡', '佛山', # 新一线城市
|
|
|
|
|
'石家庄', '太原', '呼和浩特', '沈阳', '长春', '哈尔滨', # 东北华北
|
|
|
|
|
'合肥', '福州', '南昌', '济南', '郑州', '长沙', '南宁', '海口', # 华东华中华南
|
|
|
|
|
'贵阳', '昆明', '拉萨', '兰州', '西宁', '银川', '乌鲁木齐' # 西南西北
|
|
|
|
|
])
|
|
|
|
|
self.city_combo.setCurrentText('自动定位')
|
|
|
|
|
self.city_combo.currentTextChanged.connect(self.on_city_changed)
|
|
|
|
|
|
|
|
|
|
# 刷新按钮
|
|
|
|
|
self.refresh_weather_btn = QPushButton("刷新天气")
|
|
|
|
|
self.refresh_weather_btn.clicked.connect(self.on_refresh_weather)
|
|
|
|
|
self.refresh_weather_btn.setFixedSize(80, 25)
|
|
|
|
|
# 天气工具组将在需要时动态添加
|
|
|
|
|
|
|
|
|
|
weather_layout.addWidget(self.city_combo)
|
|
|
|
|
weather_layout.addWidget(self.refresh_weather_btn)
|
|
|
|
|
weather_group.setLayout(weather_layout)
|
|
|
|
|
ribbon_layout.addWidget(weather_group)
|
|
|
|
|
|
|
|
|
|
self.ribbon_area.setLayout(ribbon_layout)
|
|
|
|
|
self.ribbon_area.setLayout(self.ribbon_layout)
|
|
|
|
|
|
|
|
|
|
main_layout.addWidget(self.ribbon_area)
|
|
|
|
|
self.setLayout(main_layout)
|
|
|
|
|
@ -186,6 +168,105 @@ class WordRibbon(QFrame):
|
|
|
|
|
"""下划线按钮点击处理"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def create_weather_group(self):
|
|
|
|
|
"""创建天气组件组"""
|
|
|
|
|
if self.weather_group is not None:
|
|
|
|
|
return self.weather_group
|
|
|
|
|
|
|
|
|
|
weather_group = self.create_ribbon_group("天气")
|
|
|
|
|
weather_layout = QVBoxLayout()
|
|
|
|
|
|
|
|
|
|
# 城市选择 - 添加所有省会城市
|
|
|
|
|
self.city_combo = QComboBox()
|
|
|
|
|
self.city_combo.setFixedWidth(120) # 增加宽度以显示完整城市名
|
|
|
|
|
self.city_combo.addItems([
|
|
|
|
|
'自动定位',
|
|
|
|
|
'北京', '上海', '广州', '深圳', '杭州', '南京', '武汉', '成都', '西安', # 一线城市
|
|
|
|
|
'天津', '重庆', '苏州', '青岛', '大连', '宁波', '厦门', '无锡', '佛山', # 新一线城市
|
|
|
|
|
'石家庄', '太原', '呼和浩特', '沈阳', '长春', '哈尔滨', # 东北华北
|
|
|
|
|
'合肥', '福州', '南昌', '济南', '郑州', '长沙', '南宁', '海口', # 华东华中华南
|
|
|
|
|
'贵阳', '昆明', '拉萨', '兰州', '西宁', '银川', '乌鲁木齐' # 西南西北
|
|
|
|
|
])
|
|
|
|
|
self.city_combo.setCurrentText('自动定位')
|
|
|
|
|
self.city_combo.currentTextChanged.connect(self.on_city_changed)
|
|
|
|
|
|
|
|
|
|
# 刷新按钮
|
|
|
|
|
self.refresh_weather_btn = QPushButton("刷新天气")
|
|
|
|
|
self.refresh_weather_btn.clicked.connect(self.on_refresh_weather)
|
|
|
|
|
self.refresh_weather_btn.setFixedSize(80, 25)
|
|
|
|
|
|
|
|
|
|
weather_layout.addWidget(self.city_combo)
|
|
|
|
|
weather_layout.addWidget(self.refresh_weather_btn)
|
|
|
|
|
weather_group.setLayout(weather_layout)
|
|
|
|
|
|
|
|
|
|
self.weather_group = weather_group
|
|
|
|
|
return weather_group
|
|
|
|
|
|
|
|
|
|
def show_weather_group(self):
|
|
|
|
|
"""显示天气组件"""
|
|
|
|
|
if not self.weather_visible and self.weather_group is None:
|
|
|
|
|
weather_group = self.create_weather_group()
|
|
|
|
|
# 在编辑组之后添加天气组
|
|
|
|
|
if self.ribbon_layout:
|
|
|
|
|
# 找到编辑组的位置,在其后插入天气组
|
|
|
|
|
insert_index = self.ribbon_layout.count() - 1 # 在stretch之前插入
|
|
|
|
|
self.ribbon_layout.insertWidget(insert_index, weather_group)
|
|
|
|
|
self.weather_visible = True
|
|
|
|
|
|
|
|
|
|
def hide_weather_group(self):
|
|
|
|
|
"""隐藏天气组件"""
|
|
|
|
|
if self.weather_visible and self.weather_group is not None:
|
|
|
|
|
self.weather_group.setParent(None)
|
|
|
|
|
self.weather_group = None
|
|
|
|
|
self.weather_visible = False
|
|
|
|
|
|
|
|
|
|
def create_quote_group(self):
|
|
|
|
|
"""创建每日一言组件组"""
|
|
|
|
|
if self.quote_group is not None:
|
|
|
|
|
return self.quote_group
|
|
|
|
|
|
|
|
|
|
quote_group = self.create_ribbon_group("每日一言")
|
|
|
|
|
quote_layout = QVBoxLayout()
|
|
|
|
|
|
|
|
|
|
# 每日一言显示标签
|
|
|
|
|
self.quote_label = QLabel("每日一言: 暂无")
|
|
|
|
|
self.quote_label.setStyleSheet("QLabel { color: #666666; font-style: italic; font-size: 10px; }")
|
|
|
|
|
self.quote_label.setWordWrap(True)
|
|
|
|
|
self.quote_label.setFixedWidth(150)
|
|
|
|
|
|
|
|
|
|
# 刷新按钮
|
|
|
|
|
self.refresh_quote_btn = QPushButton("刷新箴言")
|
|
|
|
|
self.refresh_quote_btn.clicked.connect(self.on_refresh_quote)
|
|
|
|
|
self.refresh_quote_btn.setFixedSize(80, 25)
|
|
|
|
|
|
|
|
|
|
quote_layout.addWidget(self.quote_label)
|
|
|
|
|
quote_layout.addWidget(self.refresh_quote_btn)
|
|
|
|
|
quote_group.setLayout(quote_layout)
|
|
|
|
|
|
|
|
|
|
self.quote_group = quote_group
|
|
|
|
|
return quote_group
|
|
|
|
|
|
|
|
|
|
def show_quote_group(self):
|
|
|
|
|
"""显示每日一言组件"""
|
|
|
|
|
if not self.quote_visible and self.quote_group is None:
|
|
|
|
|
quote_group = self.create_quote_group()
|
|
|
|
|
# 在天气组之后添加每日一言组
|
|
|
|
|
if self.ribbon_layout:
|
|
|
|
|
# 找到合适的位置插入每日言组
|
|
|
|
|
insert_index = self.ribbon_layout.count() - 1 # 在stretch之前插入
|
|
|
|
|
# 如果天气组件存在,在其后插入;否则在编辑组后插入
|
|
|
|
|
if self.weather_group is not None and self.weather_visible:
|
|
|
|
|
insert_index = self.ribbon_layout.indexOf(self.weather_group) + 1
|
|
|
|
|
self.ribbon_layout.insertWidget(insert_index, quote_group)
|
|
|
|
|
self.quote_visible = True
|
|
|
|
|
|
|
|
|
|
def hide_quote_group(self):
|
|
|
|
|
"""隐藏每日一言组件"""
|
|
|
|
|
if self.quote_visible and self.quote_group is not None:
|
|
|
|
|
self.quote_group.setParent(None)
|
|
|
|
|
self.quote_group = None
|
|
|
|
|
self.quote_visible = False
|
|
|
|
|
|
|
|
|
|
def create_ribbon_group(self, title):
|
|
|
|
|
"""创建功能区组"""
|
|
|
|
|
group = QGroupBox(title)
|
|
|
|
|
@ -215,6 +296,15 @@ class WordRibbon(QFrame):
|
|
|
|
|
"""城市选择变化处理"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def on_refresh_quote(self):
|
|
|
|
|
"""刷新每日一言按钮点击处理"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def update_quote_display(self, quote_text):
|
|
|
|
|
"""更新每日一言显示"""
|
|
|
|
|
if hasattr(self, 'quote_label') and self.quote_label:
|
|
|
|
|
self.quote_label.setText(f"每日一言: {quote_text}")
|
|
|
|
|
|
|
|
|
|
def create_ribbon_button(self, text, shortcut, icon_name):
|
|
|
|
|
"""创建功能区按钮"""
|
|
|
|
|
btn = QToolButton()
|
|
|
|
|
|