Menu

[r65]: / dialogs.py  Maximize  Restore  History

Download this file

183 lines (168 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python
"""
aboutdialog
help
"""
# module unittest:no
# pylint: disable=C0413
import sys
import pkgutil # to read resources from within pyzip file
import gi
gi.require_version('Gtk', '3.0') # tell we want GTK3
from gi.repository import Gtk
import gtkutils
# pylint: enable=C0413
def messagedialog(widget, title, message, imagefn):
"""!generic message dialog
The Gtk.MessageDialog does not support images anymore
and is otherwise crippeld so i create my own
@param widget: Gtk.widget (parent widget)
@param title: string
@param message: string
@param imagefn: string filename for image or logo
"""
pixbuf = gtkutils.pkgimage("videothumb:"+imagefn)
dialog = Gtk.Dialog(
title=title,
parent=widget.get_toplevel(),
flags=Gtk.MessageType.INFO)
dialog.add_buttons(
Gtk.STOCK_OK, Gtk.ResponseType.OK)
label = Gtk.Label()
label.set_markup('\n'.join(message))
box = dialog.get_content_area()
box.pack_start(Gtk.Image.new_from_pixbuf(pixbuf), False, False, 0)
box.pack_start(label, True, True, 0)
box.show_all()
dialog.run()
dialog.destroy()
def about(widget):
"""!Display about screen.
@param widget: Gtk.Widget.
Note: to read from a resouce we have to use pkgutil
Note: changed to GtkAboutDialog 20210418
because now we can use the URL to the website.
"""
pixbuf = gtkutils.pkgimage("videothumb:" + "videothumb.png")
finbytes = pkgutil.get_data("videothumb", "version.txt")
version = finbytes.decode('utf-8').strip()
comment = (
"Program to manage (home)videos.\n"
"Created with Archlinux, Gtk3, Python3, ffmpeg\n"
"License: MIT\n")
dialog = Gtk.AboutDialog(
parent=widget.get_toplevel(),
logo=pixbuf,
version=version,
comments=comment,
website="https://videothumb.sourceforge.io",
copyright="© 2014-2021 Henk Speksnijder")
dialog.run()
dialog.destroy()
def vthelp(widget):
"""!Display first help screen.
@param widget: Gtk.Widget.
"""
message = [
'Suggested (minimal) helper programs:',
'',
'ffmpeg is absolutely required to generate thumbnails',
' http://ffmpeg.org/',
'Xine as video player',
' http://www.xine-project.org/home',
'Avidemux for simple video edting.',
' http://fixounet.free.fr/avidemux',
'Tragtor a gui fontend to ffmpeg to convert videos to other formats.',
' http://mein-neues-blog.de/tragtor-gui-for-FFmpeg',
'',
'More information:',
' http://videothumb.sourceforge.io'
]
imagefn = "videothumb.png"
messagedialog(widget, "Help2", message, imagefn)
def background(widget):
"""!Display background information screen.
@param widget: Gtk.Widget
"""
message = [
'VideoThumb\n',
'This program aims to help working with home videos.\n',
' It presents a video as a row of thumbnails.\n',
' a longer video will get more thumbnails.\n',
'\n',
'Rationale:\n',
'Have a video recorder to make home videos.',
'To know what a video is about you need to watch it.',
'That is time consuming. After you have seen it you may',
'want to edit the video like delete poor sections. ',
'We often start the recorder, than notice something wrong',
'and stop it after only a few seconds.\n',
'These very short videos can usually be deleted.\n',
'\n',
'Videothumb is the tool to improve our workflow.\n',
'It can not (and never will) edit your videofiles.\n',
'But it makes it very easy to call other programs:\n',
'xine, VLC, dragon, banshee, kaffeine to watch the video\n',
'Avidemux to simply cut away parts we do not like.\n',
'ffmpeg to split a video in images.\n',
'Non-linear video editor like Kdenlive for the heavy lifting.\n',
'\n',
'Filemanagers\n',
'The usual filemanagers like Nautilus, Dolphin, Thunar or Rox are',
'not suitable because they show ONE thumbnail for every file.',
'That is ok for ordinairy documents, images and photos,',
'but very difficult for videos.',
'And with these filemanagers when you double-click you ONE program.',
'But when working on home videos there is a need for different'
'video editors and different programs to watch your work.\n',
'Henk Speksnijder 20170326'
]
msg = ''.join(message)
dialog = Gtk.MessageDialog(
title="Help",
text=msg,
parent=widget.get_toplevel(),
flags=Gtk.MessageType.INFO)
dialog.add_buttons(
Gtk.STOCK_OK, Gtk.ResponseType.OK)
dialog.run()
dialog.destroy()
# return
def warning(widget, amessage): # pylint: disable=C0111
"""!Warning dialog
@param widget: Gtk.Widget.
@param amessage: string.
@return res: boolean.
Note:
if dialog.run() == Gtk.ResponseType.OK: res = True else: res = False
Can be reduced to
res = dialog.run() == Gtk.ResponseType.OK
"""
dialog = Gtk.MessageDialog(
widget.get_toplevel(),
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.WARNING,
Gtk.ButtonsType.OK_CANCEL,
text=amessage,
title="Warning")
res = dialog.run() == Gtk.ResponseType.OK
dialog.destroy()
return res
def simpledialog():
"""Simple run mostly for testing."""
button1 = gtkutils.gtkibtn("About", about)
button2 = gtkutils.gtkibtn("Help", vthelp)
button3 = gtkutils.gtkibtn("Background", background)
hbox = Gtk.Box()
hbox.pack_start(button1, False, True, 0)
hbox.pack_start(button2, True, True, 0)
hbox.pack_start(button3, True, True, 0)
gtkutils.gtkwin(hbox, 300, 50, main=True)
Gtk.main()
# return
# =========== M A I N =========================================================
if __name__ == "__main__":
# check we have Python3
if sys.version_info[0] < 3:
raise gtkutils.Error("Error: Python version >=3 is required.")
simpledialog()