13 from PyQt6.QtSvgWidgets import QSvgWidget |
13 from PyQt6.QtSvgWidgets import QSvgWidget |
14 from PyQt6.QtWidgets import QMenu, QScrollArea, QSizePolicy, QToolBar |
14 from PyQt6.QtWidgets import QMenu, QScrollArea, QSizePolicy, QToolBar |
15 |
15 |
16 from eric7 import Preferences |
16 from eric7 import Preferences |
17 from eric7.EricGui import EricPixmapCache |
17 from eric7.EricGui import EricPixmapCache |
|
18 from eric7.EricWidgets import EricMessageBox |
|
19 from eric7.EricWidgets.EricApplication import ericApp |
18 from eric7.EricWidgets.EricMainWindow import EricMainWindow |
20 from eric7.EricWidgets.EricMainWindow import EricMainWindow |
19 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget |
21 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget |
|
22 from eric7.SystemUtilities import FileSystemUtilities |
20 |
23 |
21 |
24 |
22 class SvgDiagram(EricMainWindow): |
25 class SvgDiagram(EricMainWindow): |
23 """ |
26 """ |
24 Class implementing a dialog showing a SVG graphic. |
27 Class implementing a dialog showing a SVG graphic. |
100 |
103 |
101 # polish up the dialog |
104 # polish up the dialog |
102 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) |
105 self.resize(QSize(800, 600).expandedTo(self.minimumSizeHint())) |
103 |
106 |
104 self.zoom = 1.0 |
107 self.zoom = 1.0 |
105 self.svgFile = svgFile |
108 self.__loadSvgFile(svgFile) |
106 self.svgWidget.load(self.svgFile) |
|
107 self.svgWidget.resize(self.svgWidget.renderer().defaultSize()) |
109 self.svgWidget.resize(self.svgWidget.renderer().defaultSize()) |
108 |
110 |
109 self.__initActions() |
111 self.__initActions() |
110 self.__initContextMenu() |
112 self.__initContextMenu() |
111 self.__initToolBars() |
113 self.__initToolBars() |
112 |
114 |
113 self.grabGesture(Qt.GestureType.PinchGesture) |
115 self.grabGesture(Qt.GestureType.PinchGesture) |
|
116 |
|
117 def __loadSvgFile(self, svgFile): |
|
118 """ |
|
119 Private method to load a given SVG file. |
|
120 |
|
121 @param svgFile file path of the SVG file |
|
122 @type str |
|
123 """ |
|
124 self.svgFile = svgFile |
|
125 if FileSystemUtilities.isRemoteFileName(svgFile): |
|
126 try: |
|
127 data = ( |
|
128 ericApp() |
|
129 .getObject("EricServer") |
|
130 .getServiceInterface("FileSystem") |
|
131 .readFile(svgFile) |
|
132 ) |
|
133 self.svgWidget.load(data) |
|
134 except OSError as err: |
|
135 EricMessageBox.warning( |
|
136 self, |
|
137 self.tr("SVG-Viewer"), |
|
138 self.tr( |
|
139 "<p>The SVG file <b>{0}</b> could not be loaded.</p>" |
|
140 "<p>Reason: {1}</p>" |
|
141 ).format(svgFile, str(err)), |
|
142 ) |
|
143 |
|
144 else: |
|
145 self.svgWidget.load(self.svgFile) |
114 |
146 |
115 def __initActions(self): |
147 def __initActions(self): |
116 """ |
148 """ |
117 Private method to initialize the view actions. |
149 Private method to initialize the view actions. |
118 """ |
150 """ |