Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modified the _set_value function logic based on the mode of MMenu #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions dayu_widgets/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,34 @@ def set_value(self, data):
self.setProperty("value", data)

def _set_value(self, value):
data_list = value if isinstance(value, list) else [value]
"""
mode 1: Cascader
mode 2: Exclusive
mode 3: Single
"""
if self.property("cascader"):
selected_data = ['/'.join(map(str, value))]
else:
if self._action_group.isExclusive():
selected_data = [value]
else:
selected_data = value
Comment on lines +550 to +555
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你看看如果是修改成这样是否也能符合预期?

Suggested change
selected_data = ['/'.join(map(str, value))]
else:
if self._action_group.isExclusive():
selected_data = [value]
else:
selected_data = value
selected_data = ['/'.join(map(str, value))]
else:
selected_data = [value]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把 "/" 改为 self.property("separator") 吧


flag = False
for act in self._action_group.actions():
if act.property("long_path"):
# Ensure all values is string type.
selected = "/".join(map(str, data_list))
checked = act.property("long_path") == selected
if self.property("cascader"):
act_value = self.property("cascader") and act.property("long_path") or act.property("value")
else:
checked = act.property("value") in data_list
if self._action_group.isExclusive():
act_value = act.property("value")
else:
act_value = act.property("value")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

读了下上下文 感觉这里可以直接简化成这样

act_value = self.property("cascader") and act.property("long_path") or act.property("value")

checked = act_value in selected_data
if act.isChecked() != checked: # 更新来自代码
act.setChecked(checked)
flag = True

if flag:
self.sig_value_changed.emit(value)

Expand Down