Bläddra i källkod

toolbars and menus

runningwater 6 år sedan
incheckning
69c8d2d2af

+ 276 - 0
.gitignore

@@ -0,0 +1,276 @@
+# Created by .ignore support plugin (hsz.mobi)
+### macOS template
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### Qt template
+# C++ objects and libs
+*.slo
+*.lo
+*.o
+*.a
+*.la
+*.lai
+*.so
+*.dll
+*.dylib
+
+# Qt-es
+object_script.*.Release
+object_script.*.Debug
+*_plugin_import.cpp
+/.qmake.cache
+/.qmake.stash
+*.pro.user
+*.pro.user.*
+*.qbs.user
+*.qbs.user.*
+*.moc
+moc_*.cpp
+moc_*.h
+qrc_*.cpp
+ui_*.h
+*.qmlc
+*.jsc
+Makefile*
+*build-*
+
+# Qt unit tests
+target_wrapper.*
+
+# QtCreator
+*.autosave
+
+# QtCreator Qml
+*.qmlproject.user
+*.qmlproject.user.*
+
+# QtCreator CMake
+CMakeLists.txt.user*
+
+# QtCreator 4.8< compilation database
+compile_commands.json
+
+# QtCreator local machine specific files for imported projects
+*creator.user*
+
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn.  Uncomment if using
+# auto-import.
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Python template
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# celery beat schedule file
+celerybeat-schedule
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/pyqt.iml" filepath="$PROJECT_DIR$/.idea/pyqt.iml" />
+    </modules>
+  </component>
+</project>

+ 12 - 0
.idea/pyqt.iml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TestRunnerService">
+    <option name="projectConfiguration" value="pytest" />
+    <option name="PROJECT_TEST_RUNNER" value="pytest" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 185 - 0
.idea/workspace.xml

@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ChangeListManager">
+    <list default="true" id="c4ea2cee-1e7b-4a07-b2da-95f789e91944" name="Default Changelist" comment="">
+      <change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/pyqt.iml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/MyApp.py" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/MyApp_window.py" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/arrow-000.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/arrow-180.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/arrow-circle-315.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/bomb.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/bug.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/cactus.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/cake.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/clock-select.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/cross-circle.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/cross.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/cup.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/disk--arrow.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/disk--pencil.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/flag.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/fruit.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/hamburger.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/home.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/ice-cream-sprinkles.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/lifebuoy.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/lock-nossl.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/lock-ssl.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/ma-icon-128.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/ma-icon-256.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/ma-icon-64.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/mushroom.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/plus.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/printer.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/question.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/rocket.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/smiley-lol.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/smiley.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/icons/ui-tab--plus.png" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/toolbars_and_menus.py" afterDir="false" />
+    </list>
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
+    <option name="SHOW_DIALOG" value="false" />
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+    <option name="LAST_RESOLUTION" value="IGNORE" />
+  </component>
+  <component name="FileTemplateManagerImpl">
+    <option name="RECENT_TEMPLATES">
+      <list>
+        <option value="Python Script" />
+      </list>
+    </option>
+  </component>
+  <component name="Git.Settings">
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
+  </component>
+  <component name="ProjectId" id="1S3C7QSmQQMddbKsyuhpr0hmxLm" />
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
+  <component name="PropertiesComponent">
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
+    <property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
+  </component>
+  <component name="RecentsManager">
+    <key name="CopyFile.RECENT_KEYS">
+      <recent name="$PROJECT_DIR$" />
+    </key>
+  </component>
+  <component name="RunDashboard">
+    <option name="ruleStates">
+      <list>
+        <RuleState>
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
+        </RuleState>
+        <RuleState>
+          <option name="name" value="StatusDashboardGroupingRule" />
+        </RuleState>
+      </list>
+    </option>
+  </component>
+  <component name="RunManager" selected="Python.toolbars_and_menus">
+    <configuration name="MyApp" type="PythonConfigurationType" factoryName="Python" temporary="true">
+      <module name="pyqt" />
+      <option name="INTERPRETER_OPTIONS" value="" />
+      <option name="PARENT_ENVS" value="true" />
+      <envs>
+        <env name="PYTHONUNBUFFERED" value="1" />
+      </envs>
+      <option name="SDK_HOME" value="" />
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+      <option name="IS_MODULE_SDK" value="true" />
+      <option name="ADD_CONTENT_ROOTS" value="true" />
+      <option name="ADD_SOURCE_ROOTS" value="true" />
+      <option name="SCRIPT_NAME" value="$PROJECT_DIR$/MyApp.py" />
+      <option name="PARAMETERS" value="" />
+      <option name="SHOW_COMMAND_LINE" value="false" />
+      <option name="EMULATE_TERMINAL" value="false" />
+      <option name="MODULE_MODE" value="false" />
+      <option name="REDIRECT_INPUT" value="false" />
+      <option name="INPUT_FILE" value="" />
+      <method v="2" />
+    </configuration>
+    <configuration name="MyApp_window" type="PythonConfigurationType" factoryName="Python" temporary="true">
+      <module name="pyqt" />
+      <option name="INTERPRETER_OPTIONS" value="" />
+      <option name="PARENT_ENVS" value="true" />
+      <envs>
+        <env name="PYTHONUNBUFFERED" value="1" />
+      </envs>
+      <option name="SDK_HOME" value="" />
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+      <option name="IS_MODULE_SDK" value="true" />
+      <option name="ADD_CONTENT_ROOTS" value="true" />
+      <option name="ADD_SOURCE_ROOTS" value="true" />
+      <option name="SCRIPT_NAME" value="$PROJECT_DIR$/MyApp_window.py" />
+      <option name="PARAMETERS" value="" />
+      <option name="SHOW_COMMAND_LINE" value="false" />
+      <option name="EMULATE_TERMINAL" value="false" />
+      <option name="MODULE_MODE" value="false" />
+      <option name="REDIRECT_INPUT" value="false" />
+      <option name="INPUT_FILE" value="" />
+      <method v="2" />
+    </configuration>
+    <configuration name="toolbars_and_menus" type="PythonConfigurationType" factoryName="Python" temporary="true">
+      <module name="pyqt" />
+      <option name="INTERPRETER_OPTIONS" value="" />
+      <option name="PARENT_ENVS" value="true" />
+      <envs>
+        <env name="PYTHONUNBUFFERED" value="1" />
+      </envs>
+      <option name="SDK_HOME" value="" />
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+      <option name="IS_MODULE_SDK" value="true" />
+      <option name="ADD_CONTENT_ROOTS" value="true" />
+      <option name="ADD_SOURCE_ROOTS" value="true" />
+      <option name="SCRIPT_NAME" value="$PROJECT_DIR$/toolbars_and_menus.py" />
+      <option name="PARAMETERS" value="" />
+      <option name="SHOW_COMMAND_LINE" value="false" />
+      <option name="EMULATE_TERMINAL" value="false" />
+      <option name="MODULE_MODE" value="false" />
+      <option name="REDIRECT_INPUT" value="false" />
+      <option name="INPUT_FILE" value="" />
+      <method v="2" />
+    </configuration>
+    <recent_temporary>
+      <list>
+        <item itemvalue="Python.toolbars_and_menus" />
+        <item itemvalue="Python.MyApp_window" />
+        <item itemvalue="Python.MyApp" />
+      </list>
+    </recent_temporary>
+  </component>
+  <component name="SvnConfiguration">
+    <configuration />
+  </component>
+  <component name="TaskManager">
+    <task active="true" id="Default" summary="Default task">
+      <changelist id="c4ea2cee-1e7b-4a07-b2da-95f789e91944" name="Default Changelist" comment="" />
+      <created>1570782724558</created>
+      <option name="number" value="Default" />
+      <option name="presentableId" value="Default" />
+      <updated>1570782724558</updated>
+    </task>
+    <servers />
+  </component>
+  <component name="Vcs.Log.Tabs.Properties">
+    <option name="TAB_STATES">
+      <map>
+        <entry key="MAIN">
+          <value>
+            <State>
+              <option name="COLUMN_ORDER" />
+            </State>
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
+</project>

+ 26 - 0
MyApp.py

@@ -0,0 +1,26 @@
+# Only needed for access to command line arguments
+import sys
+
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+
+
+# 自定义窗口,继承 QMainWindow
+class MainWindow(QMainWindow):
+    def __init__(self, *args, **kwargs):
+        super(MainWindow, self).__init__(*args, **kwargs)
+        self.setWindowTitle("My Awesome App")  # 标题
+
+        label = QLabel("THIS IS AWESOME!!!")
+        label.setAlignment(Qt.AlignCenter)
+
+        self.setCentralWidget(label)
+
+
+if __name__ == '__main__':
+    app = QApplication(sys.argv)
+
+    window = MainWindow()
+    window.show()  # 默认下 windows 是隐藏的
+    # 开启事件循环
+    app.exec_()

+ 47 - 0
MyApp_window.py

@@ -0,0 +1,47 @@
+# Only needed for access to command line arguments
+import sys
+
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+
+
+# 自定义窗口,继承 QMainWindow
+
+
+class MainWindow(QMainWindow):
+    def __init__(self, *args, **kwargs):
+        super(MainWindow, self).__init__(*args, **kwargs)
+
+        self.windowTitleChanged().connect(self.onWindowTitleChanged)
+
+        self.windowTitleChanged().connect(lambda x: self.my_custom_fn())
+
+        self.windowTitleChanged().connect(lambda x: self.my_custom_fn(x))
+
+        self.windowTitleChanged().connect(lambda x: self.my_custom_fn(x, 25))
+
+        self.setWindowTitle("My Awesome App")  # 标题
+
+        label = QLabel("THIS IS AWESOME!!!")
+        label.setAlignment(Qt.AlignCenter)
+
+        self.setCentralWidget(label)
+
+    def contextMenuEvent(self, event):
+        print("Context menu event!")
+        super(MainWindow, self).contextMenuEvent(event)
+
+    def onWindowTitleChanged(self, s):
+        print(s)
+
+    def my_custom_fn(self, a="HELLO!", b=5):
+        print(a, b)
+
+
+if __name__ == '__main__':
+    app = QApplication(sys.argv)
+
+    window = MainWindow()
+    window.show()  # 默认下 windows 是隐藏的
+    # 开启事件循环
+    app.exec_()

BIN
icons/arrow-000.png


BIN
icons/arrow-180.png


BIN
icons/arrow-circle-315.png


BIN
icons/bomb.png


BIN
icons/bug.png


BIN
icons/cactus.png


BIN
icons/cake.png


BIN
icons/clock-select.png


BIN
icons/cross-circle.png


BIN
icons/cross.png


BIN
icons/cup.png


BIN
icons/disk--arrow.png


BIN
icons/disk--pencil.png


BIN
icons/flag.png


BIN
icons/fruit.png


BIN
icons/hamburger.png


BIN
icons/home.png


BIN
icons/ice-cream-sprinkles.png


BIN
icons/lifebuoy.png


BIN
icons/lock-nossl.png


BIN
icons/lock-ssl.png


BIN
icons/ma-icon-128.png


BIN
icons/ma-icon-256.png


BIN
icons/ma-icon-64.png


BIN
icons/mushroom.png


BIN
icons/plus.png


BIN
icons/printer.png


BIN
icons/question.png


BIN
icons/rocket.png


BIN
icons/smiley-lol.png


BIN
icons/smiley.png


BIN
icons/ui-tab--plus.png


+ 55 - 0
toolbars_and_menus.py

@@ -0,0 +1,55 @@
+# Only needed for access to command line arguments
+import sys
+
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+from PyQt5.QtGui import *
+
+
+# 自定义窗口,继承 QMainWindow
+class MainWindow(QMainWindow):
+    def __init__(self, *args, **kwargs):
+        super(MainWindow, self).__init__(*args, **kwargs)
+        self.setWindowTitle("My Awesome App")  # 标题
+
+        label = QLabel("THIS IS AWESOME!!!")
+        label.setAlignment(Qt.AlignCenter)
+
+        self.setCentralWidget(label)
+
+        toolbar = QToolBar("My main toolbar")
+        toolbar.setIconSize(QSize(16, 16))
+        self.addToolBar(toolbar)
+
+        button_action = QAction(QIcon("icons/bug.png"), "Your button", self)
+        button_action.setStatusTip("This is your button")
+        button_action.triggered.connect(self.onMyToolBarButtonClick)
+        button_action.setCheckable(True)
+        toolbar.addAction(button_action)
+
+        toolbar.addSeparator()
+
+        button_action2 = QAction(QIcon("icons/bug.png"), "Your button2", self)
+        button_action2.setStatusTip("This your button2")
+        button_action2.triggered.connect(self.onMyToolBarButtonClick)
+        button_action2.setCheckable(True)
+        toolbar.addAction(button_action2)
+
+        toolbar.addSeparator()
+        toolbar.addWidget(QLabel("Hello"))
+        toolbar.addWidget(QCheckBox())
+
+        # 状态栏
+        self.setStatusBar(QStatusBar(self))
+
+    def onMyToolBarButtonClick(self, s):
+        print("click", s)
+
+
+if __name__ == '__main__':
+    app = QApplication(sys.argv)
+
+    window = MainWindow()
+    window.show()  # 默认下 windows 是隐藏的
+    # 开启事件循环
+    app.exec_()