def re_open_window(self): global s2 global s3 global icon_active Window.disable_on_restore = 'N' Window.on_restore() shell.SendKeys( '%' ) #you MUST run this or the SetForegroundWindow code will error!! win32gui.SetForegroundWindow(ButtonsApp.window_id) Window.window_state = 'open' if Window.last_screen_width < Window.original_screen_width or Window.last_screen_height < Window.original_screen_height: icon_active = 'maximize' else: icon_active = 'window' Window.set_system_cursor('arrow') #normal arrow Clock.unschedule(ButtonsApp.re_open_window)
def on_touch_down(self, touch): if touch.button == 'left': #only run all this on a left click.. global touch_down_active global last_mouse_pos_x global last_mouse_pos_y global start_window_height global start_window_width global start_window_top global start_window_left global start_pos_x global start_pos_y global window_resize_feature global icon_active touch_down_active = 'N' window_resize_feature = 'disabled' title_bar_button_clicked = 'N' start_window_height = Window.size[1] start_window_width = Window.size[0] start_window_top = Window.top start_window_left = Window.left start_pos_x = mouse2.position[0] start_pos_y = mouse2.position[1] #//Minimize Button Clicked// if self.ids.s1.collide_point(touch.pos[0], touch.pos[1]): threading.Thread( target=self.disable_window_move_resize).start() Window.last_screen_pos_left = Window.left Window.last_screen_pos_top = Window.top Window.minimize() Window.window_state = 'minimized' title_bar_button_clicked = 'Y' if self.ids.s2.collide_point(touch.pos[0], touch.pos[1]): #//Window Button Clicked// if icon_active == 'window': threading.Thread( target=self.disable_window_move_resize).start() Window.disable_on_restore = 'N' Window.last_screen_width = Window.original_screen_width / 2 Window.last_screen_height = Window.original_screen_height / 2 Window.on_restore() #change the button to a maximize button.. self.ids.s2.size = [25, 20] self.ids.s2.pos = [ int(Window.size[0] - (self.get_screen_width() * .03958333)), int(Window.size[1] - (self.get_screen_height() * .02403846)) ] self.ids.t2.size = [12, 12] self.ids.t2.pos = [ int(Window.size[0] - (self.get_screen_width() * .03645833)), int(Window.size[1] - (self.get_screen_height() * .02115385)) ] self.ids.t2.source = 'maximize_icon_blue.png' touch_down_active = 'N' icon_active = 'maximize' title_bar_button_clicked = 'Y' #//Maximize Button Clicked// elif icon_active == 'maximize': threading.Thread( target=self.disable_window_move_resize).start() Window.disable_on_restore = 'N' #find which monitor the window is currently using window left and top position - look in taskbar included position coordinates i = 0 for row in Window.monitor_data_incl_taskbar: if Window.left >= row[0] and Window.left < row[ 1] and Window.top >= row[ 2] and Window.top < row[3]: break #stop the loop and use i below i = i + 1 #update window position and size Window.last_screen_pos_left = Window.monitor_data_excl_taskbar[ i][0] Window.last_screen_pos_top = Window.monitor_data_excl_taskbar[ i][2] Window.last_screen_width = Window.monitor_data_excl_taskbar[ i][4] Window.last_screen_height = Window.monitor_data_excl_taskbar[ i][5] Window.on_restore() #change the button to a window button.. self.ids.s2.size = [25, 20] self.ids.s2.pos = [ int(Window.size[0] - (self.get_screen_width() * .03854167)), int(Window.size[1] - (self.get_screen_height() * .02403846)) ] self.ids.t2.size = [15, 15] self.ids.t2.pos = [ int(Window.size[0] - (self.get_screen_width() * .03645833)), int(Window.size[1] - (self.get_screen_height() * .02307692)) ] self.ids.t2.source = 'window_icon_blue.png' icon_active = 'window' title_bar_button_clicked = 'Y' #//Close Button Clicked// if self.ids.s3.collide_point( touch.pos[0], touch.pos[1]): #if close button is clicked.. ButtonsApp.mouse_listener_active = 'N' ButtonsApp.click_listener_active = 'N' Window.close() if touch.pos[1] > Window.size[ 1] - 30 and title_bar_button_clicked == 'N': #this will limit dragging of the window to only when the cursor is near the very TOP of the window.. ButtonsApp.window_move_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' else: ButtonsApp.window_move_active = 'N' ButtonsApp.mouse_listener_active2 = 'N' #//Window Resize Feature Activated// if icon_active == 'maximize' and title_bar_button_clicked == 'N': #here is where we determine which window drag feature the user is trying to utilize #//BOTTOM - North to South// if (touch.pos[1] < 7 and touch.pos[0] < Window.size[0] - 7 ) and (touch.pos[1] < 7 and touch.pos[0] > 7): window_resize_feature = 'n_s_b' #north to south arrow for vertical sizing ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//BOTTOM RIGHT - Northwest to Southeast// elif touch.pos[1] < 7 and touch.pos[0] > Window.size[0] - 7: window_resize_feature = 'nw_se_b' #northwest to southeast arrow for diagonal sizing ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//RIGHT SIDE - West to East// elif (touch.pos[1] > 8 and touch.pos[0] > Window.size[0] - 7 ) and (touch.pos[1] < Window.size[1] - 8 and touch.pos[0] > Window.size[0] - 7): window_resize_feature = 'w_e_r' #west to east arrow for horizontal sizing ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//TOP - North to South// elif (touch.pos[1] > Window.size[1] - 7 and touch.pos[0] < Window.size[0] - 7) and ( touch.pos[1] > Window.size[1] - 7 and touch.pos[0] > 7): window_resize_feature = 'n_s_t' ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//TOP RIGHT - Northeast to Southwest// elif touch.pos[1] > Window.size[1] - 7 and touch.pos[ 0] > Window.size[0] - 7: window_resize_feature = 'ne_sw_t' ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//TOP LEFT - Northwest to Southeast// elif touch.pos[1] > Window.size[1] - 7 and touch.pos[0] < 7: window_resize_feature = 'nw_se_t' ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//LEFT SIDE - West to East// elif (touch.pos[1] > 8 and touch.pos[0] < 7) and (touch.pos[1] < Window.size[1] - 8 and touch.pos[0] < 7): window_resize_feature = 'w_e_l' ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//BOTTOM LEFT - Northeast to Southwest// elif touch.pos[1] < 7 and touch.pos[0] < 7: window_resize_feature = 'ne_sw_b' ButtonsApp.window_move_active = 'N' ButtonsApp.window_resize_active = 'Y' ButtonsApp.mouse_listener_active2 = 'Y' #//ANYTHING ELSE// else: window_resize_feature = 'disabled' ButtonsApp.window_resize_active = 'N' touch_down_active = 'Y' return super(ButtonsApp, self).on_touch_down(touch)