Skip to content

Commit c918bd7

Browse files
committed
autopep8 formatting
1 parent 28e3d50 commit c918bd7

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

mujoco_viewer/mujoco_viewer.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def _cursor_pos_callback(self, window, xpos, ypos):
173173
self._last_mouse_y = int(self._scale * ypos)
174174

175175
def _mouse_button_callback(self, window, button, act, mods):
176-
self._button_left_pressed = button==glfw.MOUSE_BUTTON_LEFT and act==glfw.PRESS
177-
self._button_right_pressed = button==glfw.MOUSE_BUTTON_RIGHT and act==glfw.PRESS
176+
self._button_left_pressed = button == glfw.MOUSE_BUTTON_LEFT and act == glfw.PRESS
177+
self._button_right_pressed = button == glfw.MOUSE_BUTTON_RIGHT and act == glfw.PRESS
178178

179179
x, y = glfw.get_cursor_pos(window)
180180
self._last_mouse_x = int(self._scale * x)
@@ -190,7 +190,7 @@ def _mouse_button_callback(self, window, button, act, mods):
190190
self._last_left_click_time = glfw.get_time()
191191

192192
time_diff = (time_now - self._last_left_click_time)
193-
if time_diff>0.01 and time_diff < 0.3:
193+
if time_diff > 0.01 and time_diff < 0.3:
194194
self._left_double_click_pressed = True
195195
self._last_left_click_time = time_now
196196

@@ -199,12 +199,12 @@ def _mouse_button_callback(self, window, button, act, mods):
199199
self._last_right_click_time = glfw.get_time()
200200

201201
time_diff = (time_now - self._last_right_click_time)
202-
if time_diff>0.01 and time_diff < 0.2:
202+
if time_diff > 0.01 and time_diff < 0.2:
203203
self._right_double_click_pressed = True
204204
self._last_right_click_time = time_now
205205

206206
# set perturbation
207-
key = mods==glfw.MOD_CONTROL
207+
key = mods == glfw.MOD_CONTROL
208208
newperturb = 0
209209
if key and self.pert.select > 0:
210210
# right: translate, left: rotate
@@ -215,7 +215,8 @@ def _mouse_button_callback(self, window, button, act, mods):
215215

216216
# perturbation onste: reset reference
217217
if newperturb and not self.pert.active:
218-
mujoco.mjv_initPerturb(self.model, self.data, self.scn, self.pert)
218+
mujoco.mjv_initPerturb(
219+
self.model, self.data, self.scn, self.pert)
219220
self.pert.active = newperturb
220221

221222
# handle doubleclick
@@ -231,42 +232,53 @@ def _mouse_button_callback(self, window, button, act, mods):
231232

232233
# find geom and 3D click point, get corresponding body
233234
width, height = self.viewport.width, self.viewport.height
234-
aspectratio = width/height
235-
relx = x/width
236-
rely = (self.viewport.height - y)/height
235+
aspectratio = width / height
236+
relx = x / width
237+
rely = (self.viewport.height - y) / height
237238
selpnt = np.zeros((3, 1), dtype=np.float64)
238239
selgeom = np.zeros((1, 1), dtype=np.int32)
239240
selskin = np.zeros((1, 1), dtype=np.int32)
240-
selbody = mujoco.mjv_select(self.model, self.data, self.vopt, aspectratio, relx, rely, self.scn, selpnt, selgeom, selskin)
241+
selbody = mujoco.mjv_select(
242+
self.model,
243+
self.data,
244+
self.vopt,
245+
aspectratio,
246+
relx,
247+
rely,
248+
self.scn,
249+
selpnt,
250+
selgeom,
251+
selskin)
241252

242253
# set lookat point, start tracking is requested
243-
if selmode==2 or selmode==3:
254+
if selmode == 2 or selmode == 3:
244255
# set cam lookat
245-
if selbody>=0:
256+
if selbody >= 0:
246257
self.cam.lookat = selpnt.flatten()
247258
# switch to tracking camera if dynamic body clicked
248-
if selmode==3 and selbody>0:
259+
if selmode == 3 and selbody > 0:
249260
self.cam.type = mujoco.mjtCamera.mjCAMERA_TRACKING
250261
self.cam.trackbodyid = selbody
251262
self.cam.fixedcamid = -1
252263
# set body selection
253264
else:
254-
if selbody>=0:
265+
if selbody >= 0:
255266
# record selection
256267
self.pert.select = selbody
257268
self.pert.skinselect = selskin
258269
# compute localpos
259270
vec = selpnt.flatten() - self.data.xpos[selbody]
260271
mat = self.data.xmat[selbody].reshape(3, 3)
261-
self.pert.localpos = self.data.xmat[selbody].reshape(3, 3).dot(vec)
272+
self.pert.localpos = self.data.xmat[selbody].reshape(
273+
3, 3).dot(vec)
262274
else:
263275
self.pert.select = 0
264276
self.pert.skinselect = -1
265277
# stop perturbation on select
266278
self.pert.active = 0
267279

268280
# 3D release
269-
if act==glfw.RELEASE:
281+
if act == glfw.RELEASE:
270282
self.pert.active = 0
271283

272284
def _scroll_callback(self, window, x_offset, y_offset):

0 commit comments

Comments
 (0)