=== modified file 'terminatorlib/terminator.py' --- terminatorlib/terminator.py 2009-09-26 10:33:17 +0000 +++ terminatorlib/terminator.py 2009-10-09 15:05:21 +0000 @@ -973,168 +973,224 @@ # print "sending %d" % (best_index) return best_index + def _match_down (self, current_geo, possible_geo, best_geo): + '''Find the terminal which is closest in a line down from the terminal's centre''' + + horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height + if self.term_list[0].is_scrollbar_present(): + verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0].get_parent().style_get_property('scroll-arrow-vlength') + else: + verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + + # Indentify the size of the horizontal and scroll bars and then add these to the size of individual terminals + local_possible_geo = {} + local_possible_geo['offset_x'] = possible_geo['offset_x'] - verticalBar + local_possible_geo['span_x'] = possible_geo['span_x'] + verticalBar + local_possible_geo['offset_y'] = possible_geo['offset_y'] - horizontalBar + local_possible_geo['span_y'] = possible_geo['span_y'] + horizontalBar + + local_current_geo = {} + local_current_geo['offset_x'] = current_geo['offset_x'] - verticalBar + local_current_geo['span_x'] = current_geo['span_x'] + verticalBar + local_current_geo['offset_y'] = current_geo['offset_y'] - horizontalBar + local_current_geo['span_y'] = current_geo['span_y'] + horizontalBar + + if(best_geo != None): + local_best_geo = {} + local_best_geo['offset_x'] = best_geo['offset_x'] - verticalBar + local_best_geo['span_x'] = best_geo['span_x'] + verticalBar + local_best_geo['offset_y'] = best_geo['offset_y'] - horizontalBar + local_best_geo['span_y'] = best_geo['span_y'] + horizontalBar + + # Find the centre of the current geometry + cursor = { 'x' : local_current_geo['offset_x'] + (local_current_geo['span_x'] / 2), 'y' : local_current_geo['offset_y'] + (current_geo['span_y'] / 2) } + + # If the target terminal to the left of the cursor then ignore it + if(cursor['x'] > (local_possible_geo['offset_x']+local_possible_geo['span_x'])): + return False + + # If the target terminal to the right the cursor then ignore it + if(cursor['x'] < (local_possible_geo['offset_x'])): + return False + + # If the target terminal is above the cursor then ignore it + if(cursor['y'] > (local_possible_geo['offset_y']+local_possible_geo['span_y'])): + return False + + # So this is A terminal to the left, if there are no other candidates select it + if(best_geo == None): + return True + + # If this terminal is close to the cursor than the other one use it + if((local_possible_geo['offset_y']) < (local_best_geo['offset_y'])): + return True + + # If all else fails reject the terminal + return False + def _match_up (self, current_geo, possible_geo, best_geo): - '''We want to find terminals that are fully above the top - border, but closest in the y direction, breaking ties via - the closest cursor x position.''' - #print "matching up..." - # top edge of the current terminal - edge = current_geo['origin_y'] - # botoom edge of the possible target - new_edge = possible_geo['origin_y']+possible_geo['span_y'] - - # Width of the horizontal bar that splits terminals - horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height - # Vertical distance between two terminals - distance = current_geo['offset_y'] - (possible_geo['offset_y'] + possible_geo['span_y']) - if new_edge < edge: - #print "new_edge < edge" - if best_geo is None: - #print "first thing left" - return True - best_edge = best_geo['origin_y']+best_geo['span_y'] - if new_edge > best_edge and distance == horizontalBar: - #print "closer y" - return True - if new_edge == best_edge: - #print "same y" - - cursor = current_geo['origin_x'] + current_geo['cursor_x'] - new_cursor = possible_geo['origin_x'] + possible_geo['cursor_x'] - best_cursor = best_geo['origin_x'] + best_geo['cursor_x'] - - if abs(new_cursor - cursor) < abs(best_cursor - cursor): - #print "closer x" - return True - else: - if distance == horizontalBar: - return True - #print "fail" - return False - - def _match_down (self, current_geo, possible_geo, best_geo): - '''We want to find terminals that are fully below the bottom - border, but closest in the y direction, breaking ties via - the closest cursor x position.''' - #print "matching down..." - # bottom edge of the current terminal - edge = current_geo['origin_y']+current_geo['span_y'] - # top edge of the possible target - new_edge = possible_geo['origin_y'] - #print "edge: %d new_edge: %d" % (edge, new_edge) - - # Width of the horizontal bar that splits terminals - horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height - # Vertical distance between two terminals - distance = possible_geo['offset_y'] - (current_geo['offset_y'] + current_geo['span_y']) - if new_edge > edge: - #print "new_edge > edge" - if best_geo is None: - #print "first thing right" - return True - best_edge = best_geo['origin_y'] - #print "best_edge: %d" % (best_edge) - if new_edge < best_edge and distance == horizontalBar: - #print "closer y" - return True - if new_edge == best_edge: - #print "same y" - - cursor = current_geo['origin_x'] + current_geo['cursor_x'] - new_cursor = possible_geo['origin_x'] + possible_geo['cursor_x'] - best_cursor = best_geo['origin_x'] + best_geo['cursor_x'] - - if abs(new_cursor - cursor) < abs(best_cursor - cursor): - #print "closer x" - return True - else: - if distance == horizontalBar: - return True - #print "fail" + '''Find the terminal which is closest in a line up from the terminal's centre''' + + horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height + if self.term_list[0].is_scrollbar_present(): + verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0].get_parent().style_get_property('scroll-arrow-vlength') + else: + verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + + # Indentify the size of the horizontal and scroll bars and then add these to the size of individual terminals + local_possible_geo = {} + local_possible_geo['offset_x'] = possible_geo['offset_x'] - verticalBar + local_possible_geo['span_x'] = possible_geo['span_x'] + verticalBar + local_possible_geo['offset_y'] = possible_geo['offset_y'] - horizontalBar + local_possible_geo['span_y'] = possible_geo['span_y'] + horizontalBar + + local_current_geo = {} + local_current_geo['offset_x'] = current_geo['offset_x'] - verticalBar + local_current_geo['span_x'] = current_geo['span_x'] + verticalBar + local_current_geo['offset_y'] = current_geo['offset_y'] - horizontalBar + local_current_geo['span_y'] = current_geo['span_y'] + horizontalBar + + if(best_geo != None): + local_best_geo = {} + local_best_geo['offset_x'] = best_geo['offset_x'] - verticalBar + local_best_geo['span_x'] = best_geo['span_x'] + verticalBar + local_best_geo['offset_y'] = best_geo['offset_y'] - horizontalBar + local_best_geo['span_y'] = best_geo['span_y'] + horizontalBar + + + # Find the centre of the current geometry + cursor = { 'x' : local_current_geo['offset_x'] + (local_current_geo['span_x'] / 2), 'y' : local_current_geo['offset_y'] + (current_geo['span_y'] / 2) } + + # If the target terminal to the left of the cursor then ignore it + if(cursor['x'] > local_possible_geo['offset_x']+local_possible_geo['span_x']): + return False + + # If the target terminal to the right the cursor then ignore it + if(cursor['x'] < (local_possible_geo['offset_x'])): + return False + + # If the target terminal is below the cursor then ignore it + if(local_possible_geo['offset_y'] > cursor['y']): + return False + + # So this is A terminal to the left, if there are no other candidates select it + if(best_geo == None): + return True + + # If this terminal is close to the cursor than the other one use it + if(local_possible_geo['offset_y'] > local_best_geo['offset_y']): + return True + + # If all else fails reject the terminal return False def _match_left (self, current_geo, possible_geo, best_geo): - '''We want to find terminals that are fully to the left of - the left-side border, but closest in the x direction, breaking - ties via the closest cursor y position.''' - #print "matching left..." - # left-side edge of the current terminal - edge = current_geo['origin_x'] - # right-side edge of the possible target - new_edge = possible_geo['origin_x']+possible_geo['span_x'] + '''Find the terminal which is closest in a line left from the terminal's centre''' - # Width of the horizontal bar that splits terminals + # Indentify the size of the horizontal and scroll bars and then add these to the size of individual terminals horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height - # Width of the vertical bar that splits terminals if self.term_list[0].is_scrollbar_present(): verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0].get_parent().style_get_property('scroll-arrow-vlength') else: verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') - # Horizontal distance between two terminals - distance = current_geo['offset_x'] - (possible_geo['offset_x'] + possible_geo['span_x']) - if new_edge <= edge: - #print "new_edge(%d) < edge(%d)" % (new_edge, edge) - if best_geo is None: - #print "first thing left" - return True - best_edge = best_geo['origin_x']+best_geo['span_x'] - if new_edge > best_edge and distance == verticalBar: - #print "closer x (new_edge(%d) > best_edge(%d))" % (new_edge, best_edge) - return True - if new_edge == best_edge: - #print "same x" - - cursor = current_geo['origin_y'] + current_geo['cursor_y'] - new_cursor = possible_geo['origin_y'] + possible_geo['cursor_y'] - best_cursor = best_geo['origin_y'] + best_geo['cursor_y'] - - if abs(new_cursor - cursor) < abs(best_cursor - cursor) and distance <> horizontalBar: - #print "closer y" - return True - #print "fail" + + local_possible_geo = {} + local_possible_geo['offset_x'] = possible_geo['offset_x'] - verticalBar + local_possible_geo['span_x'] = possible_geo['span_x'] + verticalBar + local_possible_geo['offset_y'] = possible_geo['offset_y'] - horizontalBar + local_possible_geo['span_y'] = possible_geo['span_y'] + horizontalBar + + local_current_geo = {} + local_current_geo['offset_x'] = current_geo['offset_x'] - verticalBar + local_current_geo['span_x'] = current_geo['span_x'] + verticalBar + local_current_geo['offset_y'] = current_geo['offset_y'] - horizontalBar + local_current_geo['span_y'] = current_geo['span_y'] + horizontalBar + + if(best_geo != None): + local_best_geo = {} + local_best_geo['offset_x'] = best_geo['offset_x'] - verticalBar + local_best_geo['span_x'] = best_geo['span_x'] + verticalBar + local_best_geo['offset_y'] = best_geo['offset_y'] - horizontalBar + local_best_geo['span_y'] = best_geo['span_y'] + horizontalBar + + # Find the centre of the current geometry + cursor = { 'x' : local_current_geo['offset_x'] + (local_current_geo['span_x'] / 2), 'y' : local_current_geo['offset_y'] + (current_geo['span_y'] / 2) } + + # If the target terminal is above the cursor then ignore it + if(cursor['y'] < local_possible_geo['offset_y']): + return False + + # If the target terminal is below the cursor then ignore it + if(cursor['y'] > (local_possible_geo['offset_y'] + local_possible_geo['span_y'])): + return False + + # If the target terminal is to the right of the cursor then ignore it + if(local_possible_geo['offset_x'] > cursor['x']): + return False + + # So this is A terminal to the left, if there are no other candidates select it + if(best_geo == None): + return True + + # If this terminal is close to the cursor than the other one use it + if((local_possible_geo['offset_x']+local_possible_geo['span_x']) > (local_best_geo['offset_x']+local_best_geo['span_x'])): + return True + + # If all else fails reject the terminal return False def _match_right (self, current_geo, possible_geo, best_geo): - '''We want to find terminals that are fully to the right of - the right-side border, but closest in the x direction, breaking - ties via the closest cursor y position.''' - #print "matching right..." - # right-side edge of the current terminal - edge = current_geo['origin_x']+current_geo['span_x'] - # left-side edge of the possible target - new_edge = possible_geo['origin_x'] - #print "edge: %d new_edge: %d" % (edge, new_edge) + '''Find the terminal which is closest in a right from the terminal's centre''' - # Width of the horizontal bar that splits terminals + # Indentify the size of the horizontal and scroll bars and then add these to the size of individual terminals horizontalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0]._titlebox.get_allocation().height - # Width of the vertical bar that splits terminals if self.term_list[0].is_scrollbar_present(): verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') + self.term_list[0].get_parent().style_get_property('scroll-arrow-vlength') else: verticalBar = self.term_list[0].get_parent().style_get_property('handle-size') - # Horizontal distance between two terminals - distance = possible_geo['offset_x'] - (current_geo['offset_x'] + current_geo['span_x']) - if new_edge >= edge: - #print "new_edge > edge" - if best_geo is None: - #print "first thing right" - return True - best_edge = best_geo['origin_x'] - #print "best_edge: %d" % (best_edge) - if new_edge < best_edge and distance == verticalBar: - #print "closer x" - return True - if new_edge == best_edge: - #print "same x" - - cursor = current_geo['origin_y'] + current_geo['cursor_y'] - new_cursor = possible_geo['origin_y'] + possible_geo['cursor_y'] - best_cursor = best_geo['origin_y'] + best_geo['cursor_y'] - - if abs(new_cursor - cursor) < abs(best_cursor - cursor) and distance <> horizontalBar: - #print "closer y" - return True - #print "fail" + + local_possible_geo = {} + local_possible_geo['offset_x'] = possible_geo['offset_x'] - verticalBar + local_possible_geo['span_x'] = possible_geo['span_x'] + verticalBar + local_possible_geo['offset_y'] = possible_geo['offset_y'] - horizontalBar + local_possible_geo['span_y'] = possible_geo['span_y'] + horizontalBar + + local_current_geo = {} + local_current_geo['offset_x'] = current_geo['offset_x'] - verticalBar + local_current_geo['span_x'] = current_geo['span_x'] + verticalBar + local_current_geo['offset_y'] = current_geo['offset_y'] - horizontalBar + local_current_geo['span_y'] = current_geo['span_y'] + horizontalBar + + if(best_geo != None): + local_best_geo = {} + local_best_geo['offset_x'] = best_geo['offset_x'] - verticalBar + local_best_geo['span_x'] = best_geo['span_x'] + verticalBar + local_best_geo['offset_y'] = best_geo['offset_y'] - horizontalBar + local_best_geo['span_y'] = best_geo['span_y'] + horizontalBar + + # Find the centre of the current geometry + cursor = { 'x' : local_current_geo['offset_x'] + (local_current_geo['span_x'] / 2), 'y' : local_current_geo['offset_y'] + (current_geo['span_y'] / 2) } + + # If the target terminal is above the cursor then ignore it + if(cursor['y'] < local_possible_geo['offset_y']): + return False + + # If the target terminal is below the cursor then ignore it + if(cursor['y'] > (local_possible_geo['offset_y'] + local_possible_geo['span_y'])): + return False + + # If the target terminal is to the left of the cursor then ignore it + if(local_possible_geo['offset_x']+local_possible_geo['span_x'] < cursor['x']): + return False + + # So this is A terminal to the right, if there are no other candidates select it + if(best_geo == None): + return True + + # If this terminal is close to the cursor than the other one use it + if(local_possible_geo['offset_x'] < local_best_geo['offset_x']): + return True + return False def _select_up (self, term):