This commit is contained in:
Martin Fitzpatrick
2019-05-28 00:11:53 +02:00
parent b99eb33031
commit 1252abeaaf
38 changed files with 109 additions and 118 deletions

View File

@@ -44,12 +44,11 @@ The application window should appear.
## Want to build your own apps? ## Want to build your own apps?
> If you think these apps are neat and want to learn more about > If you think these apps are neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at [my free online tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
You can also find more PyQt articles, tutorials and projects You can also find write-ups about these apps
[on my website](http://martinfitzpatrick.name/tag/pyqt). [here](http://www.learnpyqt.com/apps).
## License ## License

View File

@@ -6,10 +6,9 @@ browsing experience with the usual controls, as well as saving and loading HTML.
![Browser](screenshot-browser.jpg) ![Browser](screenshot-browser.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Other licenses ## Other licenses

View File

@@ -159,7 +159,7 @@ class MainWindow(QMainWindow):
"All files (*.*)") "All files (*.*)")
if filename: if filename:
html = self.browser.page().mainFrame().toHtml() html = self.browser.page().toHtml()
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(html) f.write(html)

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -7,10 +7,9 @@ coincidental.
![Browser tabbed](screenshot-browser-tabbed.jpg) ![Browser tabbed](screenshot-browser-tabbed.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Code notes ## Code notes

View File

@@ -208,7 +208,7 @@ class MainWindow(QMainWindow):
"All files (*.*)") "All files (*.*)")
if filename: if filename:
html = self.tabs.currentWidget().page().mainFrame().toHtml() html = self.tabs.currentWidget().page().toHtml()
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(html.encode('utf8')) f.write(html.encode('utf8'))

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -91,10 +91,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.current_op: if self.current_op:
self.last_operation = self.stack[-1], self.current_op self.last_operation = self.stack[-1], self.current_op
self.stack = [self.current_op(*self.stack)] try:
self.current_op = None self.stack = [self.current_op(*self.stack)]
self.state = READY except Exception:
self.display() self.lcdNumber.display('Err')
self.stack = [0]
else:
self.current_op = None
self.state = READY
self.display()
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -7,10 +7,9 @@ them.
![Camera](screenshot-camera.jpg) ![Camera](screenshot-camera.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Other licenses ## Other licenses

View File

@@ -73,9 +73,6 @@ class MainWindow(QMainWindow):
self.save_seq = 0 self.save_seq = 0
def take_photo(self): def take_photo(self):
self.viewfinder.setContrast(100)
#self.viewfinder.setBrightness(0)
timestamp = time.strftime("%d-%b-%Y-%H_%M_%S") timestamp = time.strftime("%d-%b-%Y-%H_%M_%S")
self.capture.capture(os.path.join(self.save_path, "%s-%04d-%s.jpg" % ( self.capture.capture(os.path.join(self.save_path, "%s-%04d-%s.jpg" % (
self.current_camera_name, self.current_camera_name,

View File

@@ -10,10 +10,9 @@ hand panel and updated to follow the position of the mouse.
![Doughnut](screenshot-currency2.jpg) ![Doughnut](screenshot-currency2.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Code notes ## Code notes

View File

@@ -1,4 +1,5 @@
PyQt5>=5.6 PyQt5>=5.6
sip
requests>=2.0.0 requests>=2.0.0
requests_cache>=0.4.13 requests_cache>=0.4.13
pyqtgraph>=0.10 pyqtgraph>=0.10

View File

@@ -15,7 +15,6 @@ which floats on top.
![Mediaplayer](screenshot-mediaplayer2.jpg) ![Mediaplayer](screenshot-mediaplayer2.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.

View File

@@ -118,15 +118,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.model.layoutChanged.emit() self.model.layoutChanged.emit()
def update_duration(self, mc): def update_duration(self, duration):
self.timeSlider.setMaximum(self.player.duration()) print("!", duration)
duration = self.player.duration() print("?", self.player.duration())
self.timeSlider.setMaximum(duration)
if duration >= 0: if duration >= 0:
self.totalTimeLabel.setText(hhmmss(duration)) self.totalTimeLabel.setText(hhmmss(duration))
def update_position(self, *args): def update_position(self, position):
position = self.player.position()
if position >= 0: if position >= 0:
self.currentTimeLabel.setText(hhmmss(position)) self.currentTimeLabel.setText(hhmmss(position))

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -18,10 +18,9 @@ alien bugs (B'ug) but they could just as easily be anything else.
![Moonsweeper](screenshot-minesweeper2.jpg) ![Moonsweeper](screenshot-minesweeper2.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Code notes ## Code notes

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -5,7 +5,6 @@ everything. Supports file loading, saving and printing.
![No2Pads](screenshot-notepad.jpg) ![No2Pads](screenshot-notepad.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.

View File

@@ -125,39 +125,37 @@ class MainWindow(QMainWindow):
def file_open(self): def file_open(self):
path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "Text documents (*.txt);All files (*.*)") path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "Text documents (*.txt);All files (*.*)")
try: if path:
with open(path, 'rU') as f: try:
text = f.read() with open(path, 'rU') as f:
text = f.read()
except Exception as e: except Exception as e:
self.dialog_critical(str(e)) self.dialog_critical(str(e))
else: else:
self.path = path self.path = path
self.editor.setPlainText(text) self.editor.setPlainText(text)
self.update_title() self.update_title()
def file_save(self): def file_save(self):
if self.path is None: if self.path is None:
# If we do not have a path, we need to use Save As. # If we do not have a path, we need to use Save As.
return self.file_saveas() return self.file_saveas()
text = self.editor.toPlainText() self._save_to_path(self.path)
try:
with open(self.path, 'w') as f:
f.write(text)
except Exception as e:
self.dialog_critical(str(e))
def file_saveas(self): def file_saveas(self):
path, _ = QFileDialog.getSaveFileName(self, "Save file", "", "Text documents (*.txt);All files (*.*)") path, _ = QFileDialog.getSaveFileName(self, "Save file", "", "Text documents (*.txt);All files (*.*)")
text = self.editor.toPlainText()
if not path: if not path:
# If dialog is cancelled, will return '' # If dialog is cancelled, will return ''
return return
self._save_to_path(path)
def _save_to_path(self, path):
text = self.editor.toPlainText()
try: try:
with open(path, 'w') as f: with open(path, 'w') as f:
f.write(text) f.write(text)

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -8,7 +8,6 @@ are stored locally in a SQLite database.
This app is very simple, but demonstrates creation of decoration-less windows in PyQt. Removing the window This app is very simple, but demonstrates creation of decoration-less windows in PyQt. Removing the window
decorations removes the means to drag windows around, so we must re-implement this behaviour ourselves. decorations removes the means to drag windows around, so we must re-implement this behaviour ourselves.
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -17,10 +17,9 @@ which is pre-loaded with pictures of delicious pie.
![Piecasso](screenshot-paint2.jpg) ![Piecasso](screenshot-paint2.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Code notes ## Code notes

View File

@@ -402,27 +402,14 @@ class Canvas(QLabel):
else: else:
self.active_color = self.secondary_color self.active_color = self.secondary_color
# Convert to image for pixel-by-pixel reading.
image = self.pixmap().toImage() image = self.pixmap().toImage()
w, h = image.width(), image.height() w, h = image.width(), image.height()
s = image.bits().asstring(w * h * 4)
x, y = e.x(), e.y() x, y = e.x(), e.y()
# Lookup the 3-byte value at our current location.
i = (x + (y * w)) * 4
target_color = s[i:i+3]
# Convert bytestring to 1byte pp. true/false for matching colour. True values # Get our target color from origin.
# will be 255, non-matching 0. Simplifies the lookup in get_pixel and target_color = image.pixel(x,y)
# comparison in the main loop giving slight performance increase.
s = b''.join(b'\xff' if s[n:n+3] == target_color else b'\x00' for n in range(0, len(s), 4))
def get_pixel(x, y):
i = (x + (y * w))
return s[i]
have_seen = set() have_seen = set()
to_fill = []
queue = [(x, y)] queue = [(x, y)]
def get_cardinal_points(have_seen, center_pos): def get_cardinal_points(have_seen, center_pos):
@@ -439,18 +426,17 @@ class Canvas(QLabel):
return points return points
# Now perform the search and fill.
p = QPainter(self.pixmap())
p.setPen(QPen(self.active_color))
while queue: while queue:
x, y = queue.pop() x, y = queue.pop()
if get_pixel(x, y): # 255 for a match (True) or 0 for a miss (False) if image.pixel(x, y) == target_color:
to_fill.append((x,y)) p.drawPoint(QPoint(x, y))
queue.extend(get_cardinal_points(have_seen, (x, y))) queue.extend(get_cardinal_points(have_seen, (x, y)))
if to_fill: self.update()
# Now we have the points, perform the fill.
p = QPainter(self.pixmap())
p.setPen(QPen(self.active_color))
p.drawPoints(*[QPoint(*xy) for xy in to_fill])
self.update()
# Dropper events # Dropper events

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -59,3 +59,8 @@ Note that the linked repository contains some custom art on ace cards which may
was not used. was not used.
Icons used in the application are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/). Icons used in the application are by [Yusuke Kamiyaman](http://p.yusukekamiyamane.com/).
> If you think this app is neat and want to learn more about
PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
which cover everything you need to know to start building your own applications with PyQt.

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -1,6 +1,6 @@
# Translatarrrr — Instant translation from any language to Pirate # Translatarrrr — Instant translation from any language to Pirate
A translator from any language (supported by Goolge translate) to pirate. A translator from any language (supported by Google translate) to pirate.
This uses a remote API from http://api.funtranslations.com for English This uses a remote API from http://api.funtranslations.com for English
to Pirate translation, and a unofficial Python wrapper around Google translate to Pirate translation, and a unofficial Python wrapper around Google translate
for other languages to English. for other languages to English.
@@ -19,9 +19,6 @@ pay for an API key to get more.
This is, therefore, very useless. This is, therefore, very useless.
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.

View File

@@ -1,2 +1,3 @@
PyQt5>=5.6 PyQt5>=5.6
sip
requests>=2.0.0 requests>=2.0.0

View File

@@ -14,10 +14,9 @@ Simply drag and drop your .zip file onto the cat to fill it up with Pez.
The press the cat's head to release the Pez. The press the cat's head to release the Pez.
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Code notes ## Code notes

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -56,7 +56,7 @@ class UnzipWorker(QRunnable):
items = self.zipfile.infolist() items = self.zipfile.infolist()
total_n = len(items) total_n = len(items)
for n, item in enumerate(items): for n, item in enumerate(items, 1):
if not any(item.filename.startswith(p) for p in EXCLUDE_PATHS): if not any(item.filename.startswith(p) for p in EXCLUDE_PATHS):
self.zipfile.extract(item) self.zipfile.extract(item)
@@ -99,7 +99,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Perform the unzip # Perform the unzip
self.threadpool.start(self.worker) self.threadpool.start(self.worker)
self.worker = None # Remove the worker so it is not double-triggere. self.worker = None # Remove the worker so it is not double-triggered.
elif e.button() == Qt.RightButton: elif e.button() == Qt.RightButton:
pass # Open a new zip. pass # Open a new zip.
@@ -201,11 +201,13 @@ class MainWindow(QMainWindow, Ui_MainWindow):
) )
def unzip_finished(self): def unzip_finished(self):
self.update_progress(1) pass
def unzip_error(self, err): def unzip_error(self, err):
exctype, value, traceback = err exctype, value, traceback = err
self.update_progress(1) # Reset the Pez bar.
dlg = QMessageBox(self) dlg = QMessageBox(self)
dlg.setText(traceback) dlg.setText(traceback)
dlg.setIcon(QMessageBox.Critical) dlg.setIcon(QMessageBox.Critical)

View File

@@ -5,10 +5,9 @@ weather and forecast API from https://openweathermap.org/
![Weather](screenshot-weather.jpg) ![Weather](screenshot-weather.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Other licenses ## Other licenses

View File

@@ -1,2 +1,3 @@
PyQt5>=5.6 PyQt5>=5.6
sip
requests>=2.0.0 requests>=2.0.0

View File

@@ -12,10 +12,9 @@ Saves and opens HTML format documents.
![Wordprocessor](screenshot-wordprocessor.jpg) ![Wordprocessor](screenshot-wordprocessor.jpg)
> If you think this example app is neat and want to learn more about > If you think this app is neat and want to learn more about
PyQt in general, [take a look at my ebook & online course PyQt in general, take a look at my [free PyQt tutorials](https://www.learnpyqt.com)
"Create Simple GUI Applications"](https://martinfitzpatrick.name/create-simple-gui-applications) which cover everything you need to know to start building your own applications with PyQt.
which covers everything you need to know to start building your own applications with PyQt.
## Other licenses ## Other licenses

View File

@@ -1 +1,2 @@
PyQt5>=5.6 PyQt5>=5.6
sip

View File

@@ -68,7 +68,6 @@ class MainWindow(QMainWindow):
layout = QVBoxLayout() layout = QVBoxLayout()
self.editor = TextEdit() self.editor = TextEdit()
# Setup the QTextEdit editor configuration # Setup the QTextEdit editor configuration
self.editor.setAcceptRichText(False)
self.editor.setAutoFormatting(QTextEdit.AutoAll) self.editor.setAutoFormatting(QTextEdit.AutoAll)
self.editor.selectionChanged.connect(self.update_format) self.editor.selectionChanged.connect(self.update_format)
# Initialize default font size. # Initialize default font size.