[ todo ] PyQt で画像のビューアを作る version 39
:追加された部分
:削除された部分
(差分が大きい場合、文字単位では表示しません)
[ todo ] PyQt で画像のビューアを作る
@[TOC](項目)
----------------
-------------------------------------
# ペンの色を指定
```
23. painter.setPen(Qt.red)
24. #painter.setPen(QColor(255, 0, 0))
26. # 使用するフォントを指定
27. painter.setFont(QFont('Times', 30))
28. # テキスト描画
29. painter.drawText(image.rect(), Qt.AlignCenter, 'Symfoware')
30. # 画像の編集終了
31. painter.end()
```
----
- コンテキストメニューを作るか
結構長くなるから別ファイルにしておくか??
このソフトの機能を呼び出すときの主要な手段になるよな
- コメント表示したい
- マウスジェスチャ 軌跡の表示
自作ものはジェスチャとコマンドが画像中心に表示される仕様だった
ウインドウを出してたんだな
別に無くても良いんだけど・・・・
- zip内の画像を順に表示できるようにする
一覧、スプレッドシートも必要
リストビューに画像表示させれば良いのかな
自作もののソースを見るか?
- 編集機能
8bfをpythonから使えないかな???
--------------------------------------
----
# コンテキストメニュー
考えたら右クリックにはジェスチャを設定していたから普通にコンテキストメニューを使うと反応してしまう
```
def mouseReleaseEvent(self,e)
if self.ges['cmd'] == '' : # ジェスチャが無い場合はコンテキストメニューを出す
c_menu.cmenu(e)
else :
元のコード
========================================
<< 本体ファイル >>
from PyQt5.QtCore import Qt
from custommenu.py import c_menu
__init__
c_menu(self)
self.label.setContextMenuPolicy(Qt.CustomContextMenu)
self.label.customContextMenuRequested.connect(c_menu.cmenu)
label か mainwindow か???
<< 別ファイルで custommenu.py >>
from PyQt5.QtWidgets import QAction ,QMenu
class c_menu():
def __init__(self,p) :
self.parent = p
def c_menu(self,e): # e が来るのかな??
menu=QMenu(self.parent)
action = QAction('Open Folder', self.parent)
action.triggered.connect(self.parent.**** )
menu.addAction(action)
action = QAction('AddToList', self.parent)
action.triggered.connect(self.parent.**** )
menu.addAction(action)
# menu.exec_(QCursor.pos ())
menu.exec_( e )
```
----
# zip内の画像を順に表示できるようにする
- 結構面倒だよ
とりあえずキーイベントで動作させよう
```
# self.pics=[] これやめよう
def __init__
self.current={'pics':[] , 'index':0, 'picslen':0 ,'zipflag':0 }
self.zip={ 'pics':[] , 'index':0, 'picslen':0}
※このあとで self.pics は全て書き換えること(ここを含めて全8箇所)
def wheel の最後で
showzip(1) # zip 初期化
self.current['zipflag'] = 0 or 1
def keyPressEvent (self, e):
if self.current['zipflag'] :
if e.key()==Qt.Key_Down :
self.calcnext( 'inc' )
if e.key()==Qt.Key_Up :
self.calcnext( 'dec' )
showzip(0) # 既存
# zipでなければ無視
def showzip( self ,flag ): # ここは書き換え
zi = ZipFile( self.current['pics'][self.current['index'] ] , 'r' )
if flag :
self.zip['pics'].clear()
self.zip['pics'] = zi.namelist()
self.zip['picslen'] = len( self.zip['pics'] )
self.zip['index'] = 0
with zi.open( self.zip['pics'][ self.zip['index'] ] ) as z_image :
pix = QPixmap() # ここスワップした方が良いのかな
pix.loadFromData(z_image.read())
self.label.setPixmap(pix)
self.resize(pix.width(),pix.height())
self.show()
zi.close()
<< サイクル計算するルーチン >>
def calcnext( sign ) :# 増か減か
if self.current['zipflag'}:
index = self.zip['index']
len = self.zip['picslen']
else:
index = self.current['index']
len = self.current['picslen']
if sign == 'inc':
index += 1
if index > (len-1) :
index=0
elif sign == 'dec' :
index -= 1
if index < 0:
index = len-1
if self.current['zipflag'}:
self.zip['index'] = index
else:
self.current['index'] = index
```
----
# 勉強サイト
- JPEGファイルの構造
https://hp.vector.co.jp/authors/VA032610/JPEGFormat/StructureOfJPEG.htm
- PNG ファイルフォーマット
https://www.setsuki.com/hsp/ext/png.htm
- Qtで始める画像処理
https://qiita.com/kanryu/items/89812b362dfd581a4c10
ここ面白そう、読もう
----
[目次に戻る](https://mimemo.io/m/QORbW4qkvOoda0N)
[もくじに戻る](https://mimemo.io/m/QORbW4qkvOoda0N)
項目ペンの色を指定コンテキストメニューzip内の画像を順に表示できるようにする勉強サイト
ペンの色を指定
23. painter.setPen(Qt.red)
24. #painter.setPen(QColor(255, 0, 0))
26. # 使用するフォントを指定
27. painter.setFont(QFont('Times', 30))
28. # テキスト描画
29. painter.drawText(image.rect(), Qt.AlignCenter, 'Symfoware')
30. # 画像の編集終了
31. painter.end()
-
コンテキストメニューを作るか
結構長くなるから別ファイルにしておくか??
このソフトの機能を呼び出すときの主要な手段になるよな -
コメント表示したい
-
マウスジェスチャ 軌跡の表示
自作ものはジェスチャとコマンドが画像中心に表示される仕様だった
ウインドウを出してたんだな
別に無くても良いんだけど・・・・ -
zip内の画像を順に表示できるようにする
一覧、スプレッドシートも必要
リストビューに画像表示させれば良いのかな
自作もののソースを見るか? -
編集機能
8bfをpythonから使えないかな???
コンテキストメニュー
考えたら右クリックにはジェスチャを設定していたから普通にコンテキストメニューを使うと反応してしまう
def mouseReleaseEvent(self,e)
if self.ges['cmd'] == '' : # ジェスチャが無い場合はコンテキストメニューを出す
c_menu.cmenu(e)
else :
元のコード
========================================
<< 本体ファイル >>
from PyQt5.QtCore import Qt
from custommenu.py import c_menu
__init__
c_menu(self)
self.label.setContextMenuPolicy(Qt.CustomContextMenu)
self.label.customContextMenuRequested.connect(c_menu.cmenu)
label か mainwindow か???
<< 別ファイルで custommenu.py >>
from PyQt5.QtWidgets import QAction ,QMenu
class c_menu():
def __init__(self,p) :
self.parent = p
def c_menu(self,e): # e が来るのかな??
menu=QMenu(self.parent)
action = QAction('Open Folder', self.parent)
action.triggered.connect(self.parent.**** )
menu.addAction(action)
action = QAction('AddToList', self.parent)
action.triggered.connect(self.parent.**** )
menu.addAction(action)
# menu.exec_(QCursor.pos ())
menu.exec_( e )
zip内の画像を順に表示できるようにする
- 結構面倒だよ
とりあえずキーイベントで動作させよう
# self.pics=[] これやめよう
def __init__
self.current={'pics':[] , 'index':0, 'picslen':0 ,'zipflag':0 }
self.zip={ 'pics':[] , 'index':0, 'picslen':0}
※このあとで self.pics は全て書き換えること(ここを含めて全8箇所)
def wheel の最後で
showzip(1) # zip 初期化
self.current['zipflag'] = 0 or 1
def keyPressEvent (self, e):
if self.current['zipflag'] :
if e.key()==Qt.Key_Down :
self.calcnext( 'inc' )
if e.key()==Qt.Key_Up :
self.calcnext( 'dec' )
showzip(0) # 既存
# zipでなければ無視
def showzip( self ,flag ): # ここは書き換え
zi = ZipFile( self.current['pics'][self.current['index'] ] , 'r' )
if flag :
self.zip['pics'].clear()
self.zip['pics'] = zi.namelist()
self.zip['picslen'] = len( self.zip['pics'] )
self.zip['index'] = 0
with zi.open( self.zip['pics'][ self.zip['index'] ] ) as z_image :
pix = QPixmap() # ここスワップした方が良いのかな
pix.loadFromData(z_image.read())
self.label.setPixmap(pix)
self.resize(pix.width(),pix.height())
self.show()
zi.close()
<< サイクル計算するルーチン >>
def calcnext( sign ) :# 増か減か
if self.current['zipflag'}:
index = self.zip['index']
len = self.zip['picslen']
else:
index = self.current['index']
len = self.current['picslen']
if sign == 'inc':
index += 1
if index > (len-1) :
index=0
elif sign == 'dec' :
index -= 1
if index < 0:
index = len-1
if self.current['zipflag'}:
self.zip['index'] = index
else:
self.current['index'] = index
勉強サイト
- JPEGファイルの構造
https://hp.vector.co.jp/authors/VA032610/JPEGFormat/StructureOfJPEG.htm - PNG ファイルフォーマット
https://www.setsuki.com/hsp/ext/png.htm - Qtで始める画像処理
https://qiita.com/kanryu/items/89812b362dfd581a4c10
ここ面白そう、読もう