Skip to content

Commit

Permalink
Merge pull request OpenShot#4527 from OpenShot/py310-numeric-types
Browse files Browse the repository at this point in the history
Fix passing of integer arguments in Python 3.10+
  • Loading branch information
ferdnyc authored Nov 25, 2021
2 parents 54f87bc + 33cf68c commit fff785e
Show file tree
Hide file tree
Showing 16 changed files with 581 additions and 397 deletions.
8 changes: 4 additions & 4 deletions src/classes/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def do_GET(self):

# Send message back to client
if os.path.exists(thumb_path):
if not only_path:
self.wfile.write(open(thumb_path, 'rb').read())
else:
if only_path:
self.wfile.write(bytes(thumb_path, "utf-8"))
else:
with open(thumb_path, 'rb') as f:
self.wfile.write(f.read())

# Pause processing of request (since we don't currently use thread pooling, this allows
# the threads to be processed without choking the CPU as much
# TODO: Make HTTPServer work with a limited thread pool and remove this sleep() hack.
time.sleep(0.01)

2 changes: 1 addition & 1 deletion src/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"""

import sys
import os.path
import os
import argparse

from PyQt5.QtCore import Qt
Expand Down
8 changes: 4 additions & 4 deletions src/windows/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def updateProgressBar(self, title_message, start_frame, end_frame, current_frame
percentage_string = format_of_progress_string % (( current_frame - start_frame ) / ( end_frame - start_frame ) * 100)
else:
percentage_string = "100%"
self.progressExportVideo.setValue(current_frame)
self.progressExportVideo.setValue(int(current_frame))
self.progressExportVideo.setFormat(percentage_string)
self.setWindowTitle("%s %s" % (percentage_string, title_message))

Expand Down Expand Up @@ -690,9 +690,9 @@ def titlestring(sec, fps, mess):
fps_encode = 0

# Init progress bar
self.progressExportVideo.setMinimum(self.txtStartFrame.value())
self.progressExportVideo.setMaximum(self.txtEndFrame.value())
self.progressExportVideo.setValue(self.txtStartFrame.value())
self.progressExportVideo.setMinimum(int(self.txtStartFrame.value()))
self.progressExportVideo.setMaximum(int(self.txtEndFrame.value()))
self.progressExportVideo.setValue(int(self.txtStartFrame.value()))

# Prompt error message
if self.txtStartFrame.value() == self.txtEndFrame.value():
Expand Down
42 changes: 21 additions & 21 deletions src/windows/models/properties_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
new_value = None

log.info(
"%s for %s changed to %s at frame %s with interpolation: %s at closest x: %s"
% (property_key, clip_id, new_value, self.frame_number, interpolation, closest_point_x))
"%s for %s changed to %s at frame %s with interpolation: %s at closest x: %s",
property_key, clip_id, new_value, self.frame_number, interpolation, closest_point_x)

# Find this clip
c = None
Expand Down Expand Up @@ -444,7 +444,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
log.debug("%s: update property %s. %s", log_id, property_key, clip_data.get(property_key))

# Check the type of property (some are keyframe, and some are not)
if property_type != "reader" and type(clip_data[property_key]) == dict:
if property_type != "reader" and isinstance(clip_data[property_key], dict):
# Keyframe
# Loop through points, find a matching points on this frame
found_point = False
Expand Down Expand Up @@ -517,36 +517,36 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
clip_updated = True
try:
clip_data[property_key] = int(new_value)
except Exception as ex:
log.warn('Invalid Integer value passed to property: %s' % ex)
except Exception:
log.warn('Invalid Integer value passed to property', exc_info=1)

elif property_type == "float":
clip_updated = True
try:
clip_data[property_key] = float(new_value)
except Exception as ex:
log.warn('Invalid Float value passed to property: %s' % ex)
except Exception:
log.warn('Invalid Float value passed to property', exc_info=1)

elif property_type == "bool":
clip_updated = True
try:
clip_data[property_key] = bool(new_value)
except Exception as ex:
log.warn('Invalid Boolean value passed to property: %s' % ex)
except Exception:
log.warn('Invalid Boolean value passed to property', exc_info=1)

elif property_type == "string":
clip_updated = True
try:
clip_data[property_key] = str(new_value)
except Exception as ex:
log.warn('Invalid String value passed to property: %s' % ex)
except Exception:
log.warn('Invalid String value passed to property', exc_info=1)

elif property_type in ["font", "caption"]:
clip_updated = True
try:
clip_data[property_key] = str(new_value)
except Exception as ex:
log.warn('Invalid Font/Caption value passed to property: %s' % ex)
except Exception:
log.warn('Invalid Font/Caption value passed to property', exc_info=1)

elif property_type == "reader":
# Transition
Expand All @@ -557,8 +557,8 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
clip_data[property_key] = json.loads(clip_object.Reader().Json())
clip_object.Close()
clip_object = None
except Exception as ex:
log.warn('Invalid Reader value passed to property: %s (%s)' % (value, ex))
except Exception:
log.warn('Invalid Reader value passed to property: %s', value, exc_info=1)

# Reduce # of clip properties we are saving (performance boost)
clip_data = {property_key: clip_data.get(property_key)}
Expand Down Expand Up @@ -688,9 +688,9 @@ def set_property(self, property, filter, c, item_type, object_id=None):

if type == "color":
# Color needs to be handled special
red = property[1]["red"]["value"]
green = property[1]["green"]["value"]
blue = property[1]["blue"]["value"]
red = int(property[1]["red"]["value"])
green = int(property[1]["green"]["value"])
blue = int(property[1]["blue"]["value"])
col.setBackground(QColor(red, green, blue))

if readonly or type in ["color", "font", "caption"] or choices or label == "Track":
Expand Down Expand Up @@ -789,9 +789,9 @@ def set_property(self, property, filter, c, item_type, object_id=None):

if type == "color":
# Update the color based on the color curves
red = property[1]["red"]["value"]
green = property[1]["green"]["value"]
blue = property[1]["blue"]["value"]
red = int(property[1]["red"]["value"])
green = int(property[1]["green"]["value"])
blue = int(property[1]["blue"]["value"])
col.setBackground(QColor(red, green, blue))

# Update helper dictionary
Expand Down
18 changes: 11 additions & 7 deletions src/windows/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self):

def txtSearch_changed(self):
"""textChanged event handler for search box"""
log.info("Search for %s" % self.txtSearch.text())
log.info("Search for %s", self.txtSearch.text())

# Populate preferences
self.Populate(filter=self.txtSearch.text())
Expand Down Expand Up @@ -317,7 +317,7 @@ def Populate(self, filter=""):
value_list.remove(value_item)

# Remove hardware mode items which cannot decode the example video
log.debug("Preparing to test hardware decoding: %s" % (value_list))
log.debug("Preparing to test hardware decoding: %s", value_list)
for value_item in list(value_list):
v = value_item["value"]
if (not self.testHardwareDecode(value_list, v, 0)
Expand Down Expand Up @@ -470,7 +470,7 @@ def bool_value_changed(self, widget, param, state):
# Trigger specific actions
if param["setting"] == "debug-mode":
# Update debug setting of timeline
log.info("Setting debug-mode to %s" % (state == Qt.Checked))
log.info("Setting debug-mode to %s", state == Qt.Checked)
debug_enabled = (state == Qt.Checked)

# Enable / Disable logger
Expand Down Expand Up @@ -528,7 +528,9 @@ def text_value_changed(self, widget, param, value=None):
if param.get("category") == "Keyboard":
previous_value = value
value = QKeySequence(value).toString()
log.info("Parsing keyboard mapping via QKeySequence from %s to %s" % (previous_value, value))
log.info(
"Parsing keyboard mapping via QKeySequence from %s to %s",
previous_value, value)

# Save setting
self.s.set(param["setting"], value)
Expand Down Expand Up @@ -604,19 +606,21 @@ def testHardwareDecode(self, all_decoders, decoder, decoder_card="0"):
if reader.GetFrame(0).CheckPixel(0, 0, 2, 133, 255, 255, 5):
is_supported = True
self.hardware_tests_cards[decoder_card].append(int(decoder))
log.debug("Successful hardware decoder! %s (%s-%s)" % (decoder_name, decoder, decoder_card))
log.debug(
"Successful hardware decoder! %s (%s-%s)",
decoder_name, decoder, decoder_card)
else:
log.debug(
"CheckPixel failed testing hardware decoding (i.e. wrong color found): %s (%s-%s)",
(decoder_name, decoder, decoder_card))
decoder_name, decoder, decoder_card)

reader.Close()
clip.Close()

except Exception:
log.debug(
"Exception trying to test hardware decoding (this is expected): %s (%s-%s)",
(decoder_name, decoder, decoder_card))
decoder_name, decoder, decoder_card)

# Resume current settings
openshot.Settings.Instance().HARDWARE_DECODER = current_decoder
Expand Down
2 changes: 1 addition & 1 deletion src/windows/process_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def accept(self):
while(not processing.IsDone() ):
# update progressbar
progressionStatus = processing.GetProgress()
self.progressBar.setValue(progressionStatus)
self.progressBar.setValue(int(progressionStatus))
time.sleep(0.01)

# Process any queued events
Expand Down
Loading

0 comments on commit fff785e

Please sign in to comment.