Print exceptions to stderr instead of ignoring them
Thomas Ross
3 years ago
434 | 434 | icon_path = self.find_path("mirage.png") |
435 | 435 | try: |
436 | 436 | Gtk.Window.set_default_icon_from_file(icon_path) |
437 | except: | |
438 | pass | |
437 | except Exception as e: | |
438 | print(e, file=sys.stderr) | |
439 | 439 | vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) |
440 | 440 | |
441 | 441 | # Hidden hotkeys |
812 | 812 | pix = self.pixbuf_add_border(pix) |
813 | 813 | try: |
814 | 814 | self.thumblist[imgnum] = [pix] |
815 | except: | |
816 | pass | |
815 | except Exception as e: | |
816 | print(e, file=sys.stderr) | |
817 | 817 | self.thumbscroll.get_vscrollbar().handler_unblock( |
818 | 818 | self.thumb_scroll_handler |
819 | 819 | ) |
865 | 865 | [uri, file_mtime, "Mirage" + __version__], |
866 | 866 | ) |
867 | 867 | return pix |
868 | except: | |
868 | except Exception as e: | |
869 | print(e, file=sys.stderr) | |
869 | 870 | return None |
870 | 871 | |
871 | 872 | def thumbpane_load_image(self, treeview, imgnum): |
884 | 885 | if not self.thumbnail_loaded[imgnum]: |
885 | 886 | self.thumbpane_set_image(self.image_list[imgnum], imgnum) |
886 | 887 | GLib.idle_add(self.thumbpane_load_image, treeview, imgnum) |
887 | except: | |
888 | pass | |
888 | except Exception as e: | |
889 | print(e, file=sys.stderr) | |
889 | 890 | |
890 | 891 | def thumbpane_select(self, imgnum): |
891 | 892 | if self.thumbpane_show: |
894 | 895 | path = Gtk.TreePath(imgnum) |
895 | 896 | self.thumbpane.get_selection().select_path(path) |
896 | 897 | self.thumbpane.scroll_to_cell(path) |
897 | except: | |
898 | pass | |
898 | except Exception as e: | |
899 | print(e, file=sys.stderr) | |
899 | 900 | self.thumbpane.get_selection().handler_unblock(self.thumb_sel_handler) |
900 | 901 | |
901 | 902 | def thumbpane_set_size(self): |
925 | 926 | imgheight |
926 | 927 | ) # Account for border that will be added to thumbnails.. |
927 | 928 | imgwidth = self.thumbnail_size |
928 | except: | |
929 | except Exception as e: | |
930 | print(e, file=sys.stderr) | |
929 | 931 | imgheight = 2 + self.thumbnail_size |
930 | 932 | imgwidth = self.thumbnail_size |
931 | 933 | blank_pix = GdkPixbuf.Pixbuf.new( |
1150 | 1152 | self.parse_action_command( |
1151 | 1153 | self.action_commands[i], self.action_batch[i] |
1152 | 1154 | ) |
1153 | except: | |
1154 | pass | |
1155 | except Exception as e: | |
1156 | print(e, file=sys.stderr) | |
1155 | 1157 | |
1156 | 1158 | break |
1157 | 1159 | |
1252 | 1254 | ].get_name() |
1253 | 1255 | if self.filetype_is_writable(filetype): |
1254 | 1256 | self.action_group.lookup_action("save-image").set_enabled(enable) |
1255 | except: | |
1256 | pass | |
1257 | except Exception as e: | |
1258 | print(e, file=sys.stderr) | |
1257 | 1259 | |
1258 | 1260 | for action in self.action_group.list_actions(): |
1259 | 1261 | if action.startswith("custom-"): |
1405 | 1407 | - self.layout.get_hadjustment().get_page_size() |
1406 | 1408 | ): |
1407 | 1409 | self.layout.get_hadjustment().set_value(newvalue) |
1408 | except: | |
1409 | pass | |
1410 | except Exception as e: | |
1411 | print(e, file=sys.stderr) | |
1410 | 1412 | if self.vscroll.get_property("visible"): |
1411 | 1413 | try: |
1412 | 1414 | newvalue = abs( |
1419 | 1421 | ): |
1420 | 1422 | self.layout.get_vadjustment().set_value(newvalue) |
1421 | 1423 | self.previmg_width = self.currimg_width |
1422 | except: | |
1423 | pass | |
1424 | except Exception as e: | |
1425 | print(e, file=sys.stderr) | |
1424 | 1426 | self.updating_adjustments = False |
1425 | 1427 | |
1426 | 1428 | def window_resized(self, widget, allocation, force_update=False): |
1676 | 1678 | self.save_image_as(None, None, None) |
1677 | 1679 | else: |
1678 | 1680 | error_dialog.destroy() |
1679 | except: | |
1681 | except Exception as e: | |
1682 | print(e, file=sys.stderr) | |
1680 | 1683 | error_dialog = Gtk.MessageDialog( |
1681 | 1684 | self.window, |
1682 | 1685 | Gtk.DialogFlags.MODAL, |
1982 | 1985 | + str(ratio) |
1983 | 1986 | + "% " |
1984 | 1987 | ) |
1985 | except: | |
1988 | except Exception as e: | |
1989 | print(e, file=sys.stderr) | |
1986 | 1990 | status_text = _("Cannot load image.") |
1987 | 1991 | self.statusbar.push(self.statusbar.get_context_id(""), status_text) |
1988 | 1992 | status_text = "" |
3971 | 3975 | self_get_name(self.currimg_name)[1], |
3972 | 3976 | self.thumbnail_get_name(new_filename)[1], |
3973 | 3977 | ) |
3974 | except: | |
3975 | pass | |
3978 | except Exception as e: | |
3979 | print(e, file=sys.stderr) | |
3976 | 3980 | self.recent_file_remove_and_refresh(self.currimg_name) |
3977 | 3981 | self.currimg_name = new_filename |
3978 | 3982 | self.register_file_with_recent_docs(self.currimg_name) |
3979 | 3983 | self.update_title() |
3980 | except: | |
3984 | except Exception as e: | |
3985 | print(e, file=sys.stderr) | |
3981 | 3986 | error_dialog = Gtk.MessageDialog( |
3982 | 3987 | self.window, |
3983 | 3988 | Gtk.DialogFlags.MODAL, |
4039 | 4044 | self.image_modified = False |
4040 | 4045 | try: |
4041 | 4046 | os.remove(self.thumbnail_get_name(self.currimg_name)[1]) |
4042 | except: | |
4043 | pass | |
4047 | except Exception as e: | |
4048 | print(e, file=sys.stderr) | |
4044 | 4049 | self.recent_file_remove_and_refresh(self.currimg_name) |
4045 | 4050 | iter = self.thumblist.get_iter((self.curr_img_in_list,)) |
4046 | 4051 | try: |
4047 | 4052 | self.thumbnail_loaded.pop(self.curr_img_in_list) |
4048 | 4053 | self.thumbpane_update_images() |
4049 | except: | |
4050 | pass | |
4054 | except Exception as e: | |
4055 | print(e, file=sys.stderr) | |
4051 | 4056 | self.thumblist.remove(iter) |
4052 | 4057 | templist = self.image_list |
4053 | 4058 | self.image_list = [] |
4076 | 4081 | self.set_go_navigation_sensitivities(False) |
4077 | 4082 | # Select new item: |
4078 | 4083 | self.thumbpane_select(self.curr_img_in_list) |
4079 | except: | |
4084 | except Exception as e: | |
4085 | print(e, file=sys.stderr) | |
4080 | 4086 | error_dialog = Gtk.MessageDialog( |
4081 | 4087 | self.window, |
4082 | 4088 | Gtk.DialogFlags.MODAL, |
4138 | 4144 | try: |
4139 | 4145 | self.about_dialog.set_transient_for(self.window) |
4140 | 4146 | self.about_dialog.set_modal(True) |
4141 | except: | |
4142 | pass | |
4147 | except Exception as e: | |
4148 | print(e, file=sys.stderr) | |
4143 | 4149 | self.about_dialog.set_name("Mirage") |
4144 | 4150 | self.about_dialog.set_version(__version__) |
4145 | 4151 | self.about_dialog.set_comments(_("A fast GTK+ Image Viewer.")) |
4175 | 4181 | try: |
4176 | 4182 | icon_pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_path) |
4177 | 4183 | self.about_dialog.set_logo(icon_pixbuf) |
4178 | except: | |
4179 | pass | |
4184 | except Exception as e: | |
4185 | print(e, file=sys.stderr) | |
4180 | 4186 | self.about_dialog.connect("response", self.close_about) |
4181 | 4187 | self.about_dialog.show_all() |
4182 | 4188 | |
4572 | 4578 | newpix.fill(0x858585FF) |
4573 | 4579 | pix.copy_area(0, 0, width, height, newpix, 1, 1) |
4574 | 4580 | return newpix |
4575 | except: | |
4581 | except Exception as e: | |
4582 | print(e, file=sys.stderr) | |
4576 | 4583 | return pix |
4577 | 4584 | |
4578 | 4585 | def crop_image(self, action, parameter, data): |
5079 | 5086 | self.imageview.set_from_pixbuf(self.currimg_pixbuf) |
5080 | 5087 | self.currimg_pixbuf = bak.copy() |
5081 | 5088 | del bak |
5082 | except: | |
5083 | pass | |
5089 | except Exception as e: | |
5090 | print(e, file=sys.stderr) | |
5084 | 5091 | gc.collect() |
5085 | 5092 | |
5086 | 5093 | def resize_image(self, action, parameter, data): |
5484 | 5491 | reset_cursor, |
5485 | 5492 | perform_onload_action, |
5486 | 5493 | ) |
5487 | except: | |
5494 | except Exception as e: | |
5495 | print(e, file=sys.stderr) | |
5488 | 5496 | self.image_load_failed(True) |
5489 | 5497 | if preload_next_image_after: |
5490 | 5498 | self.preload_when_idle = GLib.idle_add(self.preload_next_image, False) |
5812 | 5820 | gc.collect() |
5813 | 5821 | if self.verbose: |
5814 | 5822 | print(_("Preloading: %s") % self.preloadimg_next_name) |
5815 | except: | |
5823 | except Exception as e: | |
5824 | print(e, file=sys.stderr) | |
5816 | 5825 | self.preloadimg_next_in_list = -1 |
5817 | 5826 | |
5818 | 5827 | def preload_prev_image(self, use_existing_image): |
5892 | 5901 | gc.collect() |
5893 | 5902 | if self.verbose: |
5894 | 5903 | print(_("Preloading: %s") % self.preloadimg_prev_name) |
5895 | except: | |
5904 | except Exception as e: | |
5905 | print(e, file=sys.stderr) | |
5896 | 5906 | self.preloadimg_prev_in_list = -1 |
5897 | 5907 | |
5898 | 5908 | def change_cursor(self, type): |
5954 | 5964 | socket.setdefaulttimeout(5) |
5955 | 5965 | urllib.request.urlretrieve(inputlist[itemnum], tmpfile) |
5956 | 5966 | inputlist[itemnum] = tmpfile |
5957 | except: | |
5958 | pass | |
5967 | except Exception as e: | |
5968 | print(e, file=sys.stderr) | |
5959 | 5969 | # Remove hidden files from list: |
5960 | 5970 | if not self.open_hidden_files: |
5961 | 5971 | tmplist = [] |
6082 | 6092 | if not self.closing_app: |
6083 | 6093 | while Gtk.events_pending(): |
6084 | 6094 | Gtk.main_iteration() |
6085 | except: | |
6086 | pass | |
6095 | except Exception as e: | |
6096 | print(e, file=sys.stderr) | |
6087 | 6097 | if first_image_came_from_dir: |
6088 | 6098 | self.image_list = [] |
6089 | 6099 | # Pre-load second image: |
6225 | 6235 | uri = "file://" |
6226 | 6236 | uri = uri + urllib.request.pathname2url(os.path.abspath(imgfile)) |
6227 | 6237 | gtk_recent_manager.add_item(uri) |
6228 | except: | |
6238 | except Exception as e: | |
6239 | print(e, file=sys.stderr) | |
6229 | 6240 | # Isnt currently functional on win32 |
6230 | 6241 | if sys.platform == "win32": |
6231 | 6242 | pass |