1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
|
"""
@package gui_core.wrap
@brief Core wrapped wxpython widgets
Classes:
- wrap::GSpinCtrl
(C) 2016 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Anna Petrasova <kratochanna gmail.com>
"""
import sys
import wx
import wx.lib.agw.floatspin as fs
import wx.lib.colourselect as csel
import wx.lib.filebrowsebutton as filebrowse
import wx.lib.scrolledpanel as scrolled
from wx.lib import expando
from wx.lib import buttons
from wx.lib.agw.aui import tabart
try:
import wx.lib.agw.customtreectrl as CT
except ImportError:
import wx.lib.customtreectrl as CT
from core.globalvar import CheckWxVersion, gtk3, wxPythonPhoenix
if wxPythonPhoenix:
import wx.adv
from wx.adv import OwnerDrawnComboBox as OwnerDrawnComboBox_
from wx.adv import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
from wx.adv import BitmapComboBox as BitmapComboBox_
from wx.adv import HyperlinkCtrl as HyperlinkCtrl_
from wx.adv import HL_ALIGN_LEFT, HL_CONTEXTMENU
ComboPopup = wx.ComboPopup
wxComboCtrl = wx.ComboCtrl
else:
import wx.combo
from wx.combo import OwnerDrawnComboBox as OwnerDrawnComboBox_
from wx.combo import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
from wx.combo import BitmapComboBox as BitmapComboBox_
from wx import HyperlinkCtrl as HyperlinkCtrl_
from wx import HL_ALIGN_LEFT, HL_CONTEXTMENU
ComboPopup = wx.combo.ComboPopup
wxComboCtrl = wx.combo.ComboCtrl
if wxPythonPhoenix and CheckWxVersion([4, 0, 3, 0]):
from wx import NewIdRef as NewId
else:
from wx import NewId # noqa: F401
def convertToInt(argsOrKwargs, roundVal=False):
"""Convert args, kwargs float value to int
:param tuple/list/dict argsOrKwargs: args or kwargs
:param bool roundVal: True if you want round float value
return list or dict
"""
result = {} if isinstance(argsOrKwargs, dict) else []
j = None
for i in argsOrKwargs:
if isinstance(result, dict):
i, j = argsOrKwargs[i], i
if isinstance(i, float):
if roundVal:
i = round(i)
i = int(i)
result.update({j: i}) if j else result.append(i)
return result
def IsDark():
"""Detects if used theme is dark.
Wraps wx method for different versions."""
def luminance(c):
return (0.299 * c.Red() + 0.587 * c.Green() + 0.114 * c.Blue()) / 255
if hasattr(wx.SystemSettings, "GetAppearance"):
return wx.SystemSettings.GetAppearance().IsDark()
# for older wx
bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
return luminance(fg) - luminance(bg) > 0.2
def BitmapFromImage(image, depth=-1):
if wxPythonPhoenix:
return wx.Bitmap(img=image, depth=depth)
else:
return wx.BitmapFromImage(image, depth=depth)
def ImageFromBitmap(bitmap):
if wxPythonPhoenix:
return bitmap.ConvertToImage()
else:
return wx.ImageFromBitmap(bitmap)
def EmptyBitmap(width, height, depth=-1):
if wxPythonPhoenix:
return wx.Bitmap(width=width, height=height, depth=depth)
else:
return wx.EmptyBitmap(width=width, height=height, depth=depth)
def EmptyImage(width, height, clear=True):
if wxPythonPhoenix:
return wx.Image(width=width, height=height, clear=clear)
else:
return wx.EmptyImage(width=width, height=height, clear=clear)
def StockCursor(cursorId):
if wxPythonPhoenix:
return wx.Cursor(cursorId=cursorId)
else:
return wx.StockCursor(cursorId)
class Window(wx.Window):
"""Wrapper around wx.Window to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Window.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
if tip is None:
wx.Window.UnsetToolTip(self)
else:
wx.Window.SetToolTip(self, tipString=tip)
else:
if tip is None:
wx.Window.SetToolTip(self, tip)
else:
wx.Window.SetToolTipString(self, tip)
class Panel(wx.Panel):
"""Wrapper around wx.Panel to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.Panel.SetToolTip(self, tipString=tip)
else:
wx.Panel.SetToolTipString(self, tip)
class Slider(wx.Slider):
"""Wrapper around wx.Slider to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args)
kwargs = convertToInt(argsOrKwargs=kwargs)
wx.Slider.__init__(self, *args, **kwargs)
def SetRange(self, minValue, maxValue):
wx.Slider.SetRange(self, int(minValue), int(maxValue))
def SetValue(self, value):
wx.Slider.SetValue(self, int(value))
class SpinCtrl(wx.SpinCtrl):
"""Wrapper around wx.SpinCtrl to have more control
over the widget on different platforms"""
gtk3MinSize = 118 # optimal for SpinCtrl default param min=1, max=100
def __init__(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args)
kwargs = convertToInt(argsOrKwargs=kwargs)
if gtk3 and "size" in kwargs and kwargs["size"][0] < self.gtk3MinSize:
del kwargs["size"]
wx.SpinCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.SpinCtrl.SetToolTip(self, tipString=tip)
else:
wx.SpinCtrl.SetToolTipString(self, tip)
def SetRange(self, minVal, maxVal):
wx.SpinCtrl.SetRange(self, int(minVal), int(maxVal))
def SetValue(self, value):
wx.SpinCtrl.SetValue(self, int(value))
class FloatSpin(fs.FloatSpin):
"""Wrapper around fs.FloatSpin to have more control
over the widget on different platforms"""
gtk3MinSize = 130
def __init__(self, *args, **kwargs):
if gtk3:
if "size" in kwargs:
kwargs["size"] = wx.Size(
max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
)
else:
kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
fs.FloatSpin.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
fs.FloatSpin.SetToolTip(self, tipString=tip)
else:
fs.FloatSpin.SetToolTipString(self, tip)
class Button(wx.Button):
"""Wrapper around wx.Button to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Button.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.Button.SetToolTip(self, tipString=tip)
else:
wx.Button.SetToolTipString(self, tip)
class ClearButton(Button):
"""Wrapper around a Button with stock id wx.ID_CLEAR,
to disable default key binding on certain platforms"""
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self.SetId(wx.ID_CLEAR)
if sys.platform == "darwin":
self.SetLabel(_("Clear"))
else:
self.SetLabel(_("&Clear"))
class CancelButton(Button):
"""Wrapper around a Button with stock id wx.ID_CANCEL, to disable
default key binding on certain platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self.SetId(wx.ID_CANCEL)
if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
self.SetLabel(_("Cancel"))
else:
self.SetLabel(_("&Cancel"))
class CloseButton(Button):
"""Wrapper around a Close labeled Button with stock id wx.ID_CANCEL
to disable default key binding on certain platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self.SetId(wx.ID_CANCEL)
if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
self.SetLabel(_("Close"))
else:
self.SetLabel(_("&Close"))
class ApplyButton(Button):
"""Wrapper around a Button with stock id wx.ID_APPLY,
to disable default key binding on certain platforms"""
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self.SetId(wx.ID_APPLY)
if sys.platform == "darwin":
self.SetLabel(_("Apply"))
else:
self.SetLabel(_("&Apply"))
class RadioButton(wx.RadioButton):
"""Wrapper around wx.RadioButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.RadioButton.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.RadioButton.SetToolTip(self, tipString=tip)
else:
wx.RadioButton.SetToolTipString(self, tip)
class BitmapButton(wx.BitmapButton):
"""Wrapper around wx.BitmapButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.BitmapButton.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.BitmapButton.SetToolTip(self, tipString=tip)
else:
wx.BitmapButton.SetToolTipString(self, tip)
class GenBitmapButton(buttons.GenBitmapButton):
"""Wrapper around GenBitmapButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
buttons.GenBitmapButton.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
buttons.GenBitmapButton.SetToolTip(self, tipString=tip)
else:
buttons.GenBitmapButton.SetToolTipString(self, tip)
class ToggleButton(wx.ToggleButton):
"""Wrapper around wx.ToggleButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ToggleButton.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.ToggleButton.SetToolTip(self, tipString=tip)
else:
wx.ToggleButton.SetToolTipString(self, tip)
class StaticText(wx.StaticText):
"""Wrapper around wx.StaticText to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.StaticText.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.StaticText.SetToolTip(self, tip)
else:
wx.StaticText.SetToolTipString(self, tip)
class StaticBox(wx.StaticBox):
"""Wrapper around wx.StaticBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.StaticBox.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.StaticBox.SetToolTip(self, tipString=tip)
else:
wx.StaticBox.SetToolTipString(self, tip)
class CheckListBox(wx.CheckListBox):
"""Wrapper around wx.CheckListBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.CheckListBox.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.CheckListBox.SetToolTip(self, tipString=tip)
else:
wx.CheckListBox.SetToolTipString(self, tip)
class TextCtrl(wx.TextCtrl):
"""Wrapper around wx.TextCtrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.TextCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.TextCtrl.SetToolTip(self, tipString=tip)
else:
wx.TextCtrl.SetToolTipString(self, tip)
class SearchCtrl(wx.SearchCtrl):
"""Wrapper around wx.SearchCtrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.SearchCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.SearchCtrl.SetToolTip(self, tipString=tip)
else:
wx.SearchCtrl.SetToolTipString(self, tip)
class ListCtrl(wx.ListCtrl):
"""Wrapper around wx.ListCtrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ListCtrl.__init__(self, *args, **kwargs)
def InsertItem(self, index, label, imageIndex=-1):
if wxPythonPhoenix:
return wx.ListCtrl.InsertItem(
self, index=index, label=label, imageIndex=imageIndex
)
else:
return wx.ListCtrl.InsertStringItem(
self, index=index, label=label, imageIndex=imageIndex
)
def SetItem(self, index, column, label, imageId=-1):
if wxPythonPhoenix:
return wx.ListCtrl.SetItem(
self, index=index, column=column, label=label, imageId=imageId
)
else:
return wx.ListCtrl.SetStringItem(
self, index=index, col=column, label=label, imageId=imageId
)
def CheckItem(self, item, check=True):
"""Uses either deprecated listmix.CheckListCtrlMixin
or new checkbox implementation in wx.ListCtrl since 4.1.0"""
if hasattr(self, "HasCheckBoxes"):
wx.ListCtrl.CheckItem(self, item, check)
else:
super().CheckItem(item, check)
def IsItemChecked(self, item):
if hasattr(self, "HasCheckBoxes"):
return wx.ListCtrl.IsItemChecked(self, item)
else:
return super().IsChecked(item)
if CheckWxVersion([4, 1, 0]):
class CheckListCtrlMixin:
"""This class pretends to be deprecated CheckListCtrlMixin mixin and
only enables checkboxes in new versions of ListCtrl"""
def __init__(self):
self.EnableCheckBoxes(True)
self.AssignImageList(wx.ImageList(16, 16), wx.IMAGE_LIST_SMALL)
else:
import wx.lib.mixins.listctrl as listmix
class CheckListCtrlMixin(listmix.CheckListCtrlMixin):
"""Wrapper for deprecated mixin"""
def __init__(self):
listmix.CheckListCtrlMixin.__init__(self)
class TreeCtrl(wx.TreeCtrl):
"""Wrapper around wx.TreeCtrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.TreeCtrl.__init__(self, *args, **kwargs)
def AppendItem(self, parent, text, image=-1, selImage=-1, data=None):
if wxPythonPhoenix:
return wx.TreeCtrl.AppendItem(self, parent, text, image, selImage, data)
else:
return wx.TreeCtrl.AppendItem(
self, parent, text, image, selImage, wx.TreeItemData(data)
)
def GetItemData(self, item):
if wxPythonPhoenix:
return wx.TreeCtrl.GetItemData(self, item)
else:
return wx.TreeCtrl.GetPyData(self, item)
class CustomTreeCtrl(CT.CustomTreeCtrl):
"""Wrapper around wx.lib.agw.customtreectrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
CT.CustomTreeCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
CT.CustomTreeCtrl.SetToolTip(self, tipString=tip)
else:
CT.CustomTreeCtrl.SetToolTipString(self, tip)
class ToolBar(wx.ToolBar):
"""Wrapper around wx.ToolBar to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ToolBar.__init__(self, *args, **kwargs)
def AddLabelTool(
self,
toolId,
label,
bitmap,
bmpDisabled=wx.NullBitmap,
kind=0,
shortHelpString="",
longHelpString="",
clientData=None,
):
if wxPythonPhoenix:
return wx.ToolBar.AddTool(
self,
toolId=toolId,
label=label,
bitmap=bitmap,
bmpDisabled=bmpDisabled,
kind=kind,
shortHelp=shortHelpString,
longHelp=longHelpString,
clientData=clientData,
)
else:
return wx.ToolBar.AddLabelTool(
self,
toolId,
label,
bitmap,
bmpDisabled,
kind,
shortHelpString,
longHelpString,
clientData,
)
def InsertLabelTool(
self,
pos,
toolId,
label,
bitmap,
bmpDisabled=wx.NullBitmap,
kind=0,
shortHelpString="",
longHelpString="",
clientData=None,
):
if wxPythonPhoenix:
return wx.ToolBar.InsertTool(
self,
pos,
toolId=toolId,
label=label,
bitmap=bitmap,
bmpDisabled=bmpDisabled,
kind=kind,
shortHelp=shortHelpString,
longHelp=longHelpString,
clientData=clientData,
)
else:
return wx.ToolBar.InsertLabelTool(
self,
pos,
toolId,
label,
bitmap,
bmpDisabled,
kind,
shortHelpString,
longHelpString,
clientData,
)
class Menu(wx.Menu):
"""Wrapper around wx.Menu to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Menu.__init__(self, *args, **kwargs)
def AppendItem(self, menuItem):
if wxPythonPhoenix:
wx.Menu.Append(self, menuItem=menuItem)
else:
wx.Menu.AppendItem(self, menuItem)
def AppendMenu(self, id, text, submenu, help=""):
if wxPythonPhoenix:
wx.Menu.AppendSubMenu(self, submenu=submenu, text=text, help=help)
else:
wx.Menu.AppendMenu(self, id=id, text=text, submenu=submenu, help=help)
class DragImage(wx.GenericDragImage if wxPythonPhoenix else wx.DragImage):
"""Wrapper around wx.DragImage to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class PseudoDC(wx.adv.PseudoDC if wxPythonPhoenix else wx.PseudoDC):
"""Wrapper around wx.PseudoDC to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def DrawLinePoint(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args, roundVal=True)
kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
if wxPythonPhoenix:
super().DrawLine(*args, **kwargs)
else:
super().DrawLinePoint(*args, **kwargs)
def DrawRectangleRect(self, rect):
if wxPythonPhoenix:
super().DrawRectangle(rect=rect)
else:
super().DrawRectangleRect(rect)
def BeginDrawing(self):
if not wxPythonPhoenix:
super().BeginDrawing()
def EndDrawing(self):
if not wxPythonPhoenix:
super().EndDrawing()
def DrawRectangle(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args, roundVal=True)
kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
super().DrawRectangle(*args, **kwargs)
def DrawBitmap(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args, roundVal=True)
kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
super().DrawBitmap(*args, **kwargs)
def DrawCircle(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args, roundVal=True)
kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
super().DrawCircle(*args, **kwargs)
class ClientDC(wx.ClientDC):
"""Wrapper around wx.ClientDC to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def GetFullMultiLineTextExtent(self, string, font=None):
if wxPythonPhoenix:
return super().GetFullMultiLineTextExtent(string, font)
else:
return super().GetMultiLineTextExtent(string, font)
class Rect(wx.Rect):
"""Wrapper around wx.Rect to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args)
kwargs = convertToInt(argsOrKwargs=kwargs)
wx.Rect.__init__(self, *args, **kwargs)
def ContainsXY(self, x, y):
if wxPythonPhoenix:
return wx.Rect.Contains(self, x=int(x), y=int(y))
else:
return wx.Rect.ContainsXY(self, int(x), int(y))
def ContainsRect(self, rect):
if wxPythonPhoenix:
return wx.Rect.Contains(self, rect=rect)
else:
return wx.Rect.ContainsRect(self, rect)
def OffsetXY(self, dx, dy):
if wxPythonPhoenix:
return wx.Rect.Offset(self, int(dx), int(dy))
else:
return wx.Rect.OffsetXY(self, int(dx), int(dy))
class CheckBox(wx.CheckBox):
"""Wrapper around wx.CheckBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.CheckBox.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.CheckBox.SetToolTip(self, tipString=tip)
else:
wx.CheckBox.SetToolTipString(self, tip)
class Choice(wx.Choice):
"""Wrapper around wx.Choice to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Choice.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.Choice.SetToolTip(self, tipString=tip)
else:
wx.Choice.SetToolTipString(self, tip)
class TextEntryDialog(wx.TextEntryDialog):
"""Wrapper around wx.TextEntryDialog to have more control
over the widget on different platforms/wxpython versions"""
def __init__(
self,
parent,
message,
caption="Please enter text",
value="",
style=wx.OK | wx.CANCEL | wx.CENTRE,
pos=wx.DefaultPosition,
):
if wxPythonPhoenix:
super().__init__(
parent=parent,
message=message,
caption=caption,
value=value,
style=style,
pos=pos,
)
else:
super().__init__(
parent=parent,
message=message,
caption=caption,
defaultValue=value,
style=style,
pos=pos,
)
class ColourSelect(csel.ColourSelect):
"""Wrapper around wx.lib.colourselect.ColourSelect to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
csel.ColourSelect.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
csel.ColourSelect.SetToolTip(self, tipString=tip)
else:
csel.ColourSelect.SetToolTipString(self, tip)
class ComboCtrl(wxComboCtrl):
def __init__(self, *args, **kwargs):
wxComboCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wxComboCtrl.SetToolTip(self, tipString=tip)
else:
wxComboCtrl.SetToolTipString(self, tip)
class Dialog(wx.Dialog):
"""Wrapper around wx.Dialog to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Dialog.__init__(self, *args, **kwargs)
class Notebook(wx.Notebook):
"""Wrapper around NoteBook to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.Notebook.__init__(self, *args, **kwargs)
class OwnerDrawnComboBox(OwnerDrawnComboBox_):
"""Wrapper around OwnerDrawnComboBox to have more control
over the widget on different platforms/wxpython versions"""
ODCB_PAINTING_CONTROL = ODCB_PAINTING_CONTROL
ODCB_PAINTING_SELECTED = ODCB_PAINTING_SELECTED
def __init__(self, *args, **kwargs):
OwnerDrawnComboBox_.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
OwnerDrawnComboBox_.SetToolTip(self, tipString=tip)
else:
OwnerDrawnComboBox_.SetToolTipString(self, tip)
class BitmapComboBox(BitmapComboBox_):
"""Wrapper around BitmapComboBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
BitmapComboBox_.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
BitmapComboBox_.SetToolTip(self, tipString=tip)
else:
BitmapComboBox_.SetToolTipString(self, tip)
class ScrolledPanel(scrolled.ScrolledPanel):
"""Wrapper around scrolled.ScrolledPanel to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
scrolled.ScrolledPanel.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
scrolled.ScrolledPanel.SetToolTip(self, tipString=tip)
else:
scrolled.ScrolledPanel.SetToolTipString(self, tip)
class FileBrowseButton(filebrowse.FileBrowseButton):
"""Wrapper around filebrowse.FileBrowseButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
filebrowse.FileBrowseButton.__init__(self, *args, **kwargs)
class DirBrowseButton(filebrowse.DirBrowseButton):
"""Wrapper around filebrowse.DirBrowseButton to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
filebrowse.DirBrowseButton.__init__(self, *args, **kwargs)
class ExpandoTextCtrl(expando.ExpandoTextCtrl):
"""Wrapper around expando.ExpandoTextCtrl to have more control
over the widget on different platforms/wxpython versions"""
EVT_ETC_LAYOUT_NEEDED = expando.EVT_ETC_LAYOUT_NEEDED
def __init__(self, *args, **kwargs):
expando.ExpandoTextCtrl.__init__(self, *args, **kwargs)
class ColourPickerCtrl(wx.ColourPickerCtrl):
"""Wrapper around wx.ColourPickerCtrl to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ColourPickerCtrl.__init__(self, *args, **kwargs)
class ListBox(wx.ListBox):
"""Wrapper around wx.ListBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ListBox.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.ListBox.SetToolTip(self, tipString=tip)
else:
wx.ListBox.SetToolTipString(self, tip)
def DeselectAll(self):
for i in range(self.GetCount()):
self.Deselect(i)
def SelectAll(self):
for i in range(self.GetCount()):
self.Select(i)
class HyperlinkCtrl(HyperlinkCtrl_):
"""Wrapper around HyperlinkCtrl to have more control
over the widget on different platforms/wxpython versions"""
HL_ALIGN_LEFT = HL_ALIGN_LEFT
HL_CONTEXTMENU = HL_CONTEXTMENU
def __init__(self, *args, **kwargs):
HyperlinkCtrl_.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
HyperlinkCtrl_.SetToolTip(self, tipString=tip)
else:
HyperlinkCtrl_.SetToolTipString(self, tip)
class ComboBox(wx.ComboBox):
"""Wrapper around wx.ComboBox to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.ComboBox.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.ComboBox.SetToolTip(self, tipString=tip)
else:
wx.ComboBox.SetToolTipString(self, tip)
class SimpleTabArt(tabart.AuiDefaultTabArt):
"""A class simplifying the appearance of AUI notebook tabs."""
def __init__(self):
"""Default class constructor."""
tabart.AuiDefaultTabArt.__init__(self)
def SetDefaultColours(self, base_colour=None):
"""
Overrides AuiDefaultTabArt.SetDefaultColours
to get rid of gradient and to look more like
flatnotebook tabs.
"""
if base_colour is None:
base_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)
self.SetBaseColour(base_colour)
tab_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
self._border_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNSHADOW)
self._border_pen = wx.Pen(self._border_colour)
self._background_top_colour = base_colour
self._background_bottom_colour = base_colour
self._tab_top_colour = tab_color
self._tab_bottom_colour = tab_color
self._tab_gradient_highlight_colour = tab_color
self._tab_inactive_top_colour = base_colour
self._tab_inactive_bottom_colour = base_colour
self._tab_text_colour = lambda page: page.text_colour
self._tab_disabled_text_colour = wx.SystemSettings.GetColour(
wx.SYS_COLOUR_GRAYTEXT
)
|