Created
December 21, 2015 05:30
-
-
Save peace098beat/a2d7b76b2e2bec2d594c to your computer and use it in GitHub Desktop.
[PySdie] 何もしないタスクトレイアプリケーション
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! coding:utf-8 | |
| """ | |
| tasktray_app | |
| 何もしないタスクトレイアプリケーション | |
| http://moco.sakura.ne.jp/python/pyside-でタスクトレイアプリケーション作成/ | |
| Created by 0160929 on 2015/12/21 14:16 | |
| """ | |
| __version__ = '0.0' | |
| import os | |
| import sys | |
| from PySide.QtGui import * | |
| from PySide.QtCore import * | |
| class MyWindow(QDialog): | |
| def __init__(self, parent=None): | |
| QDialog.__init__(self, parent=parent) | |
| self.setWindowTitle("tasktray_app") | |
| # self.setWindowFlags(Qt.WindowStaysOnTopHint) | |
| self.resize(640, 480) | |
| # Closeアクションの追加 | |
| self.quit_action = QAction("&Quit", self) | |
| self.connect(self.quit_action, SIGNAL('triggered()'), qApp, SLOT('quit()')) | |
| # self.quit_action.triggered.connect(qApp.quit) | |
| # (仮)その他のアクション | |
| self.action_open = QAction("&Open", self) | |
| self.connect(self.action_open, SIGNAL('triggered()'), qApp, SLOT('show()')) | |
| # self.quit_action.triggered.connect(qApp.quit) | |
| self.action_save = QAction("&Save", self) | |
| # タスクアイコンのメニューを作成 | |
| self.trayIconMenu = QMenu(self) | |
| self.trayIconMenu.addAction(self.quit_action) | |
| self.trayIconMenu.addAction(self.action_open) | |
| self.trayIconMenu.addAction(self.action_save) | |
| # アイコンを追加 | |
| self.trayIcon = QSystemTrayIcon(self) | |
| self.trayIcon.setContextMenu(self.trayIconMenu) | |
| self.trayIcon.setIcon(QIcon("icon_fifics.png")) | |
| self.trayIcon.show() | |
| pass | |
| def main(): | |
| app = QApplication(sys.argv) | |
| app.setStyle('plastique') | |
| # OSがタスクトレイに対応しているか確認 | |
| if not QSystemTrayIcon.isSystemTrayAvailable(): | |
| raise OSError("We could't detect any system tray on this system.") | |
| # ウィンドウが閉じられても、アプリは終了されない:False | |
| QApplication.setQuitOnLastWindowClosed(False) | |
| win = MyWindow() | |
| win.show() | |
| sys.exit(app.exec_()) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment