Skip to content

Commit

Permalink
Merge pull request #70 from HowieHz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
HowieHz authored May 28, 2022
2 parents 7e8467a + 00a05f1 commit 62c80de
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 92 deletions.
6 changes: 3 additions & 3 deletions .idea/fileTemplates/单文件插件模板.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/hpyculator.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Plugin/CamelCase_and_UnderScoreCase_hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
输出格式
转换后的字符串
输入样例
a_b,0,1
A_B 3 1
Expand Down
8 changes: 3 additions & 5 deletions src/Plugin/Prime_Palindromes_JIT_hz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
输入数字n(n为正整数),输出 >=0且<=n 回文质数
对于输入小于100030001的数 有着绝佳的性能
使用了即时编译(JIT)技术,对于>100030000的数第一次运行稍慢
""", # 帮助和说明(可选)
"output_end": "", # 输出小尾巴(可选)
Expand Down Expand Up @@ -863,10 +863,8 @@ def scope_builder(num):
ret = int(num / 10 ** ((num_len + 1) / 2 - 1))
if int(str(ret) + str(ret)[-2::-1]) <= num:
return int(num / 10 ** ((num_len + 1) / 2 - 1))
else:
return int(num / 10 ** ((num_len + 1) / 2 - 1) - 1)
else: # 偶数位
return int(9 * (1 - 10 ** (num_len / 2)) / -9) # 9*(10**0+10**1+10**2)
return int(num / 10 ** ((num_len + 1) / 2 - 1) - 1)
return int(9 * (1 - 10 ** (num_len / 2)) / -9) # 9*(10**0+10**1+10**2)


@numba.jit(nopython=True)
Expand Down
6 changes: 2 additions & 4 deletions src/Plugin/Prime_Palindromes_hz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,8 @@ def scope_builder(num):
ret = int(num / 10 ** ((num_len + 1) / 2 - 1))
if int(str(ret) + str(ret)[-2::-1]) <= num:
return int(num / 10 ** ((num_len + 1) / 2 - 1))
else:
return int(num / 10 ** ((num_len + 1) / 2 - 1) - 1)
else: # 偶数位
return int(9 * (1 - 10 ** (num_len / 2)) / -9) # 9*(10**0+10**1+10**2)
return int(num / 10 ** ((num_len + 1) / 2 - 1) - 1)
return int(9 * (1 - 10 ** (num_len / 2)) / -9) # 9*(10**0+10**1+10**2)


def is_prime(num):
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/heron_s_formula_hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
输出格式
以A,B,C为边长的三角形的面积
输入样例
12,12,12
12,12,12
Expand Down
22 changes: 8 additions & 14 deletions src/Plugin/is_prime_hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
输入格式:
n(n为正整数且n>1)
使用了jit技术,第一次运行稍慢
""",
"output_end": "",
Expand All @@ -38,13 +38,12 @@ def is_prime_jit(num):
:param num:
:return:
"""
if (num == 2) or (num == 3):
if num in (2, 3):
return True, 0
if (num % 6 != 1) and (num % 6 != 5):
if num % 2 == 0:
return False, 2
else:
return False, 3
return False, 3
for i in range(5, int(num**0.5) + 1, 6):
if (num % i == 0) or (num % (i + 2) == 0):
return False, i
Expand All @@ -61,8 +60,7 @@ def is_prime(num):
if (num % 6 != 1) and (num % 6 != 5):
if num % 2 == 0:
return False, 2
else:
return False, 3
return False, 3
for i in range(5, int(num**0.5) + 1, 6):
if (num % i == 0) or (num % (i + 2) == 0):
return False, i
Expand All @@ -80,8 +78,7 @@ def is_prime_big_int(num):
if (int(num) % 6 != 1) and (num % 6 != 5):
if num % 2 == 0:
return False, 2
else:
return False, 3
return False, 3
for i in range(5, int(Decimal(num) / 2) + 1, 6):
if (num % i == 0) or (num % (i + 2) == 0):
return False, i
Expand All @@ -97,16 +94,13 @@ def on_calculate(num: str):
answer = is_prime_big_int(num)
if answer[0]:
return f"{num}是质数"
else:
return f"{num}不是质数,有一个因数是{answer[1]}"
return f"{num}不是质数,有一个因数是{answer[1]}"
if num > 9223372036854775807:
answer = is_prime(num)
if answer[0]:
return f"{num}是质数"
else:
return f"{num}不是质数,有一个因数是{answer[1]}"
return f"{num}不是质数,有一个因数是{answer[1]}"
answer = is_prime_jit(num)
if answer[0]:
return f"{num}是质数"
else:
return f"{num}不是质数,有一个因数是{answer[1]}"
return f"{num}不是质数,有一个因数是{answer[1]}"
2 changes: 1 addition & 1 deletion src/Plugin/prime_hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"help": """\
输入格式
n(n为正整数且n>1)
输入样例
1
""", # 帮助和说明
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def __init__(self, parent=None):
# self.titleBar.raise_()
self.resize(500, 500)

def resizeEvent(self, e):
"""Adjust the width and icon of title bar"""
super().resizeEvent(e)
# self.titleBar.resize(self.width(), self.titleBar.height())
# self.titleBar.maxBtn.setMaxState(
# self._isWindowMaximized(int(self.winId())))

def _isWindowMaximized(self, hWnd):
"""Determine whether the window is maximized"""
return self.isMaximized()
Expand Down Expand Up @@ -83,53 +76,54 @@ def nativeEvent(self, eventType, message):
by = yPos > h - self.BORDER_WIDTH
if lx and ty:
return True, win32con.HTTOPLEFT
elif rx and by:
if rx and by:
return True, win32con.HTBOTTOMRIGHT
elif rx and ty:
if rx and ty:
return True, win32con.HTTOPRIGHT
elif lx and by:
if lx and by:
return True, win32con.HTBOTTOMLEFT
elif ty:
if ty:
return True, win32con.HTTOP
elif by:
if by:
return True, win32con.HTBOTTOM
elif lx:
if lx:
return True, win32con.HTLEFT
elif rx:
if rx:
return True, win32con.HTRIGHT
elif msg.message == win32con.WM_NCCALCSIZE:
if self._isWindowMaximized(msg.hWnd):
self.__monitorNCCALCSIZE(msg)
return True, 0
elif msg.message == win32con.WM_GETMINMAXINFO:
if self._isWindowMaximized(msg.hWnd):
window_rect = win32gui.GetWindowRect(msg.hWnd)
if not window_rect:
return False, 0

# get the monitor handle
monitor = win32api.MonitorFromRect(window_rect)
if not monitor:
return False, 0

# get the monitor info
__monitorInfo = win32api.GetMonitorInfo(monitor)
monitor_rect = __monitorInfo["Monitor"]
work_area = __monitorInfo["Work"]

# convert lParam to MINMAXINFO pointer
info = cast(msg.lParam, POINTER(MINMAXINFO)).contents

# adjust the size of window
info.ptMaxSize.x = work_area[2] - work_area[0]
info.ptMaxSize.y = work_area[3] - work_area[1]
info.ptMaxTrackSize.x = info.ptMaxSize.x
info.ptMaxTrackSize.y = info.ptMaxSize.y

# modify the upper left coordinate
info.ptMaxPosition.x = abs(window_rect[0] - monitor_rect[0])
info.ptMaxPosition.y = abs(window_rect[1] - monitor_rect[1])
return True, 1
elif msg.message == win32con.WM_GETMINMAXINFO and self._isWindowMaximized(
msg.hWnd
):
window_rect = win32gui.GetWindowRect(msg.hWnd)
if not window_rect:
return False, 0

# get the monitor handle
monitor = win32api.MonitorFromRect(window_rect)
if not monitor:
return False, 0

# get the monitor info
__monitorInfo = win32api.GetMonitorInfo(monitor)
monitor_rect = __monitorInfo["Monitor"]
work_area = __monitorInfo["Work"]

# convert lParam to MINMAXINFO pointer
info = cast(msg.lParam, POINTER(MINMAXINFO)).contents

# adjust the size of window
info.ptMaxSize.x = work_area[2] - work_area[0]
info.ptMaxSize.y = work_area[3] - work_area[1]
info.ptMaxTrackSize.x = info.ptMaxSize.x
info.ptMaxTrackSize.y = info.ptMaxSize.y

# modify the upper left coordinate
info.ptMaxPosition.x = abs(window_rect[0] - monitor_rect[0])
info.ptMaxPosition.y = abs(window_rect[1] - monitor_rect[1])
return True, 1

return QWidget.nativeEvent(self, eventType, message)

Expand All @@ -149,7 +143,7 @@ def __monitorNCCALCSIZE(self, msg):
# If the display information is not saved, return directly
if monitor is None and not self.__monitorInfo:
return
elif monitor is not None:
if monitor is not None:
self.__monitorInfo = win32api.GetMonitorInfo(monitor)

# adjust the size of window
Expand Down
3 changes: 2 additions & 1 deletion src/builtin_modules/ui_manager/about_win_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _show_about(): # 关于
}
dict_jump_map[qstring]()

def event_check_update(self):
@staticmethod
def event_check_update():
"""检查更新"""
webbrowser.open("https://github.com/HowieHz/hpyculator/releases")
16 changes: 6 additions & 10 deletions src/builtin_modules/ui_manager/main_win_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,7 @@ def _tag_check(tags: list[str], tag_and_option: tuple[tuple[str], str]) -> bool:
:param tag_and_option: 单项 tag和选项名_tag_and_option ((tag1,tag2),name)
:return:
"""
for _tag in tags:
if not (_tag in tag_and_option[0]):
return False
return True
return all((_tag in tag_and_option[0]) for _tag in tags)

_search_keyword = self.ui.search_plugin.toPlainText()

Expand All @@ -639,12 +636,11 @@ def _tag_check(tags: list[str], tag_and_option: tuple[tuple[str], str]) -> bool:

self.ui.list_choices_plugin.addItems(_set_matched_item) # 匹配的添加到选框
return None
else: # 选项名搜索模式
for i in self.selection_list: # 选出符合要求的
if i.find(_search_keyword) == -1: # 字符串方法,没找到指定子串就-1
continue
self.ui.list_choices_plugin.addItem(i)
return None
for i in self.selection_list: # 选出符合要求的
if i.find(_search_keyword) == -1: # 字符串方法,没找到指定子串就-1
continue
self.ui.list_choices_plugin.addItem(i)
return None

def event_search_cancel(self) -> None:
"""
Expand Down
4 changes: 0 additions & 4 deletions src/builtin_modules/ui_manager/setting_win_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ def event_choose_background_img(self, qstring):
self.SETTING_FILE_PATH, "w+", encoding="utf-8"
) as setting_file: # 写入配置文件
toml.dump(dict_setting, setting_file)
# background_img_path = pathlib.Path(self.background_dir_path).joinpath(qstring)
# if background_img_path.is_file():
# self.bg_img = QPixmap(background_img_path)
return

def event_open_background_dir(self):
"""
Expand Down

0 comments on commit 62c80de

Please sign in to comment.