Ticket #3358: smooth_scrolling_patch.diff
| File smooth_scrolling_patch.diff, 5.7 KB (added by Geobert, 3 years ago) |
|---|
-
src/conversation_textview.py
10 10 ## 11 11 ## This program is distributed in the hope that it will be useful, 12 12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 ## GNU General Public License for more details. 15 15 ## 16 16 17 17 import random 18 18 from tempfile import gettempdir 19 19 from subprocess import Popen 20 from threading import Timer # for smooth scrolling 20 21 21 22 import gtk 22 23 import pango … … 44 45 path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png') 45 46 FOCUS_OUT_LINE_PIXBUF = gtk.gdk.pixbuf_new_from_file(path_to_file) 46 47 48 # smooth scroll constants 49 MAX_SCROLL_TIME = 0.4 # seconds 50 SCROLL_DELAY = 33 # milliseconds 51 47 52 def __init__(self, account, used_in_history_window = False): 48 53 '''if used_in_history_window is True, then we do not show 49 54 Clear menuitem in context menu''' … … 154 159 self.line_tooltip = tooltips.BaseTooltip() 155 160 # use it for hr too 156 161 self.tv.focus_out_line_pixbuf = ConversationTextview.FOCUS_OUT_LINE_PIXBUF 162 self.smooth_id = None 157 163 158 164 def del_handlers(self): 159 165 for i in self.handlers.keys(): … … 181 187 return True 182 188 return False 183 189 190 # Smooth scrolling inspired by Pidgin code 191 def smooth_scroll(self): 192 parent = self.tv.get_parent() 193 if not parent: 194 return False 195 vadj = parent.get_vadjustment() 196 max_val = vadj.upper - vadj.page_size + 1 197 cur_val = vadj.get_value() 198 # scroll by 1/3rd of remaining distance 199 onethird = cur_val + ((max_val - cur_val) / 3.0) 200 vadj.set_value(onethird) 201 if max_val - onethird < 0.01: 202 print "sroll finished" 203 self.smooth_id = None 204 self.smooth_scroll_timer.cancel() 205 return False 206 return True 207 208 def smooth_scroll_timeout(self): 209 print "-->smooth_scroll_timeout" 210 gobject.source_remove(self.smooth_id) 211 self.smooth_id = None 212 parent = self.tv.get_parent() 213 if parent: 214 vadj = parent.get_vadjustment() 215 vadj.set_value(vadj.upper - vadj.page_size + 1) 216 217 def smooth_scroll_to_end(self): 218 if None != self.smooth_id: # already scrolling 219 return False 220 print "-->add timeout" 221 self.smooth_id = gobject.timeout_add(self.SCROLL_DELAY, 222 self.smooth_scroll) 223 self.smooth_scroll_timer = Timer(self.MAX_SCROLL_TIME, 224 self.smooth_scroll_timeout) 225 self.smooth_scroll_timer.start() 226 return False 227 184 228 def scroll_to_end(self): 185 229 parent = self.tv.get_parent() 186 230 buffer = self.tv.get_buffer() … … 192 236 adjustment.set_value(0) 193 237 return False # when called in an idle_add, just do it once 194 238 195 def bring_scroll_to_end(self, diff_y = 0): 239 def bring_scroll_to_end(self, diff_y = 0,\ 240 use_smooth =\ 241 gajim.config.get('use_smooth_scrolling')): 196 242 ''' scrolls to the end of textview if end is not visible ''' 197 243 buffer = self.tv.get_buffer() 198 244 end_iter = buffer.get_end_iter() … … 200 246 visible_rect = self.tv.get_visible_rect() 201 247 # scroll only if expected end is not visible 202 248 if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y): 203 gobject.idle_add(self.scroll_to_end_iter) 249 if use_smooth: 250 gobject.idle_add(self.smooth_scroll_to_end) 251 else: 252 gobject.idle_add(self.scroll_to_end_iter) 204 253 205 254 def scroll_to_end_iter(self): 206 255 buffer = self.tv.get_buffer() … … 857 906 if at_the_end or kind == 'outgoing': 858 907 # we are at the end or we are sending something 859 908 # scroll to the end (via idle in case the scrollbar has appeared) 860 gobject.idle_add(self.scroll_to_end) 909 if gajim.config.get('use_smooth_scrolling'): 910 gobject.idle_add(self.smooth_scroll_to_end) 911 else: 912 gobject.idle_add(self.scroll_to_end) 861 913 862 914 buffer.end_user_action() 863 915 -
src/common/config.py
218 218 'hide_groupchat_occupants_list': [opt_bool, False, _('Hides the group chat occupants list in group chat window.')], 219 219 'chat_merge_consecutive_nickname': [opt_bool, False, _('In a chat, show the nickname at the beginning of a line only when it\'s not the same person talking than in previous message.')], 220 220 'chat_merge_consecutive_nickname_indent': [opt_str, ' ', _('Indentation when using merge consecutive nickname.')], 221 'use_smooth_scrolling': [opt_bool, True, _('Smooth scroll message in conversation window')], 221 222 'gc_nicknames_colors': [ opt_str, '#a34526:#c000ff:#0012ff:#388a99:#045723:#7c7c7c:#ff8a00:#94452d:#244b5a:#32645a', _('List of colors that will be used to color nicknames in group chats.'), True ], 222 223 'ctrl_tab_go_to_next_composing': [opt_bool, True, _('Ctrl-Tab go to next composing tab when none is unread.')], 223 224 'confirm_metacontacts': [ opt_str, '', _('Should we show the confirm metacontacts creation dialog or not? Empty string means we never show the dialog.')], -
src/chat_control.py
812 812 self.msg_scrolledwindow.set_property('vscrollbar-policy', 813 813 gtk.POLICY_NEVER) 814 814 self.msg_scrolledwindow.set_property('height-request', -1) 815 816 self.conv_textview.bring_scroll_to_end(diff_y - 18)815 # put inside "if diff_y != 0"" or it is called at each keystroke 816 self.conv_textview.bring_scroll_to_end(diff_y - 18) 817 817 818 818 # enable scrollbar automatic policy for horizontal scrollbar 819 819 # if message we have in message_textview is too big
