Skip to content

Commit

Permalink
Merge pull request #15 from fandesfyf/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
fandesfyf authored Jun 19, 2023
2 parents 23a7a78 + e7285c1 commit c1f7a1f
Show file tree
Hide file tree
Showing 45 changed files with 212 additions and 7,680 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
__pycache__
j_temp
.idea
build
build/*
!build/installer
dist
sometest
*.so
*.zip
Expand Down
43 changes: 36 additions & 7 deletions CoreModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@
import qt_material
from jamscreenshot import Slabel
# from aip import AipOcr
from fbs_runtime.application_context.PyQt5 import ApplicationContext
# from fbs_runtime.application_context.PyQt5 import ApplicationContext
from pynput import keyboard, mouse
from jamcontroller import ActionController, ActionCondition
from WEBFilesTransmitter import WebFilesTransmitter, WebFilesTransmitterBox, apppath
from jamspeak import Speaker
from clientFilesTransmitter import ClientFilesTransmitterGroupbox
from jam_transtalater import Translator
import jamresourse
from pynput.mouse import Controller


if PLATFORM_SYS == "win32":
import win32con
Expand All @@ -62,14 +64,16 @@
ctypes.windll.shcore.SetProcessDpiAwareness(2)
except Exception as e:
print(e)
import pynput.keyboard._win32
import pynput.mouse._win32
if PLATFORM_SYS == "darwin":
import pynput.keyboard._darwin
import pynput.mouse._darwin
elif PLATFORM_SYS == "linux":
import pynput.keyboard._xorg
import pynput.mouse._xorg

VERSON = "0.14.0B"
VERSON = "0.14.1B"


class JHotkey(QThread):
Expand Down Expand Up @@ -324,6 +328,7 @@ def __init__(self, parent):
self.showrect = Transparent_windows()
self.x = 0
self.y = 0
self.using_area = False
self.w = self.maxw = QApplication.desktop().width() // 2 * 2
self.h = self.maxh = QApplication.desktop().height() // 2 * 2

Expand Down Expand Up @@ -352,6 +357,19 @@ def init_arearecord(self):
QStandardPaths.MoviesLocation) + "/Jam_screenrecord")

def area_recording(self):
screen_number = 0
if not self.using_area:
if QApplication.desktop().screenCount()>1:
screen=self.search_in_which_screen()
else:
screen=QApplication.primaryScreen()
ssize = screen.geometry()
self.w = self.maxw = ssize.width() // 2 * 2
self.h = self.maxh = ssize.height() // 2 * 2

desktop = QApplication.desktop()
screen_number = desktop.screenNumber(desktop.cursor().pos())
print("screen_number",screen_number)
self.codec = 'libx264 '
profile = ' high444 -level 5.1 '
try:
Expand Down Expand Up @@ -456,7 +474,7 @@ def area_recording(self):
self.y,
self.w,
self.h)
video = ' -thread_queue_size 16 -f gdigrab -rtbufsize 500M ' + area + ' -i desktop '
video = ' -thread_queue_size 16 -f gdigrab -rtbufsize 500M ' + area + ' -i desktop{} '.format(f":{screen_number}")
else:
video = " -video_size {}x{} -f x11grab -draw_mouse {} -i :0.0+{},{} ".format(self.w, self.h,
self.mouse, self.x,
Expand Down Expand Up @@ -547,7 +565,16 @@ def area_recording(self):
+ audio
+ out_file
+ ' -y')

def search_in_which_screen(self):
mousepos=Controller().position
screens = QApplication.screens()
secondscreen = QApplication.primaryScreen()
for i in screens:
rect=i.geometry().getRect()
if mousepos[0]in range(rect[0],rect[0]+rect[2]) and mousepos[1]in range(rect[1],rect[1]+rect[3]):
secondscreen = i
break
return secondscreen
# -framerate 5 -draw_mouse 1 -show_region 1 显示截取区域 -i title={窗口名称} 用-framerate在macos下报错 用-r代替
def recordchange(self):
if self.waiting:
Expand Down Expand Up @@ -3794,6 +3821,7 @@ def getpix_result_callback(self,area,pix):
def set_area_callback(self,area):
print('setting recarea',area)
self.recorder.x , self.recorder.y, self.recorder.w,self.recorder.h = area
self.recorder.using_area = True

def screen_shot_end_callback(self,pic):
self.setup_ui_screenshot()
Expand Down Expand Up @@ -5695,8 +5723,9 @@ def main():
global jamtools, ffmpeg_path, documents_path, temp_path, iconpng, paypng, transformater, \
translator
start_t = time.time()
appctxt = ApplicationContext()
single_instance_check = StartUpChecker(appctxt.app)
# appctxt = ApplicationContext()
app = QApplication(sys.argv)
single_instance_check = StartUpChecker(app)
ffmpeg_path = os.path.join(apppath, 'bin', PLATFORM_SYS)
documents_path = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)

Expand All @@ -5718,7 +5747,7 @@ def main():
jamtools.init_rec_con_thread.start()
jamtools.statusBar().showMessage('初始化用时:%f' % float(time.time() - start_t))
print('init_swindowtime:', time.time() - start_t)
sys.exit(appctxt.app.exec_())
sys.exit(app.exec_())


if __name__ == '__main__':
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ $其他功能:划屏提字:打开软件后可以在任何界面(图片也可
│ jamroll_screenshot.py //滚动截屏模块
│ jampublic.py //一些非常常用的公共引用类/方法,如翻译文字识别线程类等
│ jamresourse.py //转化的资源文件
│ jamtoolsbuild.py //一键构建脚本,调用该脚本即可自动分析项目引用,自动配置项目文件,自动编译/打包等
│ jamtoolsbuild.py //一键构建脚本,调用该脚本即可自动分析项目引用,自动配置项目文件,自动编译/打包等, 基于fbs,后续将移除
│ setjam.py //附加编译脚本,如在构建脚本中设置了编译,则会调用该脚本将所有库转化为c文件后编译,需要Cython支持
| 以下几个库文件是(作者自行编译的)不同平台下的缩略版opencv库(10M+),现在默认clone的项目将不会包含这些文件(因为太大了clone起来太慢),已经放在release里面了,要小一点的文件的话就自己去下载,或者直接安装完全版的opencv-contrib-python==3.4.2.17(70M+)..
│ \ cv2.cp37-win_amd64.pyd //windows下编译的opencv库,如需扩展功能,请自行安装opencv-contrib-python==3.4.2.17
Expand Down Expand Up @@ -305,4 +305,17 @@ opencv-contrib-python # 如果需要更小体积的cv2,则可以从[这里](http

此外,本软件多媒体处理能力主要依赖于[ffmpeg库](https://ffmpeg.org/),需要自行下载[ffmpeg](https://ffmpeg.org/)(用于录屏和多媒体处理)和[gifsicle](http://www.lcdf.org/gifsicle/)(用于gif压缩)可执行文件放到bin目录对应操作系统的文件夹下,方可使用对应功能.

配置好以上环境后,可以通过运行`jamtoolsbuild.py`文件一键打包对应平台下的包,然后通过fbs install命令构建安装程序,详情请看[这里](https://github.com/mherrmann/fbs-tutorial)
### 打包安装程序

> 原本的打包基于fbs库,但是高版本的fbs开始收费了,所以换成了`cx_Freeze`进行打包(感觉更好用了,白嫖真爽!)
配置好以上环境后,可以通过运行以下命令打包为安装目录的文件夹:
```shell
python setup.py build
```
window下打包出来安装目录之后,可以使用nsis打包为安装程序,提供了一个安装程序脚本到`.\build\installer`中,具体用法可以参考[nsis教程](https://nsis.sourceforge.io/Main_Page)

TODO:
- 其他平台使用`cx_Freeze`打包还没有测试
- `cx_Freeze`本身好像支持打包为安装程序,但是不能定义安装页面,后面再看看能不能使用

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ SetCompressor /SOLID LZMA
InstallDir "$PROGRAMFILES64\JamTools"
;InstallDirRegKey HKCU "Software\JamTools" "$PROGRAMFILES64\JamTools"
!define PRODUCT_NAME "JamTools"
!define PRODUCT_VERSION "0.12.201211Alpha"

!define PRODUCT_VERSION "0.14.0B"
Unicode True

;--------------------------------
;Perform Machine-level install, if possible
Expand Down Expand Up @@ -69,7 +69,7 @@ FunctionEnd
;General

Name "JamTools"
OutFile "..\JamTools${PRODUCT_VERSION}Setup.exe"
OutFile "..\JamTools${PRODUCT_VERSION}Setup_for_windows.exe"

;--------------------------------
;Interface Settings
Expand All @@ -79,11 +79,19 @@ FunctionEnd
;--------------------------------
;Pages
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\Icon.ico"
!define MUI_WELCOMEPAGE_TEXT "本向导将把JamTools安装到你的电脑上!$\r$\n本软件是作者在日常生活中自己常用到的功能集合,算是一个小工具集吧。$\n主要功能:(滚动)截屏、文字识别、翻译、图像主体识别、录屏(支持自定义参数)、格式转换(支持图片音视频的简单裁剪拼接、压缩转码、提取混合操作)、键鼠动作录制/(倍速)播放、划屏提字(翻译)等功能$\r$\n本工具完全免费,严禁用于二次打包、贩卖等商业用途$\r$\n$\r$\n$\r$\nClick Next to continue."
!define MUI_WELCOMEPAGE_TEXT "本向导将把JamTools安装到你的电脑上!$\r$\n$\r$\n$\r$\nClick Next to continue."
!define MUI_DIRECTORYPAGE_TEXT_TOP "选择安装的位置,不建议安装到系统盘(因为太大了...) "
!define MUI_
!insertmacro MUI_PAGE_WELCOME

; 许可页面
!define MUI_PAGE_CUSTOMFUNCTION_SHOW LicenseShow
!insertmacro MUI_PAGE_LICENSE "..\JamTools\LICENSE"
Function LicenseShow

FunctionEnd



; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Expand Down Expand Up @@ -196,5 +204,5 @@ FunctionEnd

Function LaunchLink
!addplugindir "."
ShellExecAsUser::ShellExecAsUser "open" "$SMPROGRAMS\JamTools.lnk"
ExecShell "" "$InstDir\JamTools.exe"
FunctionEnd
Binary file added build/installer/ShellExecAsUser.dll
Binary file not shown.
Binary file added build/installer/killer.dll
Binary file not shown.
1 change: 1 addition & 0 deletions build/installer/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move killer.dll && ShellExecAsUser.dll to your `:NSIS\Plugins\x86-unicode`
Binary file added icon.ico
Binary file not shown.
File renamed without changes
8 changes: 5 additions & 3 deletions jamtoolsbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
freezer = subprocess.Popen('fbs freeze {}'.format("--debug" if Debug else ""), shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
freezer.wait()
print("freeze end")
if PLATFORM_SYS != "win32":
a = input("是否打包为安装文件,Y/N:(回车默认Y)")
if "y" in a.lower() or len(a) == 0:
Expand All @@ -175,8 +176,9 @@
if os.path.exists("target/JamTools/cv2"):
print("replace cv2 module")
shutil.rmtree("target/JamTools/cv2")
os.mkdir("target/JamTools/cv2")
shutil.copy2("opencv_world341.dll", "target/JamTools/cv2/opencv_world341.dll")
shutil.copy2("cv2.cp37-win_amd64.pyd", "target/JamTools/cv2/cv2.cp37-win_amd64.pyd")
os.mkdir("target/JamTools/cv2")
shutil.copy2("opencv_world341.dll", "target/JamTools/cv2/opencv_world341.dll")
shutil.copy2("cv2.cp37-win_amd64.pyd", "target/JamTools/cv2/cv2.cp37-win_amd64.pyd")

print('finished all')
time.sleep(2)
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# !usr/bin/python3
# -*- coding: utf-8 -*-

####### 本文件由jamtoolsbuild.py 打包脚本自动生成 ######
####### 本文件由setup.py 打包脚本自动生成 ######

import pynput.keyboard
import pynput.mouse
Expand Down Expand Up @@ -32,7 +32,6 @@
from qt_material import apply_stylesheet,list_themes
import qt_material
from jamscreenshot import Slabel
import fbs_runtime.application_context.PyQt5
import pynput
from jamcontroller import ActionController, ActionCondition
from WEBFilesTransmitter import WebFilesTransmitter, WebFilesTransmitterBox, apppath
Expand Down Expand Up @@ -80,5 +79,5 @@
main()


####### 本文件由jamtoolsbuild.py 打包脚本自动生成 ######
####### 本文件由setup.py 打包脚本自动生成 ######

3 changes: 1 addition & 2 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Wheel
Pillow
pynput
fbs==0.9.0
qrcode
requests==2.27
urllib3==1.25.8
Expand All @@ -22,4 +21,4 @@ setuptools==50.3.0
chardet
comtypes
opencv-contrib-python

cx_Freeze
Loading

0 comments on commit c1f7a1f

Please sign in to comment.