网站添加地图导航,物联网方案,外贸网店建站模板,地区门户网站 wap app写在前面 
 在很早之前#xff0c;我在我所在的项目上自己写过一部分工具#xff0c;web版本#xff0c;放在本地环境供自己使用。由于之前项目的架构相对陈旧#xff0c;多是一些文本处理的工具#xff08;sql处理#xff09;#xff0c;以及数据库查询相关工具类。由…写在前面 
 在很早之前我在我所在的项目上自己写过一部分工具web版本放在本地环境供自己使用。由于之前项目的架构相对陈旧多是一些文本处理的工具sql处理以及数据库查询相关工具类。由于没有进行版本管理后来换电脑的过程中那部分代码被直接遗失掉了。 
 再后来重写过一次但一直使用控制台交互自己虽然能用但感觉体验一般。因此最近java转python实现一次并使用py2app包进行打包制作成自己的MacApp想用的时候直接打开使用即可。 
 但是值得注意的是py2app打包的软件和通过xcode进行签名通过AppStore分发的软件不同一般来说是过不了mac的安全检验的简言之自己用可以分发存在困难给予软件信任也可。 
 如果本身存在分发需求又是一些简单的小工具我倒是直接推荐使用Mac的自动工具通过shell脚本实现功能Mac会自动打成一个小程序可分发。 我这里需要制作图形化界面所以还是用回py2app。不是swiftui没法比是python更有性价比 
核心实现代码 
 我这里主要实现了四个功能sql转java拼接字符串sqlJava的sql字符串转sql快速打开脚本文档快速打开在线笔记。 from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPlainTextEdit, QPushButton, QVBoxLayout, QHBoxLayout
from PyQt5.QtGui import QTextCursor, QDesktopServices
from PyQt5.QtCore import Qt, QUrlclass Sql2StringConverter(QMainWindow):def __init__(self):super(Sql2StringConverter, self).__init__()self.setWindowTitle(SQL字符串转换工具)self.setGeometry(200, 200, 1200, 700)self.sql_text  QPlainTextEdit()self.sql_text.setPlaceholderText(待转换区域)self.sql_text.setStyleSheet(background-color: white; color: black)self.result_text  QPlainTextEdit()self.result_text.setReadOnly(True)self.result_text.setPlaceholderText(已转换区域)self.result_text.setStyleSheet(background-color: white; color: black)self.input_output_layout  QHBoxLayout()self.input_output_layout.addWidget(self.sql_text)self.input_output_layout.addWidget(self.result_text)self.convert_button  QPushButton( SQL to String)self.convert_button.clicked.connect(self.convert_sql_to_string)self.reverse_button  QPushButton( String to SQL)self.reverse_button.clicked.connect(self.convert_string_to_sql)self.load_file_button  QPushButton(祖传秘籍)self.load_file_button.clicked.connect(self.load_file)self.online_button  QPushButton(在线笔记)self.online_button.clicked.connect(self.open_online_note)button_layout  QHBoxLayout()button_layout.addWidget(self.convert_button)button_layout.addWidget(self.reverse_button)button_layout.addWidget(self.load_file_button)button_layout.addWidget(self.online_button)self.central_widget  QWidget()self.setCentralWidget(self.central_widget)layout  QVBoxLayout()# layout.addWidget(self.convert_button)# layout.addWidget(self.reverse_button)# layout.addWidget(self.sql_text)# layout.addWidget(self.result_text)layout.addLayout(button_layout)layout.addLayout(self.input_output_layout)self.central_widget.setLayout(layout)def convert_sql_to_string(self):sql  self.sql_text.toPlainText()lines  sql.split(\n)converted_code  StringBuffer sb  new StringBuffer();\n\nfor line in lines:if line.strip() ! :converted_code  sb.append( {} );\n.format(line.strip())self.result_text.clear()self.result_text.insertPlainText(converted_code)# 将光标移至文本末尾cursor  self.result_text.textCursor()cursor.movePosition(QTextCursor.End)self.result_text.setTextCursor(cursor)def convert_string_to_sql(self):string  self.sql_text.toPlainText()# 去掉所有的 sql.append( 和  ); sql  string.replace(sb.append(, ).replace(StringBuffer sb  new StringBuffer();, ).replace();, ).strip()self.result_text.clear()self.result_text.insertPlainText(sql)cursor  self.result_text.textCursor()cursor.movePosition(QTextCursor.End)self.result_text.setTextCursor(cursor)def load_file(self):folder_path  docurl  QUrl.fromLocalFile(folder_path)QDesktopServices.openUrl(url)def open_online_note(self):url  QUrl(http://101.42.xx.xx:8088/#root-lYZQ)QDesktopServices.openUrl(url)if __name__  __main__:app  QApplication([])# 设置样式表app.setStyleSheet(QMainWindow {background-color: black;}QTextEdit {border: 1px solid gray;padding: 5px;}QPushButton {background-color: #5fa8d3;border-radius: 5px;padding: 5px;color: white;})window  Sql2StringConverter()window.show()app.exec_() 
在线笔记地址被我隐掉了是我在我自己服务器搭建的trilium有兴趣的放自己的印象笔记墨迹文档之类皆可。 
py2app打包设置 This is a setup.py script generated by py2appletUsage:python setup.py py2app
from setuptools import setupAPP  [transStr.py]
DATA_FILES  []
OPTIONS  {argv_emulation: True,iconfile: ./PythonApplet.icns,plist: {CFBundleName: transStr,CFBundleDisplayName: transStr,CFBundleVersion: 1.0.0,CFBundleIdentifier: transStr}
}setup(app[transStr.py],nametransStr,data_files[],options{py2app: OPTIONS},setup_requires[py2app],
) 
iconfile软件图标。是我自己搁网上下载的。 
配置文件初始化命令 
py2applet   --make-setup  xxx.py 打包命令 
python setup.py py2apppython setup.py py2app -A不包含lib库我是全部打包的因此打出来的软件较大。 在dist中可以看见自己打包好的软件 双击运行  
功能测试 
随便输入一条sql 随便输入一串sql字符串 点祖传秘籍快速定位到提前放置的字段文档或者操作文档 点在线笔记快速定位到我的在线笔记 写在后面 
 这个app原本我的打算只有字符串处理这个功能但就这样写一篇文章有点单薄因此又加了两个功能。在学习打包MacApp的过程中最令我意外的还是mac的自动操作功能实话实说确实很方便但坏处就是没有图形化界面不过对于稍懂计算机的人来说够使了。 文章转载自: http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.sjmxh.cn.gov.cn.sjmxh.cn http://www.morning.zsyqg.cn.gov.cn.zsyqg.cn http://www.morning.fpzz1.cn.gov.cn.fpzz1.cn http://www.morning.fzqfb.cn.gov.cn.fzqfb.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.czgfn.cn.gov.cn.czgfn.cn http://www.morning.tqldj.cn.gov.cn.tqldj.cn http://www.morning.fmznd.cn.gov.cn.fmznd.cn http://www.morning.pwfwk.cn.gov.cn.pwfwk.cn http://www.morning.rlcqx.cn.gov.cn.rlcqx.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.dmwck.cn.gov.cn.dmwck.cn http://www.morning.hmhdn.cn.gov.cn.hmhdn.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn http://www.morning.jmllh.cn.gov.cn.jmllh.cn http://www.morning.khxwp.cn.gov.cn.khxwp.cn http://www.morning.xoaz.cn.gov.cn.xoaz.cn http://www.morning.sqskm.cn.gov.cn.sqskm.cn http://www.morning.pqktp.cn.gov.cn.pqktp.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn http://www.morning.kgltb.cn.gov.cn.kgltb.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.yydeq.cn.gov.cn.yydeq.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn http://www.morning.ssrjt.cn.gov.cn.ssrjt.cn http://www.morning.cknws.cn.gov.cn.cknws.cn http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn http://www.morning.zknxh.cn.gov.cn.zknxh.cn http://www.morning.tgcw.cn.gov.cn.tgcw.cn http://www.morning.dnconr.cn.gov.cn.dnconr.cn http://www.morning.bdsyu.cn.gov.cn.bdsyu.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn http://www.morning.drbwh.cn.gov.cn.drbwh.cn http://www.morning.jfch.cn.gov.cn.jfch.cn http://www.morning.ldfcb.cn.gov.cn.ldfcb.cn http://www.morning.lsjgh.cn.gov.cn.lsjgh.cn http://www.morning.pbygt.cn.gov.cn.pbygt.cn http://www.morning.ttvtv.cn.gov.cn.ttvtv.cn http://www.morning.lfpzs.cn.gov.cn.lfpzs.cn http://www.morning.qklff.cn.gov.cn.qklff.cn http://www.morning.gxcit.com.gov.cn.gxcit.com http://www.morning.wcqxj.cn.gov.cn.wcqxj.cn http://www.morning.jfjfk.cn.gov.cn.jfjfk.cn http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn http://www.morning.dndjx.cn.gov.cn.dndjx.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn http://www.morning.lgmty.cn.gov.cn.lgmty.cn http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.rsjf.cn.gov.cn.rsjf.cn http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn http://www.morning.tsmcc.cn.gov.cn.tsmcc.cn http://www.morning.fsnhz.cn.gov.cn.fsnhz.cn http://www.morning.rgnp.cn.gov.cn.rgnp.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.xrrjb.cn.gov.cn.xrrjb.cn http://www.morning.nmfml.cn.gov.cn.nmfml.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn http://www.morning.nqbkb.cn.gov.cn.nqbkb.cn http://www.morning.zlhzd.cn.gov.cn.zlhzd.cn http://www.morning.ffptd.cn.gov.cn.ffptd.cn http://www.morning.bhjyh.cn.gov.cn.bhjyh.cn http://www.morning.xrct.cn.gov.cn.xrct.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn