Skip to content
Permalink
Browse files

cleaning

  • Loading branch information...
iperov committed Apr 30, 2019
1 parent efb22ec commit 1f1f94848bfcffb59bf8a228e98391f7fcdc43a7
Showing with 24 additions and 23 deletions.
  1. +24 −23 interact/interact.py
@@ -1,8 +1,9 @@
import multiprocessing
import os
import sys
import time
import types
import multiprocessing

import cv2
from tqdm import tqdm

@@ -21,7 +22,7 @@ class InteractBase(object):
EVENT_MBUTTONDOWN = 3
EVENT_MBUTTONUP = 4
EVENT_RBUTTONDOWN = 5
EVENT_RBUTTONUP = 6
EVENT_RBUTTONUP = 6
EVENT_MOUSEWHEEL = 10

def __init__(self):
@@ -35,7 +36,7 @@ def __init__(self):

def is_support_windows(self):
return False

def is_colab(self):
return False

@@ -44,10 +45,10 @@ def on_destroy_all_windows(self):

def on_create_window (self, wnd_name):
raise NotImplemented

def on_destroy_window (self, wnd_name):
raise NotImplemented

def on_show_image (self, wnd_name, img):
raise NotImplemented

@@ -77,35 +78,35 @@ def named_window(self, wnd_name):
else: print("named_window: ", wnd_name, " already created.")

def destroy_all_windows(self):
if len( self.named_windows ) != 0:
self.on_destroy_all_windows()
if len( self.named_windows ) != 0:
self.on_destroy_all_windows()
self.named_windows = {}
self.capture_mouse_windows = {}
self.capture_keys_windows = {}
self.mouse_events = {}
self.key_events = {}
self.focus_wnd_name = None

def destroy_window(self, wnd_name):
if wnd_name in self.named_windows:
self.on_destroy_window(wnd_name)
self.named_windows.pop(wnd_name)
if wnd_name == self.focus_wnd_name:

if wnd_name == self.focus_wnd_name:
self.focus_wnd_name = list(self.named_windows.keys())[-1] if len( self.named_windows ) != 0 else None

if wnd_name in self.capture_mouse_windows:
self.capture_mouse_windows.pop(wnd_name)

if wnd_name in self.capture_keys_windows:
self.capture_keys_windows.pop(wnd_name)

if wnd_name in self.mouse_events:
self.mouse_events.pop(wnd_name)

if wnd_name in self.key_events:
self.key_events.pop(wnd_name)

def show_image(self, wnd_name, img):
if wnd_name in self.named_windows:
if self.named_windows[wnd_name] == 0:
@@ -277,16 +278,16 @@ def input_in_time (self, str, max_time_sec):


class InteractDesktop(InteractBase):

def is_support_windows(self):
return True

def on_destroy_all_windows(self):
cv2.destroyAllWindows()

def on_create_window (self, wnd_name):
cv2.namedWindow(wnd_name)

def on_destroy_window (self, wnd_name):
cv2.destroyWindow(wnd_name)

@@ -295,7 +296,7 @@ def on_show_image (self, wnd_name, img):

def on_capture_mouse (self, wnd_name):
self.last_xy = (0,0)

def onMouse(event, x, y, flags, param):
(inst, wnd_name) = param
if event == cv2.EVENT_LBUTTONDOWN: ev = InteractBase.EVENT_LBUTTONDOWN
@@ -304,11 +305,11 @@ def onMouse(event, x, y, flags, param):
elif event == cv2.EVENT_RBUTTONUP: ev = InteractBase.EVENT_RBUTTONUP
elif event == cv2.EVENT_MBUTTONDOWN: ev = InteractBase.EVENT_MBUTTONDOWN
elif event == cv2.EVENT_MBUTTONUP: ev = InteractBase.EVENT_MBUTTONUP
elif event == cv2.EVENT_MOUSEWHEEL:
elif event == cv2.EVENT_MOUSEWHEEL:
ev = InteractBase.EVENT_MOUSEWHEEL
x,y = self.last_xy #fix opencv bug when window size more than screen size
else: ev = 0

self.last_xy = (x,y)
inst.add_mouse_event (wnd_name, x, y, ev, flags)
cv2.setMouseCallback(wnd_name, onMouse, (self,wnd_name) )
@@ -349,7 +350,7 @@ class InteractColab(InteractBase):

def is_support_windows(self):
return False

def is_colab(self):
return True

@@ -360,7 +361,7 @@ def on_destroy_all_windows(self):
def on_create_window (self, wnd_name):
pass
#clear_output()

def on_destroy_window (self, wnd_name):
pass

0 comments on commit 1f1f948

Please sign in to comment.
You can’t perform that action at this time.