Skip to content

Commit

Permalink
new preview & nosignal pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
nlef committed Jan 6, 2022
1 parent 09bc99e commit 95359b9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
3 changes: 2 additions & 1 deletion bot/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def take_photo(self) -> BytesIO:

if not success:
logger.debug("failed to get camera frame for photo")
img = Image.open(random.choice(glob.glob(f'{self._imgs_path}/imgs/*')))
# Todo: resize to cam resolution!
img = Image.open('../imgs/nosignal.png')
else:
if self._hw_accel:
image_um = cv2.UMat(image)
Expand Down
45 changes: 23 additions & 22 deletions bot/klippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,28 +234,29 @@ def _get_eta_message(self) -> str:
return f"Estimated time left: {eta}\nFinish at {datetime.now() + eta:%Y-%m-%d %H:%M}\n"

def _populate_with_thumb(self, thumb_path: str, message: str):
response = requests.get(f"http://{self._host}/server/files/gcodes/{urllib.parse.quote(thumb_path)}", stream=True, headers=self._headers)
if response.ok:
response.raw.decode_content = True
img = Image.open(response.raw).convert('RGB')

bio = BytesIO()
bio.name = f'{self.printing_filename}.webp'
img.save(bio, 'WebP', quality=0, lossless=True)
bio.seek(0)
img.close()
return message, bio
if not thumb_path:
# Todo: resize?
img = Image.open('../imgs/nopreview.png').convert('RGB')
else:
logger.error(f"Thumbnail download failed for {thumb_path} \n\n{response.reason}")
# Todo: add preview placeholder!
return message, None
response = requests.get(f"http://{self._host}/server/files/gcodes/{urllib.parse.quote(thumb_path)}", stream=True, headers=self._headers)
if response.ok:
response.raw.decode_content = True
img = Image.open(response.raw).convert('RGB')
else:
logger.error(f"Thumbnail download failed for {thumb_path} \n\n{response.reason}")
# Todo: resize?
img = Image.open('../imgs/nopreview.png').convert('RGB')

bio = BytesIO()
bio.name = f'{self.printing_filename}.webp'
img.save(bio, 'WebP', quality=0, lossless=True)
bio.seek(0)
img.close()
return message, bio

def get_file_info(self, message: str = '') -> (str, BytesIO):
message = self.get_print_stats(message)
if self._thumbnail_path:
return self._populate_with_thumb(self._thumbnail_path, message)
else:
return message, None
return self._populate_with_thumb(self._thumbnail_path, message)

def _get_printing_file_info(self, message_pre: str = ''):
message = f'Printing: {self.printing_filename} \n' if not message_pre else f'{message_pre}: {self.printing_filename} \n'
Expand Down Expand Up @@ -320,15 +321,15 @@ def get_file_info_by_name(self, filename: str, message: str):
if 'estimated_time' in resp and resp['estimated_time'] > 0.0:
message += f"\nEstimated printing time: {timedelta(seconds=resp['estimated_time'])}"

thumb_path = ''
if 'thumbnails' in resp:
thumb = max(resp['thumbnails'], key=lambda el: el['size'])
if 'relative_path' in thumb:
return self._populate_with_thumb(thumb['relative_path'], message)
thumb_path = thumb['relative_path']
else:
logger.error(f"Thumbnail relative_path not found in {resp}")
return message, None
else:
return message, None

return self._populate_with_thumb(thumb_path, message)

# TOdo: add scrolling
def get_gcode_files(self):
Expand Down
3 changes: 2 additions & 1 deletion bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def button_handler(update: Update, context: CallbackContext) -> None:
query.answer()
# Todo: maybe regex check?
if query.data == 'do_nothing':
context.bot.delete_message(update.effective_message.chat_id, update.effective_message.reply_to_message.message_id)
if update.effective_message.reply_to_message:
context.bot.delete_message(update.effective_message.chat_id, update.effective_message.reply_to_message.message_id)
query.delete_message()
elif query.data == 'emergency_stop':
emergency_stop_printer()
Expand Down
Binary file added imgs/nopreview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/nosignal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed imgs/nyan-cat-01-625x450.jpg
Binary file not shown.
1 change: 0 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ create_initial_config() {

report_status "Creating base config file"
cp -n "${MOONRAKER_BOT_DIR}"/scripts/base_install_template "${KLIPPER_CONF_DIR}"/telegram.conf
cp -rn "${MOONRAKER_BOT_DIR}"/imgs "${KLIPPER_CONF_DIR}"/

sed -i "s+some_log_path+${MOONRAKER_BOT_LOG}+g" "${KLIPPER_CONF_DIR}"/telegram.conf
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ wsaccel==0.6.3
websocket-client==1.2.3
Pillow==9.0.0
emoji==1.6.1
requests==2.26.0
requests==2.27.1
opencv-python~=3.4.8.29
numpy~=1.20.1
memory_profiler==0.60.0
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ wsaccel==0.6.3
websocket-client==1.2.3
Pillow==9.0.0
emoji==1.6.1
requests==2.26.0
requests==2.27.1

0 comments on commit 95359b9

Please sign in to comment.