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 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
|
# Programmer: Daniel Pozmanter
# E-mail: drpython@bluebottle.com
# Note: You must reply to the verification e-mail to get through.
#
# Copyright 2003-2010 Daniel Pozmanter
#
# Distributed under the terms of the GPL (GNU Public License)
#
# DrPython is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#prefs dialog
import os, locale
import sys
import wx
import drScrolledMessageDialog
from drProperty import *
import drPrefsFile
import drFileDialog
from drStyleDialog import drStyleDialog, drSimpleStyleDialog
from drPreferences import drPreferences
#Cause I want it to work MY way!
class drPrefsBook(wx.Panel):
def __init__(self, parent, id, size):
wx.Panel.__init__(self, parent, id, size=size)
x, y = size
self.pages = []
self.labels = []
self.ancestor = parent.parent
self.listview = wx.ListView(self, id+1, pos=(0, 0), size=(150, y), style=wx.LC_SINGLE_SEL|wx.LC_LIST)
self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.OnSelected, id=id+1)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.oldpos = -1
def AddPage(self, page, label):
page.Show(False)
self.pages.append(page)
self.labels.append(label)
def OnSelected(self, event):
if self.oldpos > -1:
self.pages[self.oldpos].Show(False)
sel = self.listview.GetFocusedItem()
self.ancestor.prefdialogposition = sel
px, py = self.GetPositionTuple()
sx, sy = self.GetSizeTuple()
self.pages[sel].Move((px+150, 0))
self.pages[sel].SetSize((sx-150, sy))
self.pages[sel].Show(True)
self.oldpos = sel
def OnSize(self, event):
sel = self.listview.GetFocusedItem()
px, py = self.GetPositionTuple()
sx, sy = self.GetSizeTuple()
self.listview.SetSize((150, sy))
self.pages[sel].Move((px+150, 0))
self.pages[sel].SetSize((sx-150, sy))
def SetSelection(self, selection):
self.listview.Select(selection)
self.listview.Focus(selection)
def ShowPanel(self, selection=0):
x = 0
for label in self.labels:
self.listview.InsertStringItem(x, label)
x += 1
self.listview.Select(selection)
self.listview.Focus(selection)
self.OnSelected(None)
#Cleaned up the sizing code, which was a tad ugly.
class PrefsPanel(wx.ScrolledWindow):
def __init__(self, parent, id, name, NumberOfItems):
wx.ScrolledWindow.__init__(self, parent, id)
self.SetName(name)
self.grandparent = parent.GetParent()
self.drframe = self.grandparent.parent
self.EnableScrolling(True, True)
self.SetScrollbars(10, NumberOfItems+3, 35, 62)
self.btnResetPanel = wx.Button(self, self.grandparent.ID_RESET_PANEL, " Reset Panel ")
#self.theSizer = wx.FlexGridSizer(NumberOfItems+2, 3, 5, 10)
self.theSizer = wx.FlexGridSizer(0, 3, 5, 10)
self.AddBuffer()
self.Add(self.btnResetPanel, "Reset Just These Preferences:")
self.Bind(wx.EVT_BUTTON, self.grandparent.OnbtnResetPanel, id=self.grandparent.ID_RESET_PANEL)
self.Show(False)
def Add(self, wxitem, label=""):
if label:
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, label), 1, wx.EXPAND)
self.theSizer.Add(wxitem, 1, wx.SHAPED)
else:
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wxitem, 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
def AddBuffer(self):
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
def AddLabel(self, label):
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wx.StaticText(self, -1, label), 1, wx.EXPAND)
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
def AddTwoItems(self, wxitem1, wxitem2):
self.theSizer.Add(wx.StaticText(self, -1, " "), 1, wx.SHAPED)
self.theSizer.Add(wxitem1, 1, wx.SHAPED)
self.theSizer.Add(wxitem2, 1, wx.SHAPED)
def SetPanelSizer(self):
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
class BookmarksPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 1)
self.btnBStyle = wx.Button(self, self.grandparent.ID_BOOKMARKS_STYLE, " Edit Bookmarks Style ")
self.Add(self.btnBStyle)
self.SetPanelSizer()
self.Bind(wx.EVT_BUTTON, self.OnbtnBStyle, id=self.grandparent.ID_BOOKMARKS_STYLE)
def OnbtnBStyle(self, event):
d = drSimpleStyleDialog(self, -1, ("Style: Bookmarks"), self.grandparent.prefs.bookmarksstyle, self.grandparent.prefs.bookmarksstyle)
d.ShowModal()
if d.ClickedOk():
self.grandparent.prefs.bookmarksstyle = d.GetStyleString()
d.Destroy()
class DocumentPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 10)
self.radusestyles = wx.RadioBox(self, -1, "Styles:", wx.DefaultPosition, wx.DefaultSize, ["Don't Use Styles", "Use Styles", "Only Use \"Normal\", \"Caret Foreground\""], 1, wx.RA_SPECIFY_COLS)
self.boxdefaultsyntaxhighlighting = wx.Choice(self, -1, wx.Point(225, 135), (-1, -1), ["Python", "C/C++", "HTML"])
self.chkonlyusedefaultsyntaxhighlighting = wx.CheckBox(self, -1, "")
self.btnStyle = wx.Button(self, self.grandparent.ID_FILE_STYLE, " Edit Text Styles ")
self.btnApplyProperty = wx.Button(self, self.grandparent.ID_APPLY_PROPERTY, " Apply Text Property To All Styles ")
self.raddocautoindent = wx.RadioBox(self, -1, "Auto Indent:", wx.DefaultPosition, wx.DefaultSize, ["None", "Normal", "Context Sensitive"], 1, wx.RA_SPECIFY_COLS)
self.chkdocshowlinenumbers = wx.CheckBox(self, -1, "")
#self.chkdocremovetrailingwhitespace = wx.CheckBox(self, -1, "")
self.chkdocautoreload = wx.CheckBox(self, -1, "")
self.chkdocparenthesismatching = wx.CheckBox(self, -1, "")
self.chkdocupdateindentation = wx.CheckBox(self, -1, "")
self.chkdocusefileindentation = wx.CheckBox(self, -1, "")
self.chkWhitespace = wx.CheckBox(self, -1, "")
self.txtcaretwidth = wx.TextCtrl(self, self.grandparent.ID_DOC_CARET_WIDTH, str(self.grandparent.prefs.doccaretwidth), wx.Point(225, 215), (35, -1))
self.chkhighlightcurrentline = wx.CheckBox(self, -1, "")
self.chkignorectrlpageupdown = wx.CheckBox(self, -1, "")
self.chkignoretextfunctionkeys = wx.CheckBox(self, -1, "")
self.chkuseindentationguides = wx.CheckBox(self, -1, "")
#Chris McDonough (I added txt prefix, update for local constants)
self.txtdoclonglinecol = wx.TextCtrl(self, self.grandparent.ID_LONGLINE_COL, str(self.grandparent.prefs.doclonglinecol), wx.Point(225, 215), (35, -1))
#/Chris McDonough
self.chkscrollextrapage = wx.CheckBox(self, -1, "")
self.raddoccommentmode = wx.RadioBox(self, -1, "Comment Mode:", wx.DefaultPosition, wx.DefaultSize, ["Start of Line", "Start of Word"], 1, wx.RA_SPECIFY_COLS)
self.Add(self.btnStyle)
self.Add(self.btnApplyProperty)
self.Add(self.radusestyles)
self.Add(self.boxdefaultsyntaxhighlighting, "Default Syntax Highlighting:")
self.Add(self.chkonlyusedefaultsyntaxhighlighting, "Only Use Default Syntax Highlighting:")
self.Add(self.chkdocshowlinenumbers, "Show Line Numbers:")
#self.Add(self.chkdocremovetrailingwhitespace, "Remove Trailing Whitespace:")
self.Add(self.raddocautoindent)
self.Add(self.chkdocautoreload, "Auto Reload:")
self.Add(self.chkdocparenthesismatching, "Parenthesis Matching:")
self.Add(self.chkdocupdateindentation, "Update Indentation:")
self.Add(self.chkdocusefileindentation, "Use File's Indentation:")
self.Add(self.chkWhitespace, "Whitespace is visible on startup:")
self.Add(self.chkuseindentationguides, "Use Indentation guides:")
self.Add(self.txtdoclonglinecol, "Long Line Indicator Column:")
self.Add(self.chkscrollextrapage, "Scroll Extra Page:")
self.Add(self.txtcaretwidth, "Caret Width:")
self.Add(self.chkhighlightcurrentline, "Highlight Current Line:")
self.Add(self.chkignorectrlpageupdown, "Ignore Ctrl Pageup/down:")
self.Add(self.chkignoretextfunctionkeys, "Ignore Text Function Keys:")
self.Add(self.raddoccommentmode)
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnStyle, id=self.grandparent.ID_FILE_STYLE)
self.Bind(wx.EVT_BUTTON, self.OnbtnApplyProperty, id=self.grandparent.ID_APPLY_PROPERTY)
self.Bind(wx.EVT_TEXT, self.Ontxtcaretwidth, id=self.grandparent.ID_DOC_CARET_WIDTH)
self.Bind(wx.EVT_TEXT, self.Ontxtdoclonglinecol, id=self.grandparent.ID_LONGLINE_COL)
def reset(self):
self.boxdefaultsyntaxhighlighting.SetSelection(self.grandparent.prefs.docdefaultsyntaxhighlighting)
self.chkonlyusedefaultsyntaxhighlighting.SetValue(self.grandparent.prefs.doconlyusedefaultsyntaxhighlighting)
self.radusestyles.SetSelection(self.grandparent.prefs.docusestyles)
self.chkdocshowlinenumbers.SetValue(self.grandparent.prefs.docshowlinenumbers)
#self.chkdocremovetrailingwhitespace.SetValue(self.grandparent.prefs.docremovetrailingwhitespace)
self.raddocautoindent.SetSelection(self.grandparent.prefs.docautoindent)
self.chkdocautoreload.SetValue(self.grandparent.prefs.docautoreload)
self.chkdocparenthesismatching.SetValue(self.grandparent.prefs.docparenthesismatching)
self.chkdocupdateindentation.SetValue(self.grandparent.prefs.docupdateindentation)
self.chkdocusefileindentation.SetValue(self.grandparent.prefs.docusefileindentation)
self.chkWhitespace.SetValue(self.grandparent.prefs.docwhitespaceisvisible)
self.chkuseindentationguides.SetValue(self.grandparent.prefs.docuseindentationguides)
self.chkscrollextrapage.SetValue(self.grandparent.prefs.docscrollextrapage)
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.doccaretwidth))
self.chkhighlightcurrentline.SetValue(self.grandparent.prefs.dochighlightcurrentline)
self.chkignorectrlpageupdown.SetValue(self.grandparent.prefs.docignorectrlpageupdown)
self.chkignoretextfunctionkeys.SetValue(self.grandparent.prefs.docignoretextfunctionkeys)
self.raddoccommentmode.SetSelection(self.grandparent.prefs.doccommentmode)
def Ontxtdoclonglinecol(self, event):
#Chris McDonough (Edited to allow for negative numbers)
x = self.txtdoclonglinecol.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
if not x == "-":
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Actual Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txtdoclonglinecol.SetValue(str(self.grandparent.prefs.doclonglinecol))
return
y = 0
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txtdoclonglinecol.SetValue(str(self.grandparent.prefs.doclonglinecol))
return
if y > 1024:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
def Ontxtcaretwidth(self, event):
x = self.txtcaretwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.doccaretwidth))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.doccaretwidth))
return
if y > 256:
drScrolledMessageDialog.ShowMessage(self, "DrPython does not recommend going this high. You can of course...", "Hmmmm")
def OnbtnStyle(self, event):
d = drStyleDialog(self, -1, "Edit Styles")
d.ShowModal()
if d.ClickedOk():
self.grandparent.prefs.PythonStyleDictionary, self.grandparent.prefs.CPPStyleDictionary, self.grandparent.prefs.HTMLStyleDictionary = d.GetArrays()
d.Destroy()
def OnbtnApplyProperty(self, event):
d = wx.SingleChoiceDialog(self, "Select the property you wish to apply to all styles:", "Apply Property To All Styles", ["Font", "Size", "Background", "Foreground"], wx.OK|wx.CANCEL)
answer = d.ShowModal()
s = d.GetStringSelection()
d.Destroy()
if answer == wx.ID_OK:
self.SetPropertyForStyleArray(self.grandparent.prefs.PythonStyleDictionary, s)
self.SetPropertyForStyleArray(self.grandparent.prefs.CPPStyleDictionary, s)
self.SetPropertyForStyleArray(self.grandparent.prefs.HTMLStyleDictionary, s)
def SetPropertyForStyleArray(self, targetArray, s):
#Ignore default text for all, and line number text for bg/fg (first two items)
x = 2
if s == "Font":
prop = "face"
dummy = ",face:terminal"
x = 1
elif s == "Size":
prop = "size"
dummy = ",size:10"
x = 1
elif s == "Background":
prop = "back"
dummy = ",back:#FFFFFF"
elif s == "Foreground":
prop = "fore"
dummy = ",fore:#000000"
newstring = getStyleProperty(prop, targetArray[0])
#ignore caret foreground, selection, folding style, long line column, current line
#(last five items).
l = len(targetArray) - 5
while x < l:
tstring = targetArray[x]
try:
tstring.index(prop)
except:
tstring = tstring + dummy
targetArray[x] = setStyleProperty(prop, tstring, newstring)
x = x + 1
class DocumentationPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 8)
self.btnBrowse = wx.Button(self, self.grandparent.ID_DOCUMENTATION_BROWSE, " &Browse ")
self.btnBrowseP = wx.Button(self, self.grandparent.ID_DOCUMENTATION_BROWSE_P, " &Browse ")
self.btnBrowseW = wx.Button(self, self.grandparent.ID_DOCUMENTATION_BROWSE_W, " &Browse ")
self.btnBrowseR = wx.Button(self, self.grandparent.ID_DOCUMENTATION_BROWSE_R, " &Browse ")
self.txtbrowser = wx.TextCtrl(self, -1, "", wx.Point(225, 215), (250, -1))
self.txtpython = wx.TextCtrl(self, -1, "", wx.Point(225, 215), (250, -1))
self.txtwxwidgets = wx.TextCtrl(self, -1, "", wx.Point(225, 215), (250, -1))
self.txtrehowto = wx.TextCtrl(self, -1, "", wx.Point(225, 215), (250, -1))
self.AddLabel("Browser:")
self.AddTwoItems(self.txtbrowser, self.btnBrowse)
self.AddLabel("Python Docs:")
self.AddTwoItems(self.txtpython, self.btnBrowseP)
self.AddLabel("WxWidgets Docs:")
self.AddTwoItems(self.txtwxwidgets, self.btnBrowseW)
self.AddLabel("Regular Expression Howto:")
self.AddTwoItems(self.txtrehowto, self.btnBrowseR)
self.SetPanelSizer()
self.reset()
if self.grandparent.prefs.platform_is_windows:
self.wildcard = "Program File (*.exe)|*.exe|All files (*)|*"
else:
self.wildcard = "All files (*)|*"
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowse, id=self.grandparent.ID_DOCUMENTATION_BROWSE)
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseDoc, id=self.grandparent.ID_DOCUMENTATION_BROWSE_P)
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseDoc, id=self.grandparent.ID_DOCUMENTATION_BROWSE_W)
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseDoc, id=self.grandparent.ID_DOCUMENTATION_BROWSE_R)
def reset(self):
self.txtbrowser.SetValue(self.grandparent.prefs.documentationbrowser)
self.txtpython.SetValue(self.grandparent.prefs.documentationpythonlocation)
self.txtwxwidgets.SetValue(self.grandparent.prefs.documentationwxwidgetslocation)
self.txtrehowto.SetValue(self.grandparent.prefs.documentationrehowtolocation)
def OnbtnBrowse(self, event):
dlg = drFileDialog.FileDialog(self.grandparent.parent, "Select A Browser", self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
self.txtbrowser.SetValue(dlg.GetPath())
dlg.Destroy()
def OnbtnBrowseDoc(self, event):
eid = event.GetId()
result = ""
dlg = drFileDialog.FileDialog(self.grandparent.parent, "Location of Documentation", self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
result = dlg.GetPath()
dlg.Destroy()
if result:
if eid == self.grandparent.ID_DOCUMENTATION_BROWSE_P:
self.txtpython.SetValue(result)
elif eid == self.grandparent.ID_DOCUMENTATION_BROWSE_W:
self.txtwxwidgets.SetValue(result)
elif eid == self.grandparent.ID_DOCUMENTATION_BROWSE_R:
self.txtrehowto.SetValue(result)
class DragAndDropPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 2)
self.raddraganddropmode = wx.RadioBox(self, -1, "Drag and Drop Mode:", wx.DefaultPosition, wx.DefaultSize, ["Drag: Files Only, Drop: Files and Text", "Drag: Files and Text, Drop: Files and Text", "Drag and Drop Files Only"], 1, wx.RA_SPECIFY_COLS)
self.raddraganddroptextmode = wx.RadioBox(self, -1, "Drag and Drop Text Mode:", wx.DefaultPosition, wx.DefaultSize, ["Copy by Default, Cut with Control", "Cut by Default, Copy with Control"], 1, wx.RA_SPECIFY_COLS)
self.Add(self.raddraganddropmode)
self.Add(self.raddraganddroptextmode)
self.SetPanelSizer()
self.reset()
def reset(self):
self.raddraganddropmode.SetSelection(self.grandparent.prefs.draganddropmode)
self.raddraganddroptextmode.SetSelection(self.grandparent.prefs.draganddroptextmode)
class DrScriptPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 2)
self.txtdefaultdirectory = wx.TextCtrl(self, -1, self.grandparent.prefs.drscriptsdirectory, wx.Point(15, 325), (250, -1))
self.DrScriptbtnBrowse = wx.Button(self, self.grandparent.ID_DRSCRIPT_BROWSE, " &Browse ")
self.btnDStyle = wx.Button(self, self.grandparent.ID_DRSCRIPT_STYLE, " Edit DrScript Style ")
self.chkloadexamples = wx.CheckBox(self, -1, "")
self.Add(self.btnDStyle)
self.AddLabel("Default Directory:")
self.AddTwoItems(self.txtdefaultdirectory, self.DrScriptbtnBrowse)
self.Add(self.chkloadexamples, "Load Example Scripts:")
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnDBrowse, id=self.grandparent.ID_DRSCRIPT_BROWSE)
self.Bind(wx.EVT_BUTTON, self.OnbtnDStyle, id=self.grandparent.ID_DRSCRIPT_STYLE)
def reset(self):
self.txtdefaultdirectory.SetValue(self.grandparent.prefs.drscriptsdirectory)
self.chkloadexamples.SetValue(self.grandparent.prefs.drscriptloadexamples)
def OnbtnDBrowse(self, event):
d = wx.DirDialog(self, "Select Default Directory For DrScript:", style=wx.DD_DEFAULT_STYLE|wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)
if d.ShowModal() == wx.ID_OK:
self.txtdefaultdirectory.SetValue(d.GetPath())
d.Destroy()
def OnbtnDStyle(self, event):
d = drSimpleStyleDialog(self, -1, ("Style: DrScript"), self.grandparent.prefs.drscriptstyle, self.grandparent.prefs.drscriptstyle)
d.ShowModal()
if d.ClickedOk():
self.grandparent.prefs.drscriptstyle = d.GetStyleString()
d.Destroy()
class FileDialogPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 2)
self.chkusewxfiledialog = wx.CheckBox(self, -1, "")
self.chkdefaultextension = wx.CheckBox(self, -1, "")
self.btnwildcard = wx.Button(self, self.grandparent.ID_BTN_WILDCARD, " Edit Wildcard ")
self.btnlnkreplacetable = wx.Button(self, self.grandparent.ID_BTN_LNK_REPLACE_TABLE, " Windows Shortcut Replace Table ")
self.Add(self.chkdefaultextension, "Default Extension ('.py'):")
self.Add(self.chkusewxfiledialog, "Use wx.FileDialog:")
self.Add(self.btnwildcard)
self.Add(self.btnlnkreplacetable)
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnEditWildcard, id=self.grandparent.ID_BTN_WILDCARD)
self.Bind(wx.EVT_BUTTON, self.OnReplaceTable, id=self.grandparent.ID_BTN_LNK_REPLACE_TABLE)
def reset(self):
self.chkusewxfiledialog.SetValue(self.grandparent.prefs.usewxfiledialog)
self.chkdefaultextension.SetValue(self.grandparent.prefs.defaultextension)
def OnEditWildcard(self, event):
import drFileDialogPrefs
d = drFileDialogPrefs.drFilePrefsDialog(self)
answer = d.ShowModal()
newwc = d.GetWildcard()
cwc = d.GetConstantWildcard()
d.Destroy()
if answer == wx.ID_OK:
self.grandparent.prefs.wildcard = newwc
self.grandparent.prefs.constantwildcard = cwc
def OnReplaceTable(self, event):
import drFileDialogPrefs
d = drFileDialogPrefs.drReplaceTableDialog(self)
answer = d.ShowModal()
newrt = d.GetReplaceTable()
d.Destroy()
if answer == wx.ID_OK:
self.grandparent.prefs.windowsshortcutreplacetable = newrt
class FileTypesPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 7)
self.ID_FILETYPE = 701
self.ID_EXTENSIONS = 702
self.ID_USETABS = 703
self.ID_TABWIDTH = 704
self.ID_FOLDING = 705
self.ID_EOLMODE = 706
self.ID_COMMENTSTRING = 707
self.ID_WORDWRAP = 708
self.ID_USEINTELLIBACKSPACE = 709
self.ID_REMOVETRAILINGWHITESPACE = 710
self.cboFileType = wx.ComboBox(self, self.ID_FILETYPE, choices=["Python", "C/C++", "HTML", "Text"])
self.filetype = self.drframe.txtDocument.filetype
self.txtExtensions = wx.TextCtrl(self, self.ID_EXTENSIONS, "", wx.Point(225, 215), (225, -1))
self.chkdocusetabs = wx.CheckBox(self, self.ID_USETABS, "")
self.chkdocuseintellibackspace = wx.CheckBox(self, self.ID_USEINTELLIBACKSPACE, "")
self.chkdocremovetrailingwhitespace = wx.CheckBox(self, self.ID_REMOVETRAILINGWHITESPACE, "")
self.chkdocwordwrap = wx.CheckBox(self, self.ID_WORDWRAP, "")
self.chkfolding = wx.CheckBox(self, self.ID_FOLDING, "")
self.txtdoccommentstring = wx.TextCtrl(self, self.ID_COMMENTSTRING, "", wx.Point(225, 215), (35, -1))
self.txttabwidth = wx.TextCtrl(self, self.ID_TABWIDTH, "", wx.Point(225, 215), (35, -1))
self.radFormat = wx.Choice(self, self.ID_EOLMODE, wx.Point(15, 80), wx.DefaultSize, [" Unix ('\\n') "," DOS/Windows ('\\r\\n') "," Mac ('\\r') "])
self.Add(self.cboFileType, "File Type:")
self.Add(self.txtExtensions, "Extensions:")
self.Add(self.txtdoccommentstring, "Comment String:")
self.Add(self.txttabwidth, "Tab Width:")
self.Add(self.chkdocusetabs, "Use Tabs:")
self.Add(self.chkdocuseintellibackspace, "Use Intelli Backspace:")
self.Add(self.chkdocremovetrailingwhitespace, "Remove trailing Whitespace on Save:")
self.Add(self.chkfolding, "Folding:")
self.Add(self.chkdocwordwrap, "Word Wrap:")
self.Add(self.radFormat, "Line Ending Format:")
self.SetPanelSizer()
self.Bind(wx.EVT_COMBOBOX, self.OnFileType, id=self.ID_FILETYPE)
self.Bind(wx.EVT_TEXT, self.Ontxttabwidth, id=self.ID_TABWIDTH)
self.Bind(wx.EVT_TEXT, self.OnExtensions, id=self.ID_EXTENSIONS)
self.Bind(wx.EVT_TEXT, self.OnCommentString, id=self.ID_COMMENTSTRING)
self.Bind(wx.EVT_CHECKBOX, self.OnUseTabs, id=self.ID_USETABS)
self.Bind(wx.EVT_CHECKBOX, self.OnUseIntelliBackspace, id=self.ID_USEINTELLIBACKSPACE)
self.Bind(wx.EVT_CHECKBOX, self.OnRemoveTrailingWhitespace, id=self.ID_REMOVETRAILINGWHITESPACE)
self.Bind(wx.EVT_CHECKBOX, self.OnFolding, id=self.ID_FOLDING)
self.Bind(wx.EVT_CHECKBOX, self.OnWordWrap, id=self.ID_WORDWRAP)
self.Bind(wx.EVT_CHOICE, self.OnEolMode, id=self.ID_EOLMODE)
self.cboFileType.SetSelection(self.filetype)
self.reset()
def reset(self):
self.extensions = self.grandparent.prefs.extensions.copy()
self.docusetabs = self.grandparent.prefs.docusetabs.copy()
self.docuseintellibackspace = self.grandparent.prefs.docuseintellibackspace.copy()
self.docremovetrailingwhitespace= self.grandparent.prefs.docremovetrailingwhitespace.copy()
self.doctabwidth = self.grandparent.prefs.doctabwidth.copy()
self.doceolmode = self.grandparent.prefs.doceolmode.copy()
self.docfolding = self.grandparent.prefs.docfolding.copy()
self.doccommentstring = self.grandparent.prefs.doccommentstring.copy()
self.docwordwrap = self.grandparent.prefs.docwordwrap.copy()
self.OnFileType(None)
def OnCommentString(self, event):
self.doccommentstring[self.filetype] = self.txtdoccommentstring.GetValue()
def OnEolMode(self, event):
self.doceolmode[self.filetype] = self.radFormat.GetSelection()
def OnExtensions(self, event):
self.extensions[self.filetype] = self.txtExtensions.GetValue()
def OnFileType(self, event):
self.filetype = self.cboFileType.GetSelection()
self.txtExtensions.SetValue(self.extensions[self.filetype])
self.chkdocusetabs.SetValue(self.docusetabs[self.filetype])
self.chkdocuseintellibackspace.SetValue(self.docuseintellibackspace[self.filetype])
self.chkdocremovetrailingwhitespace.SetValue(self.docremovetrailingwhitespace[self.filetype])
self.txttabwidth.SetValue(str(self.doctabwidth[self.filetype]))
self.radFormat.SetSelection(self.doceolmode[self.filetype])
self.chkfolding.SetValue(self.docfolding[self.filetype])
self.txtdoccommentstring.SetValue(self.doccommentstring[self.filetype])
self.chkdocwordwrap.SetValue(self.docwordwrap[self.filetype])
def OnFolding(self, event):
self.docfolding[self.filetype] = int(self.chkfolding.GetValue())
def Ontxttabwidth(self, event):
x = self.txttabwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.doctabwidth[self.filetype]))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.doctabwidth[self.filetype]))
return
if y > 1024:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
return
self.doctabwidth[self.filetype] = y
def OnWordWrap(self, event):
self.docwordwrap[self.filetype] = int(self.chkdocwordwrap.GetValue())
def OnUseTabs(self, event):
self.docusetabs[self.filetype] = int(self.chkdocusetabs.GetValue())
def OnUseIntelliBackspace(self, event):
self.docuseintellibackspace[self.filetype] = int(self.chkdocuseintellibackspace.GetValue())
def OnRemoveTrailingWhitespace(self, event):
self.docremovetrailingwhitespace[self.filetype] = int(self.chkdocremovetrailingwhitespace.GetValue())
class FindReplacePanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 8)
self.chkregularexpression = wx.CheckBox(self, -1, "")
self.chkmatchcase = wx.CheckBox(self, -1, "")
self.chkfindbackwards = wx.CheckBox(self, -1, "")
self.chkwholeword = wx.CheckBox(self, -1, "")
self.chkinselection = wx.CheckBox(self, -1, "")
self.chkfromcursor = wx.CheckBox(self, -1, "")
self.chkpromptonreplace = wx.CheckBox(self, -1, "")
self.chkfindreplaceautowrap = wx.CheckBox(self, -1, "")
self.chkundercursor = wx.CheckBox(self, -1, "")
self.Add(self.chkregularexpression, "Regular Expression:")
self.Add(self.chkmatchcase, "Match Case:")
self.Add(self.chkfindbackwards, "Find Backwards:")
self.Add(self.chkwholeword, "Whole Word:")
self.Add(self.chkinselection, "In Selection:")
self.Add(self.chkfromcursor, "From Cursor:")
self.Add(self.chkpromptonreplace, "Prompt On Replace:")
self.Add(self.chkfindreplaceautowrap, "Auto Wrap:")
self.Add(self.chkundercursor, "Under Cursor:")
self.SetPanelSizer()
self.reset()
def reset(self):
self.chkregularexpression.SetValue(self.grandparent.prefs.findreplaceregularexpression)
self.chkmatchcase.SetValue(self.grandparent.prefs.findreplacematchcase)
self.chkfindbackwards.SetValue(self.grandparent.prefs.findreplacefindbackwards)
self.chkwholeword.SetValue(self.grandparent.prefs.findreplacewholeword)
self.chkinselection.SetValue(self.grandparent.prefs.findreplaceinselection)
self.chkfromcursor.SetValue(self.grandparent.prefs.findreplacefromcursor)
self.chkpromptonreplace.SetValue(self.grandparent.prefs.findreplacepromptonreplace)
self.chkfindreplaceautowrap.SetValue(self.grandparent.prefs.findreplaceautowrap)
self.chkundercursor.SetValue(self.grandparent.prefs.findreplaceundercursor)
class GeneralPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 8)
try:
defaultlocale = locale.getdefaultlocale()[1]
except:
defaultlocale = None
if defaultlocale is not None:
self.encodings = [defaultlocale, "ascii", "latin-1", "cp1252", "utf-8", "utf-16"]
else:
self.encodings = ["ascii", "latin-1", "cp1252", "utf-8", "utf-16"]
self.chkrememberwindowsizeandposition = wx.CheckBox(self, -1, "")
self.chkrememberdialogsizesandpositions = wx.CheckBox(self, -1, "")
self.chkrememberpanelsizes = wx.CheckBox(self, -1, "")
self.chkautodetectencoding = wx.CheckBox(self, -1, "")
self.cboEncoding = wx.ComboBox(self, -1, choices=self.encodings)
self.chksaveonrun = wx.CheckBox(self, -1, "")
self.chkchecksyntaxonsave = wx.CheckBox(self, -1, "")
self.txtchecksyntaxextensions = wx.TextCtrl(self, -1, self.grandparent.prefs.checksyntaxextensions, size=(55, -1))
self.chkpromptonsaveall = wx.CheckBox(self, -1, "")
self.chkdoubleclicktoclosetab = wx.CheckBox(self, -1, "")
self.boxiconsize = wx.Choice(self, self.grandparent.ID_ICON_SIZE, wx.Point(225, 135), (-1, -1), ["0", "16", "24"])
self.txtRecentFiles = wx.TextCtrl(self, self.grandparent.ID_TXT_RECENT_FILES, str(self.grandparent.prefs.recentfileslimit), wx.Point(225, 175), (35, -1))
self.chkcheckindentation = wx.CheckBox(self, -1, "")
self.txtpythonargs = wx.TextCtrl(self, -1, self.grandparent.prefs.pythonargs, wx.Point(225, 255), (55, -1))
self.chkenablefeedback = wx.CheckBox(self, -1, "")
self.chkdebugmodus = wx.CheckBox(self, -1, "")
self.chkalwayspromptonexit = wx.CheckBox(self, -1, "")
self.chkbackupfileonsave = wx.CheckBox(self, -1, "")
self.chkCheckFormat = wx.CheckBox(self, -1, "")
self.chkvieweol = wx.CheckBox(self, -1, "")
self.txtdefaultuserprefsdirectory = wx.TextCtrl(self, -1, self.grandparent.GetParent().preferencesdirectory, wx.Point(15, 325), (250, -1))
self.btnBrowseUserPrefsDir = wx.Button(self, self.grandparent.ID_FILE_BROWSE_USER_PREFS_DIR, " &Browse ")
self.txtdefaultcurdirdirectory = wx.TextCtrl(self, -1, self.grandparent.prefs.defaultdirectory, wx.Point(15, 375), (250, -1))
self.btnBrowseCurDir = wx.Button(self, self.grandparent.ID_FILE_BROWSE_CUR_DIR, " &Browse ")
self.btnExportSetup = wx.Button(self, self.grandparent.ID_EXPORT_PREFS, " Export Preferences ")
self.btnImportSetup = wx.Button(self, self.grandparent.ID_IMPORT_PREFS, " Import Preferences ")
self.Add(self.chkrememberwindowsizeandposition, "Remember Window Size And Position:")
self.Add(self.chkrememberdialogsizesandpositions, "Remember Dialog Sizes and Positions:")
self.Add(self.chkrememberpanelsizes, "Remember Panel Sizes:")
self.Add(self.chkautodetectencoding, "Auto Detect Encoding:")
self.Add(self.cboEncoding, "Default Encoding")
self.Add(self.chksaveonrun, "Save On Run:")
self.Add(self.chkchecksyntaxonsave, "Check Syntax On Save:")
self.Add(self.txtchecksyntaxextensions, "Check Syntax: Only On Extensions:")
self.Add(self.chkpromptonsaveall, "Prompt On Save All:")
self.Add(self.chkdoubleclicktoclosetab, "Double Click To Close Tab:")
self.Add(self.txtRecentFiles, "Max number of recent files:")
self.Add(self.chkvieweol, "View Line Endings With Whitespace:")
self.Add(self.chkCheckFormat, "Check Line Ending Format on Open:")
self.Add(self.chkcheckindentation, "Check Indentation Type on Open:")
self.Add(self.txtpythonargs, "Python arguments (eg \"-i\"):")
self.Add(self.boxiconsize, "Toolbar Icon Size:")
self.AddBuffer()
self.AddLabel("Default Preferences Directory:")
self.AddTwoItems(self.txtdefaultuserprefsdirectory, self.btnBrowseUserPrefsDir)
self.AddBuffer()
self.AddLabel("Default Current Working Directory:")
self.AddTwoItems(self.txtdefaultcurdirdirectory, self.btnBrowseCurDir)
self.AddBuffer()
self.Add(self.chkenablefeedback, "Enable Feedback Messages:")
self.Add(self.chkdebugmodus, "Debug Modus:")
self.Add(self.chkalwayspromptonexit, "Always Prompt On Exit:")
self.Add(self.chkbackupfileonsave, "Backup File On Save:")
self.Add(self.btnExportSetup)
self.Add(self.btnImportSetup)
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseUserPrefsDir, id=self.grandparent.ID_FILE_BROWSE_USER_PREFS_DIR)
self.Bind(wx.EVT_BUTTON, self.OnbtnBrowseCurDir, id=self.grandparent.ID_FILE_BROWSE_CUR_DIR)
self.Bind(wx.EVT_TEXT, self.OntxtRecentFiles, id=self.grandparent.ID_TXT_RECENT_FILES)
self.Bind(wx.EVT_BUTTON, self.OnbtnExportPrefs, id=self.grandparent.ID_EXPORT_PREFS)
self.Bind(wx.EVT_BUTTON, self.OnbtnImportPrefs, id=self.grandparent.ID_IMPORT_PREFS)
def reset(self):
self.txtdefaultuserprefsdirectory.SetValue(self.grandparent.GetParent().preferencesdirectory)
self.txtdefaultcurdirdirectory.SetValue(self.grandparent.prefs.defaultdirectory)
self.chkrememberwindowsizeandposition.SetValue(self.grandparent.prefs.rememberwindowsizeandposition)
self.chkrememberdialogsizesandpositions.SetValue(self.grandparent.prefs.rememberdialogsizesandpositions)
self.chkrememberpanelsizes.SetValue(self.grandparent.prefs.rememberpanelsizes)
self.chkautodetectencoding.SetValue(self.grandparent.prefs.autodetectencoding)
self.chksaveonrun.SetValue(self.grandparent.prefs.saveonrun)
self.chkchecksyntaxonsave.SetValue(self.grandparent.prefs.checksyntaxonsave)
self.txtchecksyntaxextensions.SetValue(self.grandparent.prefs.checksyntaxextensions)
self.chkpromptonsaveall.SetValue(self.grandparent.prefs.promptonsaveall)
self.chkdoubleclicktoclosetab.SetValue(self.grandparent.prefs.doubleclicktoclosetab)
self.txtRecentFiles.SetValue(str(self.grandparent.prefs.recentfileslimit))
if self.grandparent.prefs.defaultencoding not in self.encodings:
self.encodings.append(self.grandparent.prefs.defaultencoding)
self.cboEncoding.Append(self.grandparent.prefs.defaultencoding)
self.cboEncoding.SetSelection(self.encodings.index(self.grandparent.prefs.defaultencoding))
self.chkcheckindentation.SetValue(self.grandparent.prefs.checkindentation)
if self.grandparent.prefs.iconsize == 24:
self.boxiconsize.SetSelection(2)
elif self.grandparent.prefs.iconsize == 16:
self.boxiconsize.SetSelection(1)
else:
self.boxiconsize.SetSelection(0)
self.txtpythonargs.SetValue(self.grandparent.prefs.pythonargs)
self.chkenablefeedback.SetValue(self.grandparent.prefs.enablefeedback)
self.chkdebugmodus.SetValue(self.grandparent.prefs.debugmodus)
self.chkalwayspromptonexit.SetValue(self.grandparent.prefs.alwayspromptonexit)
self.chkbackupfileonsave.SetValue(self.grandparent.prefs.backupfileonsave)
self.chkvieweol.SetValue(self.grandparent.prefs.vieweol)
self.chkCheckFormat.SetValue(self.grandparent.prefs.checkeol)
def OnbtnBrowseUserPrefsDir(self, event):
#bug fix by Antonio, 06.03.2007: (removed |wx.DD_NEW_DIR_BUTTON because the style wx.DD_DEFAULT_STYLE already includes wx.DD_NEW_DIR_BUTTON)
d = wx.DirDialog(self, "Select Default User Preferences Directory:", style=wx.DD_DEFAULT_STYLE)
if d.ShowModal() == wx.ID_OK:
self.txtdefaultuserprefsdirectory.SetValue(d.GetPath())
d.Destroy()
def OnbtnBrowseCurDir(self, event):
d = wx.DirDialog(self, "Select Default Current Working Directory:", style=wx.DD_DEFAULT_STYLE)
if d.ShowModal() == wx.ID_OK:
self.txtdefaultcurdirdirectory.SetValue(d.GetPath())
d.Destroy()
def OnbtnExportPrefs(self, event):
import drZip
import zipfile
dlg = drFileDialog.FileDialog(self.drframe, "Export Preferences, Plugins, and DrScripts To", 'Zip File (*.zip)|*.zip', IsASaveDialog=True)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath().replace('\\', '/')
if not filename.endswith(".zip"): #AB: bug of drFileDialog
filename=filename.split('.')[0] + ".zip"
zf = zipfile.ZipFile(filename, 'w')
drZip.AddDirectoryToZipFile(self.drframe.preferencesdirectory, "", zf)
zf.close()
dlg.Destroy()
def OnbtnImportPrefs(self, event):
import drZip
if self.drframe.Ask("This will permanently overwrite all of your preferences, plugins, and drscript file.\n\nProceed?", "Warning"):
dlg = drFileDialog.FileDialog(self.drframe, "Import Preferences, Plugins, and DrScripts From", "Zip File (*.zip)|*.zip")
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath().replace('\\', '/')
drZip.ImportPreferencesFrom(self.drframe.preferencesdirectory, filename)
self.drframe.ShowMessage("Successfully imported preferences, plugins, and drscripts.", "Import Success")
dlg.Destroy()
def OntxtRecentFiles(self, event):
x = self.txtRecentFiles.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txtRecentFiles.SetValue(str(self.grandparent.prefs.recentfileslimit))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txtRecentFiles.SetValue(str(self.grandparent.prefs.recentfileslimit))
return
if y > 25:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
class PluginsPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 1)
self.txtdefaultdirectory = wx.TextCtrl(self, -1, self.grandparent.prefs.pluginsdirectory, wx.Point(15, 325), (250, -1))
self.PluginsbtnBrowse = wx.Button(self, self.grandparent.ID_PLUGINS_BROWSE, " &Browse ")
self.AddLabel("Default Directory:")
self.AddTwoItems(self.txtdefaultdirectory, self.PluginsbtnBrowse)
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnPBrowse, id=self.grandparent.ID_PLUGINS_BROWSE)
def reset(self):
self.txtdefaultdirectory.SetValue(self.grandparent.prefs.pluginsdirectory)
def OnbtnPBrowse(self, event):
d = wx.DirDialog(self, "Select Default Directory For Plugins:", style=wx.DD_DEFAULT_STYLE|wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)
if d.ShowModal() == wx.ID_OK:
self.txtdefaultdirectory.SetValue(d.GetPath())
d.Destroy()
class PrintPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 3)
self.chkdoclinenumbers = wx.CheckBox(self, -1, "")
self.chkpromptlinenumbers = wx.CheckBox(self, -1, "")
self.txttabwidth = wx.TextCtrl(self, self.grandparent.ID_PRINT_TAB_WIDTH, str(self.grandparent.prefs.printtabwidth), wx.Point(225, 215), (35, -1))
self.Add(self.chkdoclinenumbers, "Document Line Numbers:")
self.Add(self.chkpromptlinenumbers, "Prompt Line Numbers:")
self.Add(self.txttabwidth, "Tab Width:")
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_TEXT, self.Ontxttabwidth, id=self.grandparent.ID_PRINT_TAB_WIDTH)
def reset(self):
self.chkdoclinenumbers.SetValue(self.grandparent.prefs.printdoclinenumbers)
self.chkpromptlinenumbers.SetValue(self.grandparent.prefs.printpromptlinenumbers)
self.txttabwidth.SetValue(str(self.grandparent.prefs.printtabwidth))
def Ontxttabwidth(self, event):
x = self.txttabwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.printtabwidth))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.printtabwidth))
return
if y > 32:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
class PromptPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 8)
self.ID_TABWIDTH = 750
self.radusestyles = wx.RadioBox(self, -1, "Styles:", wx.DefaultPosition, wx.DefaultSize, ["Don't Use Styles", "Use Styles", "Only Use \"Normal\", \"Caret Foreground\""], 1, wx.RA_SPECIFY_COLS)
self.btnStyle = wx.Button(self, self.grandparent.ID_PROMPT_STYLE, " Edit Text Styles ")
self.btnApplyProperty = wx.Button(self, self.grandparent.ID_PROMPT_APPLY_PROPERTY, " Apply Text Property To All Styles ")
self.txtmarginwidth = wx.TextCtrl(self, self.grandparent.ID_PROMPT_MARGIN_WIDTH, str(self.grandparent.prefs.promptmarginwidth), wx.Point(225, 215), (35, -1))
self.chkVisible = wx.CheckBox(self, -1, "")
self.chkpromptusetabs = wx.CheckBox(self, -1, "")
self.chkwordwrap = wx.CheckBox(self, -1, "")
self.txtcaretwidth = wx.TextCtrl(self, self.grandparent.ID_PROMPT_CARET_WIDTH, str(self.grandparent.prefs.promptcaretwidth), wx.Point(225, 215), (35, -1))
self.chkWhitespace = wx.CheckBox(self, -1, "")
self.chkscrollextrapage = wx.CheckBox(self, -1, "")
self.sldrSize = wx.Slider(self, -1, self.grandparent.prefs.promptsize, 25, 100, wx.Point(150, 55), (75, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
self.sldrSize.SetTickFreq(25, 1)
self.txttabwidth = wx.TextCtrl(self, self.ID_TABWIDTH, "", wx.Point(225, 215), (35, -1))
self.radFormat = wx.Choice(self, -1, wx.Point(15, 80), wx.DefaultSize, [" Unix ('\\n') "," DOS/Windows ('\\r\\n') "," Mac ('\\r') "])
self.txtStartupScript = wx.TextCtrl(self, -1, self.grandparent.prefs.promptstartupscript, wx.Point(225, 215), (250, 150), wx.TE_MULTILINE)
self.Add(self.btnStyle)
self.Add(self.btnApplyProperty)
self.Add(self.radusestyles)
self.Add(self.txtmarginwidth, "Line Number Margin Width:")
self.Add(self.chkVisible, "Visible By Default:")
self.Add(self.txttabwidth, "Tab Width:")
self.Add(self.chkpromptusetabs, "Use Tabs:")
self.Add(self.radFormat, "Line Ending Format:")
self.Add(self.chkwordwrap, "Word Wrap:")
self.Add(self.txtcaretwidth, "Caret Width:")
self.Add(self.chkWhitespace, "Whitespace is Visible on Startup:")
self.Add(self.chkscrollextrapage, "Scroll Extra Page:")
self.Add(self.sldrSize, "Vertical Size:")
self.AddLabel("Startup Script:")
self.Add(self.txtStartupScript)
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnStyle, id=self.grandparent.ID_PROMPT_STYLE)
self.Bind(wx.EVT_BUTTON, self.OnbtnApplyProperty, id=self.grandparent.ID_PROMPT_APPLY_PROPERTY)
self.Bind(wx.EVT_TEXT, self.Ontxtmarginwidth, id=self.grandparent.ID_PROMPT_MARGIN_WIDTH)
self.Bind(wx.EVT_TEXT, self.Ontxtcaretwidth, id=self.grandparent.ID_PROMPT_CARET_WIDTH)
self.Bind(wx.EVT_TEXT, self.Ontxttabwidth, id=self.ID_TABWIDTH)
def reset(self):
self.txttabwidth.SetValue(str(self.grandparent.prefs.prompttabwidth))
self.radFormat.SetSelection(self.grandparent.prefs.prompteolmode)
self.radusestyles.SetSelection(self.grandparent.prefs.promptusestyles)
self.txtmarginwidth.SetValue(str(self.grandparent.prefs.promptmarginwidth))
self.chkVisible.SetValue(self.grandparent.prefs.promptisvisible)
self.chkpromptusetabs.SetValue(self.grandparent.prefs.promptusetabs)
self.chkwordwrap.SetValue(self.grandparent.prefs.promptwordwrap)
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.promptcaretwidth))
self.chkWhitespace.SetValue(self.grandparent.prefs.promptwhitespaceisvisible)
self.sldrSize.SetValue(self.grandparent.prefs.promptsize)
self.chkscrollextrapage.SetValue(self.grandparent.prefs.promptscrollextrapage)
self.txtStartupScript.SetValue(self.grandparent.prefs.promptstartupscript)
def OnbtnStyle(self, event):
d = drStyleDialog(self, -1, "Edit Prompt Styles", True)
d.ShowModal()
if d.ClickedOk():
self.grandparent.prefs.txtPromptStyleDictionary = d.GetArrays()
d.Destroy()
def OnbtnApplyProperty(self, event):
d = wx.SingleChoiceDialog(self, "Select the property you wish to apply to all styles:", "Apply Property To All Styles", ["Font", "Size", "Background", "Foreground"], wx.OK|wx.CANCEL)
answer = d.ShowModal()
s = d.GetStringSelection()
d.Destroy()
if answer == wx.ID_OK:
if s == "Font":
prop = "face"
dummy = ",face:terminal"
elif s == "Size":
prop = "size"
dummy = ",size:10"
elif s == "Background":
prop = "back"
dummy = ",back:#000000"
elif s == "Foreground":
prop = "fore"
dummy = ",fore:#FFFFFF"
l = len(self.grandparent.prefs.txtPromptStyleDictionary) - 3
#ignore caret foreground, selections
x = 2
#Ignore default text, and line number text (0, and 1)
bstring = getStyleProperty(prop, self.grandparent.prefs.txtPromptStyleDictionary[0])
while x < l:
tstring = self.grandparent.prefs.txtPromptStyleDictionary[x]
#self.grandparent.prefs.txtPromptStyleDictionary.pop(x)
try:
tstring.index(prop)
except:
tstring = tstring + dummy
self.grandparent.prefs.txtPromptStyleDictionary[x] = setStyleProperty(prop, tstring, bstring)
x = x + 1
def Ontxtcaretwidth(self, event):
x = self.txtcaretwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.promptcaretwidth))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txtcaretwidth.SetValue(str(self.grandparent.prefs.promptcaretwidth))
return
if y > 256:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
def Ontxtmarginwidth(self, event):
x = self.txtmarginwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txtmarginwidth.SetValue(str(self.grandparent.prefs.promptmarginwidth))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txtmarginwidth.SetValue(str(self.grandparent.prefs.promptmarginwidth))
return
if y > 1024:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
def Ontxttabwidth(self, event):
x = self.txttabwidth.GetValue()
if not x:
return
try:
y = int(x)
except ValueError:
drScrolledMessageDialog.ShowMessage(self, ("Whatever you are trying to do... Stop it.\nIt won't work. Positive Numbers only please.\nDrPython will reset to the value last loaded."), "Value Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.prompttabwidth))
return
except TypeError:
drScrolledMessageDialog.ShowMessage(self, ("\"" + y + "\" is not an integer (a number, eg 2, 4, 568)\nDrPython will reset to the value last loaded."), "Type Error")
self.txttabwidth.SetValue(str(self.grandparent.prefs.prompttabwidth))
return
if y > 1024:
drScrolledMessageDialog.ShowMessage(self, ("DrPython does not recommend going this high. You can of course..."), "Hmmmm")
class SidePanelPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 4)
self.sldrSizeLeft = wx.Slider(self, -1, self.grandparent.prefs.sidepanelleftsize, 15, 100, wx.Point(150, 55), (75, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
self.sldrSizeLeft.SetTickFreq(25, 1)
self.sldrSizeRight = wx.Slider(self, -1, self.grandparent.prefs.sidepanelrightsize, 15, 100, wx.Point(150, 55), (75, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
self.sldrSizeRight.SetTickFreq(25, 1)
self.sldrSizeTop = wx.Slider(self, -1, self.grandparent.prefs.sidepaneltopsize, 15, 100, wx.Point(150, 55), (75, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
self.sldrSizeTop.SetTick(15)
self.sldrSizeTop.SetTickFreq(25, 1)
self.Add(self.sldrSizeLeft, "Left Panel Size:")
self.Add(self.sldrSizeRight, "Right Panel Size:")
self.Add(self.sldrSizeTop, "Top Panel Size:")
self.SetPanelSizer()
self.reset()
def reset(self):
self.sldrSizeLeft.SetValue(self.grandparent.prefs.sidepanelleftsize)
self.sldrSizeRight.SetValue(self.grandparent.prefs.sidepanelrightsize)
self.sldrSizeTop.SetValue(self.grandparent.prefs.sidepaneltopsize)
class SourceBrowserPanel(PrefsPanel):
def __init__(self, parent, id, name):
PrefsPanel.__init__(self, parent, id, name, 4)
self.btnCStyle = wx.Button(self, self.grandparent.ID_CLASS_BROWSER_STYLE, " Edit Source Browser Style ")
self.positionchooser = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, ["Left", "Right", "Top"], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
self.sldrSize = wx.Slider(self, -1, self.grandparent.prefs.sourcebrowsersize, 1, 100, wx.Point(150, 55), (75, -1), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
self.sldrSize.SetTickFreq(1, 1)
self.chkIsVisible = wx.CheckBox(self, -1, "")
self.chkcloseonactivate = wx.CheckBox(self, -1, "")
self.chkissorted = wx.CheckBox(self, -1, "")
self.chkautorefreshonsave = wx.CheckBox(self, -1, "")
self.chkautorefresh = wx.CheckBox(self, -1, "")
self.chkuseimages = wx.CheckBox(self, -1, "")
self.Add(self.btnCStyle)
self.AddLabel("")
self.AddLabel("Panel Position:")
self.Add(self.positionchooser)
self.Add(self.sldrSize, "Panel Size:")
self.Add(self.chkIsVisible, "Visible By Default:")
self.Add(self.chkcloseonactivate, "Close On Activate:")
self.Add(self.chkissorted, "Sorted (Alphabetical):")
self.Add(self.chkautorefreshonsave, "Auto Refresh On Save:")
self.Add(self.chkautorefresh, "Auto Refresh:")
self.Add(self.chkuseimages, "Use Images:")
self.SetPanelSizer()
self.reset()
self.Bind(wx.EVT_BUTTON, self.OnbtnCStyle, id=self.grandparent.ID_CLASS_BROWSER_STYLE)
def reset(self):
self.positionchooser.SetSelection(self.grandparent.prefs.sourcebrowserpanel)
self.sldrSize.SetValue(self.grandparent.prefs.sourcebrowsersize)
self.chkIsVisible.SetValue(self.grandparent.prefs.sourcebrowserisvisible)
self.chkcloseonactivate.SetValue(self.grandparent.prefs.sourcebrowsercloseonactivate)
self.chkissorted.SetValue(self.grandparent.prefs.sourcebrowserissorted)
self.chkautorefreshonsave.SetValue(self.grandparent.prefs.sourcebrowserautorefreshonsave)
self.chkautorefresh.SetValue(self.grandparent.prefs.sourcebrowserautorefresh)
self.chkuseimages.SetValue(self.grandparent.prefs.sourcebrowseruseimages)
def OnbtnCStyle(self, event):
d = drSimpleStyleDialog(self, -1, ("Style: Source Browser"), self.grandparent.prefs.sourcebrowserstyle, self.grandparent.prefs.sourcebrowserstyle)
d.ShowModal()
if d.ClickedOk():
self.grandparent.prefs.sourcebrowserstyle = d.GetStyleString()
d.Destroy()
class drPrefsDialog(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, (640, 480), wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER)
self.parent = parent
self.ID_PAGES = 100
self.ID_CLOSE = 101
self.ID_RESET = 102
self.ID_UPDATE = 103
self.ID_SAVE = 104
self.ID_HELP = 105
self.ID_FILE_BROWSE_USER_PREFS_DIR = 109
self.ID_TEXT_TYPE = 110
self.ID_FILE_STYLE = 111
self.ID_APPLY_PROPERTY = 112
self.ID_DOC_MARGIN_WIDTH = 113
self.ID_FILE_BROWSE_CUR_DIR = 114
self.ID_DOC_CARET_WIDTH = 1235
self.ID_PROMPT_CARET_WIDTH = 1237
self.ID_LONGLINE_COL = 116
self.ID_ICON_SIZE = 350
self.ID_PROMPT_STYLE = 1140
self.ID_PROMPT_MARGIN_WIDTH = 115
self.ID_PROMPT_TEXT_TYPE = 117
self.ID_PROMPT_APPLY_PROPERTY = 118
self.ID_CLASS_BROWSER_STYLE = 201
self.ID_BOOKMARKS_STYLE = 202
self.ID_DRSCRIPT_STYLE = 203
self.ID_DRSCRIPT_BROWSE = 211
self.ID_PLUGINS_BROWSE = 212
self.ID_PRINT_TAB_WIDTH = 251
self.ID_DOCUMENTATION_BROWSE = 231
self.ID_DOCUMENTATION_BROWSE_P = 232
self.ID_DOCUMENTATION_BROWSE_W = 233
self.ID_DOCUMENTATION_BROWSE_R = 234
self.ID_TXT_RECENT_FILES = 301
self.ID_TXT_TAB_WIDTH = 302
self.ID_USE_TABS = 303
self.ID_RESET_PANEL = 405
self.ID_LB_PREFS = 505
self.ID_EXPORT_PREFS = 501
self.ID_IMPORT_PREFS = 502
self.ID_BTN_WILDCARD = 510
self.ID_BTN_LNK_REPLACE_TABLE = 511
self.prefs = drPreferences(self.parent, parent.PLATFORM_IS_WIN, parent.programdirectory)
self.prefs.Copy(parent.prefs)
self.oldprefs = drPreferences(self.parent, parent.PLATFORM_IS_WIN, parent.programdirectory)
self.oldprefs.Copy(parent.prefs)
self.lbPrefs = drPrefsBook(self, self.ID_LB_PREFS, (600, 400))
self.pnlGeneral = GeneralPanel(self.lbPrefs, -1, "General")
self.pnlBookmarks = BookmarksPanel(self.lbPrefs, -1, "Bookmarks")
self.pnlDocument = DocumentPanel(self.lbPrefs, -1, "Document")
self.pnlDocumentation = DocumentationPanel(self.lbPrefs, -1, "Documentation")
self.pnlDragAndDrop = DragAndDropPanel(self.lbPrefs, -1, "Drag and Drop")
self.pnlDrScript = DrScriptPanel(self.lbPrefs, -1, "DrScript")
self.pnlFileDialog = FileDialogPanel(self.lbPrefs, -1, "File Dialog")
self.pnlFileTypes = FileTypesPanel(self.lbPrefs, -1, "File Types")
self.pnlFindReplace = FindReplacePanel(self.lbPrefs, -1, "Find/Replace")
self.pnlPlugins = PluginsPanel(self.lbPrefs, -1, "Plugins")
self.pnlPrint = PrintPanel(self.lbPrefs, -1, "Printing")
self.pnlPrompt = PromptPanel(self.lbPrefs, -1, "Prompt")
self.pnlSidePanels = SidePanelPanel(self.lbPrefs, -1, "Side Panels")
self.pnlSourceBrowser = SourceBrowserPanel(self.lbPrefs, -1, "Source Browser")
self.lbPrefs.AddPage(self.pnlGeneral, "General")
self.lbPrefs.AddPage(self.pnlBookmarks, "Bookmarks")
self.lbPrefs.AddPage(self.pnlDocument, "Document")
self.lbPrefs.AddPage(self.pnlDocumentation, "Documentation")
self.lbPrefs.AddPage(self.pnlDragAndDrop, "Drag And Drop")
self.lbPrefs.AddPage(self.pnlDrScript, "DrScript")
self.lbPrefs.AddPage(self.pnlFileDialog, "File Dialog")
self.lbPrefs.AddPage(self.pnlFileTypes, "File Types")
self.lbPrefs.AddPage(self.pnlFindReplace, "Find/Replace")
self.lbPrefs.AddPage(self.pnlPlugins, "Plugins")
self.lbPrefs.AddPage(self.pnlPrint, "Printing")
self.lbPrefs.AddPage(self.pnlPrompt, "Prompt")
self.lbPrefs.AddPage(self.pnlSidePanels, "Side Panels")
self.lbPrefs.AddPage(self.pnlSourceBrowser, "Source Browser")
self.lbPrefs.ShowPanel(parent.prefdialogposition)
self.theSizer = wx.BoxSizer(wx.VERTICAL)
self.buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
self.btnClose = wx.Button(self, self.ID_CLOSE, " &Close ")
self.btnClose.SetDefault()
self.btnHelp = wx.Button(self, self.ID_HELP, " &Help ")
self.btnReset = wx.Button(self, self.ID_RESET, " &Reset All ")
self.btnUpdate = wx.Button(self, self.ID_UPDATE, " &Update ")
self.btnSave = wx.Button(self, self.ID_SAVE, " &Save ")
self.buttonSizer.Add(self.btnClose, 0, wx.ALL|wx.EXPAND, 4)
self.buttonSizer.Add(self.btnHelp, 0, wx.ALL|wx.EXPAND, 4)
self.buttonSizer.Add(self.btnReset, 0, wx.ALL|wx.EXPAND, 4)
self.buttonSizer.Add(self.btnUpdate, 0, wx.ALL|wx.EXPAND, 4)
self.buttonSizer.Add(self.btnSave, 0, wx.ALL|wx.EXPAND, 4)
#self.theSizer.Add(self.lbPrefs, 1, wx.ALL|wx.EXPAND, 4)
#if border is used, the right scrollbar doesn't show entirely (!)
self.theSizer.Add(self.lbPrefs, 1, wx.EXPAND)
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.SHAPED | wx.ALIGN_CENTER)
self.theSizer.Add(self.buttonSizer, 0, wx.SHAPED | wx.ALIGN_CENTER)
self.SetAutoLayout(True)
self.SetSizer(self.theSizer)
self.Bind(wx.EVT_BUTTON, self.OnbtnClose, id=self.ID_CLOSE)
self.Bind(wx.EVT_BUTTON, self.OnbtnHelp, id=self.ID_HELP)
self.Bind(wx.EVT_BUTTON, self.OnbtnReset, id=self.ID_RESET)
self.Bind(wx.EVT_BUTTON, self.OnbtnUpdate, id=self.ID_UPDATE)
self.Bind(wx.EVT_BUTTON, self.OnbtnSave, id=self.ID_SAVE)
parent.LoadDialogSizeAndPosition(self, "preferencesdialog.sizeandposition.dat")
if parent.PLATFORM_IS_GTK: #does not get initially the focus (bug tracker #1903778, "Open Imported Module: focus problem", 29.02.2008: from Jon White, thanks.
self.SetFocus()
def OnCloseW(self, event):
self.parent.SaveDialogSizeAndPosition(self, "preferencesdialog.sizeandposition.dat")
if event is not None:
event.Skip()
def OnbtnClose(self, event):
self.OnCloseW(None)
self.EndModal(0)
def OnbtnHelp(self, event):
self.parent.ViewURLInBrowser("/usr/share/doc/drpython/documentation/preferences.html")
def OnbtnReset(self, event):
answer = wx.MessageBox("This will reset all preferences to the program default.\n(You still need to click update and/or save)\nAre you sure you want to do this?", "Reset Preferences", wx.YES_NO | wx.ICON_QUESTION)
if answer == wx.YES:
self.prefs.reset()
self.pnlSourceBrowser.reset()
self.pnlDocument.reset()
self.pnlDocumentation.reset()
self.pnlDrScript.reset()
self.pnlFindReplace.reset()
self.pnlFileTypes.reset()
self.pnlGeneral.reset()
self.pnlPlugins.reset()
self.pnlPrint.reset()
self.pnlPrompt.reset()
self.pnlSidePanels.reset()
def OnbtnResetPanel(self, event):
answer = wx.MessageBox("This will reset all of this panel's preferences to the program default.\n\
(You still need to click update and/or save)\nAre you sure you want to do this?", "Reset Panel Preferences", wx.YES_NO | wx.ICON_QUESTION)
if answer == wx.YES:
panel = event.GetEventObject().GetParent()
self.prefs.resetjust(panel.GetName())
panel.reset()
def OnbtnUpdate(self, event):
self.parent.prefs = self.GetPreferences()
self.parent.updatePrefs(self.oldprefs)
self.oldprefs.Copy(self.prefs)
if self.parent.prefs.enablefeedback:
drScrolledMessageDialog.ShowMessage(self, ("Succesfully updated the current instance of DrPython.\nClick Save to make it permanent."), "Updated Preferences")
def OnbtnSave(self, event):
self.parent.prefs = self.GetPreferences()
self.parent.WriteUserPreferencesDirectoryFile()
if not os.path.exists(self.parent.preferencesdirectory):
drScrolledMessageDialog.ShowMessage(self, "Your userpreferencesdirectory '" + self.parent.preferencesdirectory + "' does not exist.", "DrPython Error")
return
preffile = self.parent.prefsfile
try:
drPrefsFile.WritePreferences(self.GetPreferences(), preffile)
except IOError:
drScrolledMessageDialog.ShowMessage(self, "There were some problems writing to:\n" + preffile, "Write Error")
return
self.parent.updatePrefs(self.oldprefs)
self.oldprefs.Copy(self.prefs)
if self.parent.prefs.enablefeedback:
drScrolledMessageDialog.ShowMessage(self, ("Succesfully wrote to:\n" + preffile + "\nand updated the current instance of DrPython."), "Saved Preferences")
def GetPreferences(self):
#General
self.prefs.rememberwindowsizeandposition = int(self.pnlGeneral.chkrememberwindowsizeandposition.GetValue())
self.prefs.rememberdialogsizesandpositions = int(self.pnlGeneral.chkrememberdialogsizesandpositions.GetValue())
self.prefs.rememberpanelsizes = int(self.pnlGeneral.chkrememberpanelsizes.GetValue())
self.prefs.autodetectencoding = int(self.pnlGeneral.chkautodetectencoding.GetValue())
self.prefs.defaultencoding = self.pnlGeneral.cboEncoding.GetValue()
self.prefs.saveonrun = int(self.pnlGeneral.chksaveonrun.GetValue())
self.prefs.checksyntaxonsave = int(self.pnlGeneral.chkchecksyntaxonsave.GetValue())
self.prefs.checksyntaxextensions = self.pnlGeneral.txtchecksyntaxextensions.GetValue()
self.prefs.promptonsaveall = int(self.pnlGeneral.chkpromptonsaveall.GetValue())
self.prefs.doubleclicktoclosetab = int(self.pnlGeneral.chkdoubleclicktoclosetab.GetValue())
self.prefs.recentfileslimit = self.pnlGeneral.txtRecentFiles.GetValue()
if not self.prefs.recentfileslimit:
self.prefs.recentfileslimit = self.oldprefs.recentfileslimit
self.prefs.recentfileslimit = int(self.prefs.recentfileslimit)
self.prefs.iconsize = int(self.pnlGeneral.boxiconsize.GetStringSelection())
self.prefs.pythonargs = self.pnlGeneral.txtpythonargs.GetValue()
self.parent.preferencesdirectory = self.pnlGeneral.txtdefaultuserprefsdirectory.GetValue().replace('\\', '/')
self.prefs.defaultdirectory = self.pnlGeneral.txtdefaultcurdirdirectory.GetValue().replace('\\', '/')
#Plugins
self.prefs.pluginsdirectory = self.pnlPlugins.txtdefaultdirectory.GetValue().replace('\\', '/')
#DrScript
self.prefs.drscriptsdirectory = self.pnlDrScript.txtdefaultdirectory.GetValue().replace('\\', '/')
self.parent.SetDrPythonDirectories()
self.prefs.drscriptloadexamples = int(self.pnlDrScript.chkloadexamples.GetValue())
self.prefs.enablefeedback = int(self.pnlGeneral.chkenablefeedback.GetValue())
self.prefs.debugmodus = wx.GetApp().debugmodus = int(self.pnlGeneral.chkdebugmodus.GetValue())
self.prefs.alwayspromptonexit = int(self.pnlGeneral.chkalwayspromptonexit.GetValue())
self.prefs.backupfileonsave = int(self.pnlGeneral.chkbackupfileonsave.GetValue())
self.prefs.checkindentation = int(self.pnlGeneral.chkcheckindentation.GetValue())
self.prefs.checkeol = int(self.pnlGeneral.chkCheckFormat.GetValue())
self.prefs.vieweol = int(self.pnlGeneral.chkvieweol.GetValue())
#Drag and Drop
self.prefs.draganddropmode = self.pnlDragAndDrop.raddraganddropmode.GetSelection()
self.prefs.draganddroptextmode = self.pnlDragAndDrop.raddraganddroptextmode.GetSelection()
#File Types:
self.prefs.extensions = self.pnlFileTypes.extensions.copy()
self.prefs.docusetabs = self.pnlFileTypes.docusetabs.copy()
self.prefs.docuseintellibackspace = self.pnlFileTypes.docuseintellibackspace.copy()
self.prefs.docremovetrailingwhitespace= self.pnlFileTypes.docremovetrailingwhitespace.copy()
self.prefs.doctabwidth = self.pnlFileTypes.doctabwidth.copy()
self.prefs.doceolmode = self.pnlFileTypes.doceolmode.copy()
self.prefs.docfolding = self.pnlFileTypes.docfolding.copy()
self.prefs.doccommentstring = self.pnlFileTypes.doccommentstring.copy()
self.prefs.docwordwrap = self.pnlFileTypes.docwordwrap.copy()
#File Dialog
self.prefs.usewxfiledialog = int(self.pnlFileDialog.chkusewxfiledialog.GetValue())
self.prefs.defaultextension = int(self.pnlFileDialog.chkdefaultextension.GetValue())
#Document
self.prefs.docshowlinenumbers = int(self.pnlDocument.chkdocshowlinenumbers.GetValue())
self.prefs.docparenthesismatching = int(self.pnlDocument.chkdocparenthesismatching.GetValue())
self.prefs.docupdateindentation = int(self.pnlDocument.chkdocupdateindentation.GetValue())
self.prefs.docautoindent = self.pnlDocument.raddocautoindent.GetSelection()
#self.prefs.docremovetrailingwhitespace = int(self.pnlDocument.chkdocremovetrailingwhitespace.GetValue())
self.prefs.docautoreload = int(self.pnlDocument.chkdocautoreload.GetValue())
self.prefs.docusefileindentation = int(self.pnlDocument.chkdocusefileindentation.GetValue())
self.prefs.docwhitespaceisvisible = int(self.pnlDocument.chkWhitespace.GetValue())
self.prefs.docusestyles = self.pnlDocument.radusestyles.GetSelection()
self.prefs.docuseindentationguides = int(self.pnlDocument.chkuseindentationguides.GetValue())
self.prefs.doccommentmode = self.pnlDocument.raddoccommentmode.GetSelection()
self.prefs.doccaretwidth = self.pnlDocument.txtcaretwidth.GetValue()
if not self.prefs.doccaretwidth:
self.prefs.doccaretwidth = self.oldprefs.doccaretwidth
self.prefs.doccaretwidth = int(self.prefs.doccaretwidth)
self.prefs.dochighlightcurrentline = int(self.pnlDocument.chkhighlightcurrentline.GetValue())
self.prefs.docignorectrlpageupdown = int(self.pnlDocument.chkignorectrlpageupdown.GetValue())
self.prefs.docignoretextfunctionkeys = int(self.pnlDocument.chkignoretextfunctionkeys.GetValue())
#Chris McDonough (I added the txt prefix)
self.prefs.doclonglinecol = self.pnlDocument.txtdoclonglinecol.GetValue()
if not self.prefs.doclonglinecol:
self.prefs.doclonglinecol = self.oldprefs.doclonglinecol
self.prefs.doclonglinecol = int(self.prefs.doclonglinecol)
#/Chris McDonough
self.prefs.docscrollextrapage = int(self.pnlDocument.chkscrollextrapage.GetValue())
self.prefs.docdefaultsyntaxhighlighting = self.pnlDocument.boxdefaultsyntaxhighlighting.GetSelection()
self.prefs.doconlyusedefaultsyntaxhighlighting = self.pnlDocument.chkonlyusedefaultsyntaxhighlighting.GetValue()
#Prompt
self.prefs.prompttabwidth = self.pnlPrompt.txttabwidth.GetValue()
if not self.prefs.prompttabwidth:
self.prefs.prompttabwidth = self.oldprefs.prompttabwidth
self.prefs.prompttabwidth = int(self.prefs.prompttabwidth)
self.prefs.prompteolmode = self.pnlPrompt.radFormat.GetSelection()
self.prefs.promptmarginwidth = self.pnlPrompt.txtmarginwidth.GetValue()
if not self.prefs.promptmarginwidth:
self.prefs.promptmarginwidth = self.oldprefs.promptmarginwidth
self.prefs.promptmarginwidth = int(self.prefs.promptmarginwidth)
self.prefs.promptusetabs = int(self.pnlPrompt.chkpromptusetabs.GetValue())
self.prefs.promptisvisible = int(self.pnlPrompt.chkVisible.GetValue())
self.prefs.promptsize = int(self.pnlPrompt.sldrSize.GetValue())
self.prefs.promptwordwrap = int(self.pnlPrompt.chkwordwrap.GetValue())
self.prefs.promptcaretwidth = self.pnlPrompt.txtcaretwidth.GetValue()
if not self.prefs.promptcaretwidth:
self.prefs.promptcaretwidth = self.oldprefs.promptcaretwidth
self.prefs.promptcaretwidth = int(self.prefs.promptcaretwidth)
self.prefs.promptwhitespaceisvisible = int(self.pnlPrompt.chkWhitespace.GetValue())
self.prefs.promptusestyles = self.pnlPrompt.radusestyles.GetSelection()
self.prefs.promptscrollextrapage = int(self.pnlPrompt.chkscrollextrapage.GetValue())
self.prefs.promptstartupscript = self.pnlPrompt.txtStartupScript.GetValue()
#Find/Replace
self.prefs.findreplaceregularexpression = int(self.pnlFindReplace.chkregularexpression.GetValue())
self.prefs.findreplacematchcase = int(self.pnlFindReplace.chkmatchcase.GetValue())
self.prefs.findreplacefindbackwards = int(self.pnlFindReplace.chkfindbackwards.GetValue())
self.prefs.findreplacewholeword = int(self.pnlFindReplace.chkwholeword.GetValue())
self.prefs.findreplaceinselection = int(self.pnlFindReplace.chkinselection.GetValue())
self.prefs.findreplacefromcursor = int(self.pnlFindReplace.chkfromcursor.GetValue())
self.prefs.findreplacepromptonreplace = int(self.pnlFindReplace.chkpromptonreplace.GetValue())
self.prefs.findreplaceautowrap = int(self.pnlFindReplace.chkfindreplaceautowrap.GetValue())
self.prefs.findreplaceundercursor = int(self.pnlFindReplace.chkundercursor.GetValue())
#Side Panels
self.prefs.sidepanelleftsize = int(self.pnlSidePanels.sldrSizeLeft.GetValue())
self.prefs.sidepanelrightsize = int(self.pnlSidePanels.sldrSizeRight.GetValue())
self.prefs.sidepaneltopsize = int(self.pnlSidePanels.sldrSizeTop.GetValue())
#Source Browser
self.prefs.sourcebrowserpanel = self.pnlSourceBrowser.positionchooser.GetSelection()
self.prefs.sourcebrowsersize = self.pnlSourceBrowser.sldrSize.GetValue()
self.prefs.sourcebrowserisvisible = int(self.pnlSourceBrowser.chkIsVisible.GetValue())
self.prefs.sourcebrowsercloseonactivate = int(self.pnlSourceBrowser.chkcloseonactivate.GetValue())
self.prefs.sourcebrowserissorted = int(self.pnlSourceBrowser.chkissorted.GetValue())
self.prefs.sourcebrowserautorefreshonsave = int(self.pnlSourceBrowser.chkautorefreshonsave.GetValue())
self.prefs.sourcebrowserautorefresh = int(self.pnlSourceBrowser.chkautorefresh.GetValue())
self.prefs.sourcebrowseruseimages = int(self.pnlSourceBrowser.chkuseimages.GetValue())
#Printing
self.prefs.printdoclinenumbers = int(self.pnlPrint.chkdoclinenumbers.GetValue())
self.prefs.printpromptlinenumbers = int(self.pnlPrint.chkpromptlinenumbers.GetValue())
self.prefs.printtabwidth = self.pnlPrint.txttabwidth.GetValue()
if not self.prefs.printtabwidth:
self.prefs.printtabwidth = self.oldprefs.printtabwidth
self.prefs.printtabwidth = int(self.prefs.printtabwidth)
#Documentation
self.prefs.documentationbrowser = self.pnlDocumentation.txtbrowser.GetValue()
self.prefs.documentationpythonlocation = self.pnlDocumentation.txtpython.GetValue()
self.prefs.documentationwxwidgetslocation = self.pnlDocumentation.txtwxwidgets.GetValue()
self.prefs.documentationrehowtolocation = self.pnlDocumentation.txtrehowto.GetValue()
if self.prefs.defaultencoding:
reload(sys) #this is needed because of wine and linux
sys.setdefaultencoding(self.prefs.defaultencoding)
wx.SetDefaultPyEncoding(str(self.prefs.defaultencoding))
#sys.setappdefaultencoding(self.prefs.defaultencoding)
return self.prefs
|