Use traceback to format exception information
Thomas Ross
2 years ago
30 | 30 | import random, urllib.request, locale |
31 | 31 | import stat, time, subprocess, shutil, filecmp |
32 | 32 | import tempfile, socket, threading |
33 | import traceback | |
33 | 34 | |
34 | 35 | from .fullscreen_controls import FullscreenControls |
35 | 36 | |
434 | 435 | icon_path = self.find_path("mirage.png") |
435 | 436 | try: |
436 | 437 | Gtk.Window.set_default_icon_from_file(icon_path) |
437 | except Exception as e: | |
438 | print(e, file=sys.stderr) | |
438 | except: | |
439 | print(traceback.format_exc(), file=sys.stderr) | |
439 | 440 | vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) |
440 | 441 | |
441 | 442 | # Hidden hotkeys |
812 | 813 | pix = self.pixbuf_add_border(pix) |
813 | 814 | try: |
814 | 815 | self.thumblist[imgnum] = [pix] |
815 | except Exception as e: | |
816 | print(e, file=sys.stderr) | |
816 | except: | |
817 | print(traceback.format_exc(), file=sys.stderr) | |
817 | 818 | self.thumbscroll.get_vscrollbar().handler_unblock( |
818 | 819 | self.thumb_scroll_handler |
819 | 820 | ) |
865 | 866 | [uri, file_mtime, "Mirage" + __version__], |
866 | 867 | ) |
867 | 868 | return pix |
868 | except Exception as e: | |
869 | print(e, file=sys.stderr) | |
869 | except: | |
870 | print(traceback.format_exc(), file=sys.stderr) | |
870 | 871 | return None |
871 | 872 | |
872 | 873 | def thumbpane_load_image(self, treeview, imgnum): |
885 | 886 | if not self.thumbnail_loaded[imgnum]: |
886 | 887 | self.thumbpane_set_image(self.image_list[imgnum], imgnum) |
887 | 888 | GLib.idle_add(self.thumbpane_load_image, treeview, imgnum) |
888 | except Exception as e: | |
889 | print(e, file=sys.stderr) | |
889 | except: | |
890 | print(traceback.format_exc(), file=sys.stderr) | |
890 | 891 | |
891 | 892 | def thumbpane_select(self, imgnum): |
892 | 893 | if self.thumbpane_show: |
895 | 896 | path = Gtk.TreePath(imgnum) |
896 | 897 | self.thumbpane.get_selection().select_path(path) |
897 | 898 | self.thumbpane.scroll_to_cell(path) |
898 | except Exception as e: | |
899 | print(e, file=sys.stderr) | |
899 | except: | |
900 | print(traceback.format_exc(), file=sys.stderr) | |
900 | 901 | self.thumbpane.get_selection().handler_unblock(self.thumb_sel_handler) |
901 | 902 | |
902 | 903 | def thumbpane_set_size(self): |
926 | 927 | imgheight |
927 | 928 | ) # Account for border that will be added to thumbnails.. |
928 | 929 | imgwidth = self.thumbnail_size |
929 | except Exception as e: | |
930 | print(e, file=sys.stderr) | |
930 | except: | |
931 | print(traceback.format_exc(), file=sys.stderr) | |
931 | 932 | imgheight = 2 + self.thumbnail_size |
932 | 933 | imgwidth = self.thumbnail_size |
933 | 934 | blank_pix = GdkPixbuf.Pixbuf.new( |
1152 | 1153 | self.parse_action_command( |
1153 | 1154 | self.action_commands[i], self.action_batch[i] |
1154 | 1155 | ) |
1155 | except Exception as e: | |
1156 | print(e, file=sys.stderr) | |
1156 | except: | |
1157 | print(traceback.format_exc(), file=sys.stderr) | |
1157 | 1158 | |
1158 | 1159 | break |
1159 | 1160 | |
1254 | 1255 | ].get_name() |
1255 | 1256 | if self.filetype_is_writable(filetype): |
1256 | 1257 | self.action_group.lookup_action("save-image").set_enabled(enable) |
1257 | except Exception as e: | |
1258 | print(e, file=sys.stderr) | |
1258 | except: | |
1259 | print(traceback.format_exc(), file=sys.stderr) | |
1259 | 1260 | |
1260 | 1261 | for action in self.action_group.list_actions(): |
1261 | 1262 | if action.startswith("custom-"): |
1407 | 1408 | - self.layout.get_hadjustment().get_page_size() |
1408 | 1409 | ): |
1409 | 1410 | self.layout.get_hadjustment().set_value(newvalue) |
1410 | except Exception as e: | |
1411 | print(e, file=sys.stderr) | |
1411 | except: | |
1412 | print(traceback.format_exc(), file=sys.stderr) | |
1412 | 1413 | if self.vscroll.get_property("visible"): |
1413 | 1414 | try: |
1414 | 1415 | newvalue = abs( |
1421 | 1422 | ): |
1422 | 1423 | self.layout.get_vadjustment().set_value(newvalue) |
1423 | 1424 | self.previmg_width = self.currimg_width |
1424 | except Exception as e: | |
1425 | print(e, file=sys.stderr) | |
1425 | except: | |
1426 | print(traceback.format_exc(), file=sys.stderr) | |
1426 | 1427 | self.updating_adjustments = False |
1427 | 1428 | |
1428 | 1429 | def window_resized(self, widget, allocation, force_update=False): |
1681 | 1682 | self.save_image_as(None, None, None) |
1682 | 1683 | else: |
1683 | 1684 | error_dialog.destroy() |
1684 | except Exception as e: | |
1685 | print(e, file=sys.stderr) | |
1685 | except: | |
1686 | print(traceback.format_exc(), file=sys.stderr) | |
1686 | 1687 | error_dialog = Gtk.MessageDialog( |
1687 | 1688 | self.window, |
1688 | 1689 | Gtk.DialogFlags.MODAL, |
1994 | 1995 | + str(ratio) |
1995 | 1996 | + "% " |
1996 | 1997 | ) |
1997 | except Exception as e: | |
1998 | print(e, file=sys.stderr) | |
1998 | except: | |
1999 | print(traceback.format_exc(), file=sys.stderr) | |
1999 | 2000 | status_text = _("Cannot load image.") |
2000 | 2001 | self.statusbar.push(self.statusbar.get_context_id(""), status_text) |
2001 | 2002 | status_text = "" |
3992 | 3993 | self_get_name(self.currimg_name)[1], |
3993 | 3994 | self.thumbnail_get_name(new_filename)[1], |
3994 | 3995 | ) |
3995 | except Exception as e: | |
3996 | print(e, file=sys.stderr) | |
3996 | except: | |
3997 | print(traceback.format_exc(), file=sys.stderr) | |
3997 | 3998 | self.recent_file_remove_and_refresh(self.currimg_name) |
3998 | 3999 | self.currimg_name = new_filename |
3999 | 4000 | self.register_file_with_recent_docs(self.currimg_name) |
4000 | 4001 | self.update_title() |
4001 | except Exception as e: | |
4002 | print(e, file=sys.stderr) | |
4002 | except: | |
4003 | print(traceback.format_exc(), file=sys.stderr) | |
4003 | 4004 | error_dialog = Gtk.MessageDialog( |
4004 | 4005 | self.window, |
4005 | 4006 | Gtk.DialogFlags.MODAL, |
4061 | 4062 | self.image_modified = False |
4062 | 4063 | try: |
4063 | 4064 | os.remove(self.thumbnail_get_name(self.currimg_name)[1]) |
4064 | except Exception as e: | |
4065 | print(e, file=sys.stderr) | |
4065 | except: | |
4066 | print(traceback.format_exc(), file=sys.stderr) | |
4066 | 4067 | self.recent_file_remove_and_refresh(self.currimg_name) |
4067 | 4068 | iter = self.thumblist.get_iter((self.curr_img_in_list,)) |
4068 | 4069 | try: |
4069 | 4070 | self.thumbnail_loaded.pop(self.curr_img_in_list) |
4070 | 4071 | self.thumbpane_update_images() |
4071 | except Exception as e: | |
4072 | print(e, file=sys.stderr) | |
4072 | except: | |
4073 | print(traceback.format_exc(), file=sys.stderr) | |
4073 | 4074 | self.thumblist.remove(iter) |
4074 | 4075 | templist = self.image_list |
4075 | 4076 | self.image_list = [] |
4098 | 4099 | self.set_go_navigation_sensitivities(False) |
4099 | 4100 | # Select new item: |
4100 | 4101 | self.thumbpane_select(self.curr_img_in_list) |
4101 | except Exception as e: | |
4102 | print(e, file=sys.stderr) | |
4102 | except: | |
4103 | print(traceback.format_exc(), file=sys.stderr) | |
4103 | 4104 | error_dialog = Gtk.MessageDialog( |
4104 | 4105 | self.window, |
4105 | 4106 | Gtk.DialogFlags.MODAL, |
4164 | 4165 | try: |
4165 | 4166 | self.about_dialog.set_transient_for(self.window) |
4166 | 4167 | self.about_dialog.set_modal(True) |
4167 | except Exception as e: | |
4168 | print(e, file=sys.stderr) | |
4168 | except: | |
4169 | print(traceback.format_exc(), file=sys.stderr) | |
4169 | 4170 | self.about_dialog.set_name("Mirage") |
4170 | 4171 | self.about_dialog.set_version(__version__) |
4171 | 4172 | self.about_dialog.set_comments(_("A fast GTK+ Image Viewer.")) |
4201 | 4202 | try: |
4202 | 4203 | icon_pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_path) |
4203 | 4204 | self.about_dialog.set_logo(icon_pixbuf) |
4204 | except Exception as e: | |
4205 | print(e, file=sys.stderr) | |
4205 | except: | |
4206 | print(traceback.format_exc(), file=sys.stderr) | |
4206 | 4207 | self.about_dialog.connect("response", self.close_about) |
4207 | 4208 | self.about_dialog.show_all() |
4208 | 4209 | |
4598 | 4599 | newpix.fill(0x858585FF) |
4599 | 4600 | pix.copy_area(0, 0, width, height, newpix, 1, 1) |
4600 | 4601 | return newpix |
4601 | except Exception as e: | |
4602 | print(e, file=sys.stderr) | |
4602 | except: | |
4603 | print(traceback.format_exc(), file=sys.stderr) | |
4603 | 4604 | return pix |
4604 | 4605 | |
4605 | 4606 | def crop_image(self, action, parameter, data): |
5106 | 5107 | self.imageview.set_from_pixbuf(self.currimg_pixbuf) |
5107 | 5108 | self.currimg_pixbuf = bak.copy() |
5108 | 5109 | del bak |
5109 | except Exception as e: | |
5110 | print(e, file=sys.stderr) | |
5110 | except: | |
5111 | print(traceback.format_exc(), file=sys.stderr) | |
5111 | 5112 | gc.collect() |
5112 | 5113 | |
5113 | 5114 | def resize_image(self, action, parameter, data): |
5511 | 5512 | reset_cursor, |
5512 | 5513 | perform_onload_action, |
5513 | 5514 | ) |
5514 | except Exception as e: | |
5515 | print(e, file=sys.stderr) | |
5515 | except: | |
5516 | print(traceback.format_exc(), file=sys.stderr) | |
5516 | 5517 | self.image_load_failed(True) |
5517 | 5518 | if preload_next_image_after: |
5518 | 5519 | self.preload_when_idle = GLib.idle_add(self.preload_next_image, False) |
5840 | 5841 | gc.collect() |
5841 | 5842 | if self.verbose: |
5842 | 5843 | print(_("Preloading: %s") % self.preloadimg_next_name) |
5843 | except Exception as e: | |
5844 | print(e, file=sys.stderr) | |
5844 | except: | |
5845 | print(traceback.format_exc(), file=sys.stderr) | |
5845 | 5846 | self.preloadimg_next_in_list = -1 |
5846 | 5847 | |
5847 | 5848 | def preload_prev_image(self, use_existing_image): |
5921 | 5922 | gc.collect() |
5922 | 5923 | if self.verbose: |
5923 | 5924 | print(_("Preloading: %s") % self.preloadimg_prev_name) |
5924 | except Exception as e: | |
5925 | print(e, file=sys.stderr) | |
5925 | except: | |
5926 | print(traceback.format_exc(), file=sys.stderr) | |
5926 | 5927 | self.preloadimg_prev_in_list = -1 |
5927 | 5928 | |
5928 | 5929 | def change_cursor(self, type): |
5984 | 5985 | socket.setdefaulttimeout(5) |
5985 | 5986 | urllib.request.urlretrieve(inputlist[itemnum], tmpfile) |
5986 | 5987 | inputlist[itemnum] = tmpfile |
5987 | except Exception as e: | |
5988 | print(e, file=sys.stderr) | |
5988 | except: | |
5989 | print(traceback.format_exc(), file=sys.stderr) | |
5989 | 5990 | # Remove hidden files from list: |
5990 | 5991 | if not self.open_hidden_files: |
5991 | 5992 | tmplist = [] |
6112 | 6113 | if not self.closing_app: |
6113 | 6114 | while Gtk.events_pending(): |
6114 | 6115 | Gtk.main_iteration() |
6115 | except Exception as e: | |
6116 | print(e, file=sys.stderr) | |
6116 | except: | |
6117 | print(traceback.format_exc(), file=sys.stderr) | |
6117 | 6118 | if first_image_came_from_dir: |
6118 | 6119 | self.image_list = [] |
6119 | 6120 | # Pre-load second image: |
6255 | 6256 | uri = "file://" |
6256 | 6257 | uri = uri + urllib.request.pathname2url(os.path.abspath(imgfile)) |
6257 | 6258 | gtk_recent_manager.add_item(uri) |
6258 | except Exception as e: | |
6259 | print(e, file=sys.stderr) | |
6259 | except: | |
6260 | print(traceback.format_exc(), file=sys.stderr) | |
6260 | 6261 | # Isnt currently functional on win32 |
6261 | 6262 | if sys.platform == "win32": |
6262 | 6263 | pass |