Home | Trees | Indices | Help |
|
---|
|
1 #! /usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 # Copyright (C) 2011 ~ 2012 Deepin, Inc. 5 # 2011 ~ 2012 Wang Yong 6 # 7 # Author: Wang Yong <lazycat.manatee@gmail.com> 8 # Maintainer: Wang Yong <lazycat.manatee@gmail.com> 9 # 10 # This program is free software: you can redistribute it and/or modify 11 # it under the terms of the GNU General Public License as published by 12 # the Free Software Foundation, either version 3 of the License, or 13 # any later version. 14 # 15 # This program is distributed in the hope that it will be useful, 16 # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 # GNU General Public License for more details. 19 # 20 # You should have received a copy of the GNU General Public License 21 # along with this program. If not, see <http://www.gnu.org/licenses/>. 22 23 from cache_pixbuf import CachePixbuf 24 from constant import DEFAULT_FONT_SIZE 25 from draw import draw_vlinear, draw_pixbuf, draw_line, draw_text 26 from keymap import get_keyevent_name 27 from label import Label 28 from theme import ui_theme 29 import gobject 30 import gtk 31 import pango 32 from utils import (get_content_size, color_hex_to_cairo, propagate_expose, set_clickable_cursor, 33 window_is_max, get_same_level_widgets, widget_fix_cycle_destroy_bug, run_command) 34 35 __all__ = ["Button", "ImageButton", "ThemeButton", 36 "MenuButton", "MinButton", "CloseButton", 37 "MaxButton", "ToggleButton", "ActionButton", 38 "CheckButton", "RadioButton", "DisableButton", 39 "LinkButton"] 4042 ''' 43 Button with Deepin UI style. 44 45 @undocumented: key_press_button 46 @undocumented: expose_button 47 ''' 48160 161 gobject.type_register(Button) 16250 ''' 51 Initialize Button class. 52 53 @param label: Button label. 54 @param font_size: Button label font size. 55 ''' 56 gtk.Button.__init__(self) 57 self.font_size = font_size 58 self.min_width = 69 59 self.min_height = 22 60 self.padding_x = 15 61 self.padding_y = 3 62 63 self.set_label(label) 64 65 self.connect("expose-event", self.expose_button) 66 self.connect("key-press-event", self.key_press_button) 67 68 self.keymap = { 69 "Return" : self.clicked}7072 ''' 73 Set label of Button. 74 75 @param label: Button label. 76 @param font_size: Button label font size. 77 ''' 78 self.label = label 79 (self.label_width, self.label_height) = get_content_size(label, self.font_size) 80 self.set_size_request(max(self.label_width + self.padding_x * 2, self.min_width), 81 max(self.label_height + self.padding_y * 2, self.min_height)) 82 83 self.queue_draw()84 95164 ''' 165 ImageButton class. 166 ''' 167186 187 gobject.type_register(ImageButton) 188168 - def __init__(self, 169 normal_dpixbuf, 170 hover_dpixbuf, 171 press_dpixbuf, 172 scale_x=False, 173 content=None):174 ''' 175 Initialize ImageButton class. 176 177 @param normal_dpixbuf: DynamicPixbuf for button normal status. 178 @param hover_dpixbuf: DynamicPixbuf for button hover status. 179 @param press_dpixbuf: DynamicPixbuf for button press status. 180 @param scale_x: Whether scale horticulturally, default is False. 181 @param content: Button label content. 182 ''' 183 gtk.Button.__init__(self) 184 self.cache_pixbuf = CachePixbuf() 185 draw_button(self, self.cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf, scale_x, content)190 ''' 191 ThemeButton class. 192 ''' 193206 207 gobject.type_register(ThemeButton) 208195 ''' 196 Initialize ThemeButton class. 197 ''' 198 gtk.Button.__init__(self) 199 self.cache_pixbuf = CachePixbuf() 200 draw_button( 201 self, 202 self.cache_pixbuf, 203 ui_theme.get_pixbuf("button/window_theme_normal.png"), 204 ui_theme.get_pixbuf("button/window_theme_hover.png"), 205 ui_theme.get_pixbuf("button/window_theme_press.png"))210 ''' 211 MenuButton class. 212 ''' 213226 227 gobject.type_register(MenuButton) 228215 ''' 216 Initialize MenuButton class. 217 ''' 218 gtk.Button.__init__(self) 219 self.cache_pixbuf = CachePixbuf() 220 draw_button( 221 self, 222 self.cache_pixbuf, 223 ui_theme.get_pixbuf("button/window_menu_normal.png"), 224 ui_theme.get_pixbuf("button/window_menu_hover.png"), 225 ui_theme.get_pixbuf("button/window_menu_press.png"))230 ''' 231 MinButton. 232 ''' 233246 247 gobject.type_register(MinButton) 248235 ''' 236 Initialize MinButton class. 237 ''' 238 gtk.Button.__init__(self) 239 self.cache_pixbuf = CachePixbuf() 240 draw_button( 241 self, 242 self.cache_pixbuf, 243 ui_theme.get_pixbuf("button/window_min_normal.png"), 244 ui_theme.get_pixbuf("button/window_min_hover.png"), 245 ui_theme.get_pixbuf("button/window_min_press.png"))250 ''' 251 CloseButton class. 252 ''' 253266 267 gobject.type_register(CloseButton) 268255 ''' 256 Initialize CloseButton class. 257 ''' 258 gtk.Button.__init__(self) 259 self.cache_pixbuf = CachePixbuf() 260 draw_button( 261 self, 262 self.cache_pixbuf, 263 ui_theme.get_pixbuf("button/window_close_normal.png"), 264 ui_theme.get_pixbuf("button/window_close_hover.png"), 265 ui_theme.get_pixbuf("button/window_close_press.png"))270 ''' 271 MaxButton class. 272 ''' 273288 289 gobject.type_register(MaxButton) 290 322 385 405 451274 - def __init__(self, 275 sub_dir="button", 276 max_path_prefix="window_max", 277 unmax_path_prefix="window_unmax"):278 ''' 279 Initialize MaxButton class. 280 281 @param sub_dir: Subdirectory of button images. 282 @param max_path_prefix: Image path prefix for maximise status. 283 @param unmax_path_prefix: Image path prefix for un-maximise status. 284 ''' 285 gtk.Button.__init__(self) 286 self.cache_pixbuf = CachePixbuf() 287 draw_max_button(self, self.cache_pixbuf, sub_dir, max_path_prefix, unmax_path_prefix)453 ''' 454 ToggleButton class. 455 456 @undocumented: press_toggle_button 457 @undocumented: release_toggle_button 458 @undocumented: expose_toggle_button 459 @undocumented: set_inactive_pixbuf_group 460 @undocumented: set_active_pixbuf_group 461 ''' 462529 531 ''' 532 Callback for `button-press-release` signal. 533 534 @param widget: ToggleButton widget. 535 @param event: Button release event. 536 ''' 537 self.button_press_flag = False 538 self.queue_draw() 539 618463 - def __init__(self, 464 inactive_normal_dpixbuf, 465 active_normal_dpixbuf, 466 inactive_hover_dpixbuf=None, 467 active_hover_dpixbuf=None, 468 inactive_press_dpixbuf=None, 469 active_press_dpixbuf=None, 470 inactive_disable_dpixbuf=None, 471 active_disable_dpixbuf=None, 472 button_label=None, 473 padding_x=0):474 ''' 475 Initialize ToggleButton class. 476 477 @param inactive_normal_dpixbuf: DynamicPixbuf for inactive normal status. 478 @param active_normal_dpixbuf: DynamicPixbuf for active normal status. 479 @param inactive_hover_dpixbuf: DynamicPixbuf for inactive hover status, default is None. 480 @param active_hover_dpixbuf: DynamicPixbuf for active hover status, default is None. 481 @param inactive_press_dpixbuf: DynamicPixbuf for inactive press status, default is None. 482 @param active_press_dpixbuf: DynamicPixbuf for active press status, default is None. 483 @param inactive_disable_dpixbuf: DynamicPixbuf for inactive disable status, default is None. 484 @param active_disable_dpixbuf: DynamicPixbuf for active disable status, default is None. 485 @param button_label: Button label, default is None. 486 @param padding_x: Padding x, default is 0. 487 ''' 488 gtk.ToggleButton.__init__(self) 489 font_size = DEFAULT_FONT_SIZE 490 label_dcolor = ui_theme.get_color("button_default_font") 491 self.button_press_flag = False 492 493 self.inactive_pixbuf_group = (inactive_normal_dpixbuf, 494 inactive_hover_dpixbuf, 495 inactive_press_dpixbuf, 496 inactive_disable_dpixbuf) 497 498 self.active_pixbuf_group = (active_normal_dpixbuf, 499 active_hover_dpixbuf, 500 active_press_dpixbuf, 501 active_disable_dpixbuf) 502 503 # Init request size. 504 label_width = 0 505 button_width = inactive_normal_dpixbuf.get_pixbuf().get_width() 506 button_height = inactive_normal_dpixbuf.get_pixbuf().get_height() 507 if button_label: 508 label_width = get_content_size(button_label, font_size)[0] 509 self.set_size_request(button_width + label_width + padding_x * 2, 510 button_height) 511 512 self.connect("button-press-event", self.press_toggle_button) 513 self.connect("button-release-event", self.release_toggle_button) 514 515 # Expose button. 516 self.connect("expose-event", lambda w, e : self.expose_toggle_button( 517 w, e, 518 button_label, padding_x, font_size, label_dcolor))519 521 ''' 522 Callback for `button-press-event` signal. 523 524 @param widget: ToggleButton widget. 525 @param event: Button press event. 526 ''' 527 self.button_press_flag = True 528 self.queue_draw()620 ''' 621 Set inactive pixbuf group. 622 623 @param new_group: Inactive pixbuf group. 624 ''' 625 self.inactive_pixbuf_group = new_group626 628 ''' 629 Set inactive pixbuf group. 630 631 @param new_group: Active pixbuf group. 632 ''' 633 self.active_pixbuf_group = new_group 634636 ''' 637 ActionButton class. 638 639 @undocumented: expose_action_button 640 ''' 641701 702 gobject.type_register(ActionButton) 703643 ''' 644 Initialize for ActionButton class. 645 646 @param actions: Actions for button. 647 @param index: Index default is 0. 648 ''' 649 gtk.Button.__init__(self) 650 self.actions = actions 651 self.index = index 652 653 pixbuf = self.actions[self.index][0][0].get_pixbuf() 654 self.set_size_request(pixbuf.get_width(), pixbuf.get_height()) 655 656 self.connect("expose-event", self.expose_action_button) 657 self.connect("clicked", lambda w: self.update_action_index(w))658660 ''' 661 Update action index of ActionButton. 662 663 @param widget: ActionButton widget. 664 ''' 665 # Call click callback. 666 self.actions[self.index][1](widget) 667 668 # Update index. 669 self.index += 1 670 if self.index >= len(self.actions): 671 self.index = 0 672 673 # Redraw. 674 self.queue_draw()675705 ''' 706 CheckButton class. 707 ''' 708728 729 gobject.type_register(CheckButton) 730710 ''' 711 Initialize CheckButton class. 712 713 @param label_text: Label text. 714 @param padding_x: Horticultural padding value, default is 8. 715 ''' 716 ToggleButton.__init__( 717 self, 718 ui_theme.get_pixbuf("button/check_button_inactive_normal.png"), 719 ui_theme.get_pixbuf("button/check_button_active_normal.png"), 720 ui_theme.get_pixbuf("button/check_button_inactive_hover.png"), 721 ui_theme.get_pixbuf("button/check_button_active_hover.png"), 722 ui_theme.get_pixbuf("button/check_button_inactive_press.png"), 723 ui_theme.get_pixbuf("button/check_button_active_press.png"), 724 ui_theme.get_pixbuf("button/check_button_inactive_disable.png"), 725 ui_theme.get_pixbuf("button/check_button_active_disable.png"), 726 label_text, padding_x 727 )732 ''' 733 RadioButton class. 734 735 @undocumented: click_radio_button 736 ''' 737773 774 gobject.type_register(RadioButton) 775739 ''' 740 Initialize RadioButton class. 741 742 @param label_text: Label text. 743 @param padding_x: Horticultural padding value, default is 8. 744 ''' 745 ToggleButton.__init__( 746 self, 747 ui_theme.get_pixbuf("button/radio_button_inactive_normal.png"), 748 ui_theme.get_pixbuf("button/radio_button_active_normal.png"), 749 ui_theme.get_pixbuf("button/radio_button_inactive_hover.png"), 750 ui_theme.get_pixbuf("button/radio_button_active_hover.png"), 751 ui_theme.get_pixbuf("button/radio_button_inactive_press.png"), 752 ui_theme.get_pixbuf("button/radio_button_active_press.png"), 753 ui_theme.get_pixbuf("button/radio_button_inactive_disable.png"), 754 ui_theme.get_pixbuf("button/radio_button_active_disable.png"), 755 label_text, 756 padding_x 757 ) 758 759 self.switch_lock = False 760 self.connect("clicked", self.click_radio_button)761777 ''' 778 DisableButton class. 779 780 @undocumented: expose_disable_button 781 ''' 782825 826 gobject.type_register(DisableButton) 827784 ''' 785 Initialize DisableButton class. 786 787 @param dpixbufs: DyanmicPixbuf. 788 ''' 789 gtk.Button.__init__(self) 790 pixbuf = dpixbufs[0].get_pixbuf() 791 self.set_size_request(pixbuf.get_width(), pixbuf.get_height()) 792 793 widget_fix_cycle_destroy_bug(self) 794 self.connect("expose-event", lambda w, e: self.expose_disable_button(w, e, dpixbufs))795829 ''' 830 LinkButton click to open browser. 831 ''' 832852 853 gobject.type_register(LinkButton) 854833 - def __init__(self, 834 text, 835 link, 836 enable_gaussian=True, 837 text_color=ui_theme.get_color("link_text")):838 ''' 839 Initialize LinkButton class. 840 841 @param text: Link content. 842 @param link: Link address. 843 @param enable_gaussian: To enable gaussian effect on link, default is True. 844 @param text_color: Link color, just use when option enable_gaussian is False. 845 ''' 846 Label.__init__(self, text, text_color, enable_gaussian=enable_gaussian, text_size=9, 847 gaussian_radious=1, border_radious=0) 848 849 self.connect("button-press-event", lambda w, e: run_command("xdg-open %s" % link)) 850 851 set_clickable_cursor(self)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Aug 8 13:17:38 2012 | http://epydoc.sourceforge.net |