Changeset 2659
- Timestamp:
- 07/31/05 21:21:11 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
dialogs.py (modified) (10 diffs)
-
roster_window.py (modified) (4 diffs)
-
systray.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dialogs.py
r2652 r2659 517 517 [ [ gtk.STOCK_OK, gtk.RESPONSE_OK ] ] 518 518 ) 519 520 class RosterTooltip: 521 def __init__(self, plugin): 522 self.plugin = plugin 523 524 self.image = gtk.Image() 525 self.image.set_alignment(0.5, 0.025) 526 self.account = None 527 self.table = None 528 529 self.current_row = 1 519 class BaseTooltip: 520 ''' Base Tooltip . Usage: 521 tooltip = BaseTooltip() 522 .... 523 tooltip.show_tooltip('', window_postions, widget_postions) 524 .... 525 if tooltip.timeout != 0: 526 tooltip.hide_tooltip() 527 ''' 528 def __init__(self): 530 529 self.timeout = 0 531 530 self.prefered_position = [0, 0] 532 self.path = None 531 self.win = None 532 self.id = None 533 534 def populate(self, data): 535 ''' this method must be overridenby all extenders ''' 533 536 self.create_window() 537 self.win.add(gtk.Label(data)) 534 538 535 539 def create_window(self): 536 540 ''' create a popup window each time tooltip is requested ''' 537 541 self.win = gtk.Window(gtk.WINDOW_POPUP) 542 self.win.set_border_width(3) 538 543 self.win.set_resizable(False) 539 544 self.win.set_name('gtk-tooltips') 540 self.hbox = gtk.HBox() 541 self.hbox.set_border_width(6) 542 self.hbox.set_homogeneous(False) 543 self.win.add(self.hbox) 544 self.hbox.pack_start(self.image, False, False) 545 545 546 546 547 self.win.set_events(gtk.gdk.POINTER_MOTION_MASK) … … 562 563 else: 563 564 self.prefered_position[0] -= half_width 565 screen.get_height() 564 566 if self.prefered_position[1] + requisition.height > screen.get_height(): 565 self.prefered_position[1] -= requisition.height + 25 567 # flip tooltip up 568 self.prefered_position[1] -= requisition.height + self.widget_height + 8 566 569 if self.prefered_position[1] < 0: 567 570 self.prefered_position[1] = 0 … … 581 584 return True 582 585 583 def show_tooltip(self, contact, pointer_position, win_size):584 self.populate( contact)585 new_x = win_size[0] + pointer_position[0]586 new_y = win_size[1] + pointer_position[1] + 35586 def show_tooltip(self, data, widget_pos, win_size): 587 self.populate(data) 588 new_x = win_size[0] + widget_pos[0] 589 new_y = win_size[1] + widget_pos[1] + 4 587 590 self.prefered_position = [new_x, new_y] 591 self.widget_height = widget_pos[1] 588 592 self.win.ensure_style() 589 593 self.win.show_all() … … 593 597 gobject.source_remove(self.timeout) 594 598 self.timeout = 0 595 self.win.destroy() 596 self.path = None 597 598 599 def add_status(self, file_path, resource, priority, show, status): 599 if self.win: 600 self.win.destroy() 601 self.win = None 602 self.id = None 603 604 class StatusTable: 605 ''' Contains methods for creating status table. This 606 is used in Roster and NotificationArea tooltips ''' 607 def __init__(self): 608 self.current_row = 1 609 self.table = None 610 self.text_lable = None 611 612 def create_table(self): 613 self.table = gtk.Table(3, 1) 614 self.table.set_property('column-spacing', 6) 615 self.text_lable = gtk.Label() 616 self.text_lable.set_line_wrap(True) 617 self.text_lable.set_alignment(0, 0) 618 self.text_lable.set_selectable(False) 619 self.table.attach(self.text_lable, 1, 4, 1, 2) 620 621 def get_status_info(self, resource, priority, show, status): 622 str_status = resource + ' ('+str(priority)+')' 623 if status: 624 status = status.strip() 625 if status != '': 626 str_status += ' - ' + status 627 return gtkgui_helpers.escape_for_pango_markup(str_status) 628 629 def add_status_row(self, file_path, show, str_status): 600 630 ''' appends a new row with status icon to the table ''' 601 631 self.current_row += 1 … … 606 636 image = gtk.Image() 607 637 image.set_from_pixbuf(None) 608 spacer = gtk.Label(' ')638 spacer = gtk.Label(' ') 609 639 for file in files: 610 640 if os.path.exists(file): … … 617 647 self.current_row + 1, 0, 0, 3, 0) 618 648 image.set_alignment(0.01, 1) 619 str_status = resource + ' ('+str(priority)+')' 620 if status: 621 status = status.strip() 622 if status != '': 623 str_status += ' - ' + status 624 status_label = gtk.Label(str_status) 649 status_label = gtk.Label() 650 status_label.set_markup(str_status) 625 651 status_label.set_alignment(00, 0) 626 652 self.table.attach(status_label, 3, 4, self.current_row, 627 653 self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0) 654 655 class NotificationAreaTooltip(BaseTooltip, StatusTable): 656 ''' Tooltip that is shown in the notification area ''' 657 def __init__(self, plugin): 658 self.plugin = plugin 659 BaseTooltip.__init__(self) 660 StatusTable.__init__(self) 661 662 663 def populate(self, data): 664 self.create_window() 665 self.create_table() 666 self.hbox = gtk.HBox() 667 self.table.set_property('column-spacing', 1) 668 text, single_line, accounts = '', '', [] 669 if gajim.contacts: 670 for account in gajim.contacts.keys(): 671 status_idx = gajim.connections[account].connected 672 # uncomment the following to hide offline accounts 673 # if status_idx == 0: continue 674 from common.connection import STATUS_LIST 675 status = STATUS_LIST[status_idx] 676 message = gajim.connections[account].status 677 single_line = helpers.get_uf_show(status) 678 if message is None: 679 message = '' 680 else: 681 message = message.strip() 682 if message != '': 683 single_line += ': ' + message 684 else: 685 message = helpers.get_uf_show(status) 686 687 accounts.append({'name':account, 'status_line':single_line, 688 'show':status, 'message':message}) 689 unread_messages_no = self.plugin.roster.nb_unread 690 if unread_messages_no > 1: 691 text = _('Gajim - %s unread messages') % unread_messages_no 692 elif unread_messages_no == 1: 693 text = _('Gajim - 1 unread message') 694 elif len(accounts) > 1: 695 text = _('Gajim') 696 self.current_row = 1 697 self.table.resize(2,1) 698 iconset = gajim.config.get('iconset') 699 if not iconset: 700 iconset = 'sun' 701 file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16') 702 for acct in accounts: 703 self.add_status_row(file_path, acct['show'], '<span weight="bold">' + 704 gtkgui_helpers.escape_for_pango_markup(acct['name']) + '</span>' 705 + ' - ' + gtkgui_helpers.escape_for_pango_markup(acct['message'])) 706 707 elif len(accounts) == 1: 708 text = _('Gajim - %s') % accounts[0]['status_line'] 709 else: 710 text = _('Gajim - %s') % helpers.get_uf_show('offline') 711 self.text_lable.set_markup(text) 712 self.hbox.add(self.table) 713 self.win.add(self.hbox) 714 715 class RosterTooltip(BaseTooltip, StatusTable): 716 ''' Tooltip that is shown in the roster treeview ''' 717 def __init__(self, plugin): 718 self.account = None 719 self.plugin = plugin 720 721 self.image = gtk.Image() 722 self.image.set_alignment(0.5, 0.025) 723 BaseTooltip.__init__(self) 724 StatusTable.__init__(self) 628 725 629 726 def populate(self, contacts): … … 631 728 return 632 729 self.create_window() 633 self.table = gtk.Table(3, 1) 634 self.table.set_property('column-spacing', 6) 635 self.account = gtk.Label() 636 self.account.set_line_wrap(True) 637 self.account.set_alignment(0, 0) 638 self.account.set_selectable(False) 639 self.table.attach(self.account, 1, 4, 1, 2) 640 self.hbox.pack_start(self.table, True, True) 641 # default resource of the contact 730 self.hbox = gtk.HBox() 731 #~ self.hbox.set_border_width(6) 732 self.hbox.set_homogeneous(False) 733 self.create_table() 642 734 prim_contact = None # primary contact 643 735 for contact in contacts: … … 666 758 self.image.set_from_file(file) 667 759 break 668 760 669 761 info = '<span size="large" weight="bold">' + prim_contact.jid + '</span>' 670 762 info += '\n<span weight="bold">' + _('Name: ') + '</span>' + \ … … 694 786 for contact in contacts: 695 787 if contact.resource: 696 s elf.add_status(file_path,contact.resource, contact.priority,788 status_line = self.get_status_info(contact.resource, contact.priority, 697 789 contact.show, contact.status) 790 self.add_status_row(file_path, contact.show, status_line) 698 791 699 792 else: # only one resource … … 711 804 info += ' - ' + gtkgui_helpers.escape_for_pango_markup(status) 712 805 713 self.account.set_markup(info) 806 self.text_lable.set_markup(info) 807 self.hbox.pack_start(self.image, False, False) 808 self.hbox.pack_start(self.table, True, True) 809 self.win.add(self.hbox) 714 810 715 811 class InputDialog: -
trunk/src/roster_window.py
r2657 r2659 643 643 pointer = self.tree.get_pointer() 644 644 props = self.tree.get_path_at_pos(pointer[0], pointer[1]) 645 if props and self.tooltip. path== props[0]:645 if props and self.tooltip.id == props[0]: 646 646 # check if the current pointer is at the same path 647 647 # as it was before setting the timeout 648 self.tooltip.show_tooltip(contact, self.window.get_pointer(), 649 self.window.get_position()) 648 rect = self.tree.get_cell_area(props[0],props[1]) 649 position = self.tree.window.get_origin() 650 pointer = self.window.get_pointer() 651 self.tooltip.show_tooltip(contact, (pointer[0], rect.height ), 652 (position[0], position[1] + rect.y)) 650 653 else: 651 654 self.tooltip.hide_tooltip() … … 655 658 props = widget.get_path_at_pos(int(event.x), int(event.y)) 656 659 if self.tooltip.timeout > 0: 657 if not props or self.tooltip. path== props[0]:660 if not props or self.tooltip.id == props[0]: 658 661 self.tooltip.hide_tooltip() 659 662 … … 662 665 props = widget.get_path_at_pos(int(event.x), int(event.y)) 663 666 if self.tooltip.timeout > 0: 664 if not props or self.tooltip. path!= props[0]:667 if not props or self.tooltip.id != props[0]: 665 668 self.tooltip.hide_tooltip() 666 669 if props: … … 671 674 jid = model[iter][3] 672 675 img = model[iter][0] 673 if self.tooltip.timeout == 0 or self.tooltip. path!= props[0]:674 self.tooltip. path= row676 if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: 677 self.tooltip.id = row 675 678 self.tooltip.timeout = gobject.timeout_add(500, 676 679 self.show_tooltip, gajim.contacts[account][jid]) -
trunk/src/systray.py
r2636 r2659 5 5 ## - Vincent Hanquez <tab@snarc.org> 6 6 ## - Nikos Kouremenos <kourem@gmail.com> 7 ## - Dimitur Kirov <dkirov@gmail.com> 7 8 ## 8 9 ## Copyright (C) 2003-2005 Gajim Team … … 20 21 import gtk 21 22 import gtk.glade 23 import gobject 22 24 import dialogs 23 25 import os … … 51 53 self.new_message_handler_id = None 52 54 self.t = None 53 self.tip = gtk.Tooltips()55 #~ self.tip = gtk.Tooltips() 54 56 self.img_tray = gtk.Image() 55 57 self.status = 'offline' … … 133 135 self.status = global_status 134 136 self.set_img() 135 self.tip.set_tip(self.t, text)137 #~ self.tip.set_tip(self.t, text) 136 138 137 139 def start_chat(self, widget, account, jid): … … 271 273 def on_clicked(self, widget, event): 272 274 # hide the tooltip 273 self.tip.disable()274 self.tip.enable()275 #~ self.tip.disable() 276 #~ self.tip.enable() 275 277 win = self.plugin.roster.window 276 278 if event.button == 1: # Left click … … 311 313 index = l.index(show) 312 314 self.plugin.roster.status_combobox.set_active(index) 313 315 316 def show_tooltip(self, widget): 317 position = widget.window.get_origin() 318 if self.tooltip.id == position: 319 size = widget.window.get_size() 320 self.tooltip.show_tooltip('', 321 (widget.window.get_pointer()[0], size[1]), position) 322 323 def on_tray_motion_notify_event(self, widget, event): 324 wireq=widget.size_request() 325 position = widget.window.get_origin() 326 if self.tooltip.timeout > 0: 327 if self.tooltip.id != position: 328 self.tooltip.hide_tooltip() 329 if self.tooltip.timeout == 0 and \ 330 self.tooltip.id != position: 331 self.tooltip.id = position 332 self.tooltip.timeout = gobject.timeout_add(500, 333 self.show_tooltip, widget) 334 335 def on_tray_leave_notify_event(self, widget, event): 336 position = widget.window.get_origin() 337 if self.tooltip.timeout > 0 and \ 338 self.tooltip.id == position: 339 self.tooltip.hide_tooltip() 340 314 341 def show_icon(self): 315 342 if not self.t: … … 318 345 # avoid draw seperate bg color in some gtk themes 319 346 eb.set_visible_window(False) 347 eb.set_events(gtk.gdk.POINTER_MOTION_MASK) 320 348 eb.connect('button-press-event', self.on_clicked) 321 self.set_tooltip() 349 eb.connect('motion-notify-event', self.on_tray_motion_notify_event) 350 eb.connect('leave-notify-event', self.on_tray_leave_notify_event) 351 self.tooltip = dialogs.NotificationAreaTooltip(self.plugin) 352 #~ self.set_tooltip() 322 353 self.img_tray = gtk.Image() 323 354 eb.add(self.img_tray) … … 327 358 328 359 def set_tooltip(self, unread_messages_no=None): 329 # we look for the number of unread messages330 # and we set the appropriate tooltip331 360 if unread_messages_no > 1: 332 361 text = _('Gajim - %s unread messages') % unread_messages_no 333 self.tip.set_tip(self.t, text)334 362 elif unread_messages_no == 1: 335 363 text = _('Gajim - 1 unread message') 336 self.tip.set_tip(self.t, text)337 364 else: # it's None or 0 338 365 self.change_status()
