| Conditions | 2 |
| Total Lines | 167 |
| Code Lines | 135 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # |
||
| 423 | def createUI(self): |
||
| 424 | screenWidth, screenHeight = gdata.scrnSize |
||
| 425 | # size of dialog in layout metrics (for SimpleGridLM) |
||
| 426 | cols = 33 |
||
| 427 | rows = 18 |
||
| 428 | # dialog width and height in pixels |
||
| 429 | width = cols * 20 + 5 |
||
| 430 | height = rows * 20 + 4 |
||
| 431 | #creating dialog window |
||
| 432 | self.win = ui.Window(self.app, |
||
| 433 | modal = 1, |
||
| 434 | escKeyClose = 1, |
||
| 435 | movable = 0, |
||
| 436 | title = _("Options"), |
||
| 437 | rect = ui.Rect((screenWidth - width) / 2, (screenHeight - height) / 2, width, height), |
||
| 438 | layoutManager = ui.SimpleGridLM(), |
||
| 439 | tabChange = True |
||
| 440 | ) |
||
| 441 | self.win.subscribeAction('*', self) |
||
| 442 | # first row is window title |
||
| 443 | rows -= 1 |
||
| 444 | |||
| 445 | # Resolution |
||
| 446 | ui.Title(self.win, layout = (1, 1, 5, 1), text = _('Resolution'), |
||
| 447 | align = ui.ALIGN_NONE, font = 'normal-bold') |
||
| 448 | |||
| 449 | ui.Button(self.win, layout = (1, 2, 5, 1), id = "vResolution", align = ui.ALIGN_W) |
||
| 450 | ui.ActiveLabel(self.win, layout = (1, 3, 5, 1), id = "vResolution2") |
||
| 451 | width = 304 # 15 * 20 + 4 |
||
| 452 | height = 264 # 13 * 20 + 4 |
||
| 453 | self.reswin = ui.Window(self.app, |
||
| 454 | modal = 1, |
||
| 455 | escKeyClose = 1, |
||
| 456 | titleOnly = 0, |
||
| 457 | movable = 0, |
||
| 458 | title = _("Select resolution"), |
||
| 459 | rect = ui.Rect((screenWidth - width) / 2, (screenHeight - height) / 2, width, height), |
||
| 460 | layoutManager = ui.SimpleGridLM(), |
||
| 461 | ) |
||
| 462 | self.reswin.subscribeAction('*', self) |
||
| 463 | # rename |
||
| 464 | ui.Listbox(self.reswin, layout = (0, 0, 15, 11), id = 'vResolutions', columnLabels = 0, |
||
| 465 | columns = ((None, 'text', 0, ui.ALIGN_W),), multiselection = 0) |
||
| 466 | # status bar + submit/cancel |
||
| 467 | ui.TitleButton(self.reswin, layout = (10, 11, 5, 1), text = _("Select"), action = 'onResolutionSelected') |
||
| 468 | ui.TitleButton(self.reswin, layout = (5, 11, 5, 1), text = _("Cancel"), action = 'onResolutionCancel') |
||
| 469 | ui.Title(self.reswin, id = 'vStatusBar', layout = (0, 11, 5, 1), align = ui.ALIGN_W) |
||
| 470 | |||
| 471 | # Languages |
||
| 472 | ui.Title(self.win, layout = (1, 5, 5, 1), text = _('Language'), |
||
| 473 | align = ui.ALIGN_NONE, font = 'normal-bold') |
||
| 474 | try: |
||
| 475 | longLang = self.languages[self.curLang] |
||
| 476 | except: |
||
| 477 | longLang = self.curLang |
||
| 478 | ui.Button(self.win, layout = (1, 6, 5, 1), text = longLang, id = 'vLangSel', action = 'onSelectLanguage') |
||
| 479 | lcols = 12 |
||
| 480 | lrows = 6 |
||
| 481 | width = lcols * 20 + 4 |
||
| 482 | height = lrows * 20 + 4 |
||
| 483 | self.lwin = ui.Window(self.app, |
||
| 484 | modal = 1, |
||
| 485 | escKeyClose = 1, |
||
| 486 | titleOnly = 0, |
||
| 487 | movable = 0, |
||
| 488 | title = _("Select language"), |
||
| 489 | rect = ui.Rect((screenWidth - width) / 2, (screenHeight - height) / 2, width, height), |
||
| 490 | layoutManager = ui.SimpleGridLM(), |
||
| 491 | ) |
||
| 492 | self.lwin.subscribeAction('*', self) |
||
| 493 | # rename |
||
| 494 | ui.Listbox(self.lwin, layout = (0, 0, lcols, lrows-2), id = 'vLanguages', columnLabels = 0, |
||
| 495 | columns = ((None, 'text', 0, ui.ALIGN_W),), multiselection = 0, sortedBy=('text', 1)) |
||
| 496 | # status bar + submit/cancel |
||
| 497 | ui.TitleButton(self.lwin, layout = (lcols-5, lrows-2, 5, 1), text = _("Select"), action = 'onLanguageSelected') |
||
| 498 | ui.TitleButton(self.lwin, layout = (lcols-10, lrows-2, 5, 1), text = _("Cancel"), action = 'onLanguageCancel') |
||
| 499 | ui.Title(self.lwin, id = 'vStatusBar', layout = (0, lrows-2, lcols-10, 1), align = ui.ALIGN_W) |
||
| 500 | |||
| 501 | # Theme |
||
| 502 | ui.Title(self.win, layout = (1, 9, 5, 1), text = _('Themes'), |
||
| 503 | align = ui.ALIGN_NONE, font = 'normal-bold') |
||
| 504 | ui.Button(self.win, layout = (1, 10, 5, 1), id = "vTheme", align = ui.ALIGN_W) |
||
| 505 | ui.ActiveLabel(self.win, layout = (1, 11, 5, 1), id = "vTheme2") |
||
| 506 | width = 304 # 15 * 20 + 4 |
||
| 507 | height = 264 # 13 * 20 + 4 |
||
| 508 | self.twin = ui.Window(self.app, |
||
| 509 | modal = 1, |
||
| 510 | escKeyClose = 1, |
||
| 511 | titleOnly = 0, |
||
| 512 | movable = 0, |
||
| 513 | title = _("Select theme"), |
||
| 514 | rect = ui.Rect((screenWidth - width) / 2, (screenHeight - height) / 2, width, height), |
||
| 515 | layoutManager = ui.SimpleGridLM(), |
||
| 516 | ) |
||
| 517 | self.twin.subscribeAction('*', self) |
||
| 518 | |||
| 519 | # rename |
||
| 520 | ui.Listbox(self.twin, layout = (0, 0, 15, 11), id = 'vThemes', columnLabels = 0, |
||
| 521 | columns = ((None, 'text', 0, ui.ALIGN_W),), multiselection = 0, sortedBy=('text', 1)) |
||
| 522 | # status bar + submit/cancel |
||
| 523 | ui.TitleButton(self.twin, layout = (10, 11, 5, 1), text = _("Select"), action = 'onThemeSelected') |
||
| 524 | ui.TitleButton(self.twin, layout = (5, 11, 5, 1), text = _("Cancel"), action = 'onThemeCancel') |
||
| 525 | ui.Title(self.twin, id = 'vStatusBar', layout = (0, 11, 5, 1), align = ui.ALIGN_W) |
||
| 526 | |||
| 527 | # Defaults |
||
| 528 | ui.Title(self.win, layout = (7, 7, 25, 1), text = _('Default settings'), |
||
| 529 | align = ui.ALIGN_NONE, font = 'normal-bold') |
||
| 530 | ui.Check(self.win, layout = (7, 8, 8, 1), text = _('Report finalization'), id = 'vReportFin', |
||
| 531 | checked = 0) |
||
| 532 | ui.Check(self.win, layout = (15, 8, 8, 1), text = _('Display help/tooltip'), id = 'vDisplayHelp', |
||
| 533 | checked = 1) |
||
| 534 | ui.Check(self.win, layout = (23, 8, 9, 1), text = _('Show coordinates'), id = 'vCoords', |
||
| 535 | checked = 1) |
||
| 536 | ui.Check(self.win, layout = (7 ,9 ,8 ,1), text = _('Players highlight'), id = 'vHighlights', |
||
| 537 | checked = 1) |
||
| 538 | ui.Check(self.win, layout = (15, 9, 8, 1), text = _('Show minimap'), id = 'vShowMinimap', |
||
| 539 | checked = 1) |
||
| 540 | ui.Check(self.win, layout = (23, 9, 8, 1), text = _('Show gate systems'), id = 'vShowGateSystems', |
||
| 541 | checked = 1) |
||
| 542 | ui.Check(self.win, layout = (7, 10, 8, 1), text = _('Show redirects'), id = 'vRedirects', |
||
| 543 | checked = 1, tooltipTitle = _('Starmap hotkey:'), tooltip = _('CTRL-R')) |
||
| 544 | ui.Check(self.win, layout = (15, 10, 8, 1), text = _('Show map grid'), id = 'vShowMapGrid', |
||
| 545 | checked = 1, tooltipTitle = _('Starmap hotkey'), tooltip = _('CTRL-G')) |
||
| 546 | ui.Check(self.win, layout = (23, 10, 8, 1), text = _('Alternate system info'), id = 'vShowAlternateView', |
||
| 547 | checked = 0, tooltipTitle = _('Starmap hotkey'), tooltip = _('CTRL-A')) |
||
| 548 | ui.Check(self.win, layout = (7, 11, 8, 1), text = _('Show map scanners'), id = 'vShowMapScanners', |
||
| 549 | checked = 1, tooltipTitle = _('Starmap hotkey'), tooltip = _('CTRL-S')) |
||
| 550 | ui.Check(self.win, layout = (15, 11, 8, 1), text = _('Show fleet lines'), id = 'vShowMapFleetLines', |
||
| 551 | checked = 1, tooltipTitle = _('Starmap hotkey'), tooltip = _('CTRL-L')) |
||
| 552 | ui.Check(self.win, layout = (23, 11, 8, 1), text = _('Show player zones'), id = 'vShowPlayerZones', |
||
| 553 | checked = 0, tooltipTitle = _('Starmap hotkey'), tooltip = _('CTRL-P')) |
||
| 554 | |||
| 555 | # Login settings |
||
| 556 | ui.Title(self.win, layout = (7,13, 15, 1), text = _('Login settings'), |
||
| 557 | align = ui.ALIGN_NONE, font = 'normal-bold') |
||
| 558 | ui.Check(self.win, layout = (15,14,8,1), text = _('Auto-login'), id = 'vAutoLogin', |
||
| 559 | checked = 0) |
||
| 560 | ui.Check(self.win, layout = (7,14,8,1), text = _('Remember password'), id = 'vSavePassword', |
||
| 561 | checked = 0, action = "onChangeSavePassword") |
||
| 562 | ui.Button(self.win, layout = (23.5, 13, 9, 1), id = "vChangePassword", text = _("Change password"), action = 'onChangePassword', align = ui.ALIGN_NONE) |
||
| 563 | |||
| 564 | # proxy settings |
||
| 565 | ui.Title(self.win, layout = (13, 1, 9, 1), text = _('Proxy'), font = 'normal-bold') |
||
| 566 | ui.Label(self.win, layout = (13, 2, 4, 1), text = _('Host:'), align = ui.ALIGN_E) |
||
| 567 | ui.Entry(self.win, layout = (17, 2, 5, 1), id = 'vProxyHost', align = ui.ALIGN_W, orderNo = 1) |
||
| 568 | ui.Label(self.win, layout = (13, 3, 4, 1), text = _('Port:'), align = ui.ALIGN_E) |
||
| 569 | ui.Entry(self.win, layout = (17, 3, 5, 1), id = 'vProxyPort', align = ui.ALIGN_W, orderNo = 2) |
||
| 570 | ui.Label(self.win, layout = (13, 4, 4, 1), text = _('Username:'), align = ui.ALIGN_E) |
||
| 571 | ui.Entry(self.win, layout = (17, 4, 5, 1), id = 'vProxyUsername', align = ui.ALIGN_W, orderNo = 3) |
||
| 572 | ui.Label(self.win, layout = (13, 5, 4, 1), text = _('Password:'), align = ui.ALIGN_E) |
||
| 573 | ui.Entry(self.win, layout = (17, 5, 5, 1), id = 'vProxyPassword', align = ui.ALIGN_W, orderNo = 4) |
||
| 574 | |||
| 575 | # sound options |
||
| 576 | ui.Title(self.win, layout = (23, 1, 9, 1), text = _('Sound / Music'), font = 'normal-bold') |
||
| 577 | ui.Check(self.win, layout = (23, 2, 9, 1), text = _('Sounds'), id = 'vSoundEnabled', |
||
| 578 | checked = 1) |
||
| 579 | ui.Scrollbar(self.win, layout = (23, 3, 9, 1), id = 'vSoundVolume', |
||
| 580 | action = "onChangeSoundVolume") |
||
| 581 | ui.Check(self.win, layout = (23, 4, 9, 1), text = _('Music'), id = 'vMusicEnabled', |
||
| 582 | checked = 1) |
||
| 583 | ui.Scrollbar(self.win, layout = (23, 5, 9, 1), id = 'vMusicVolume', |
||
| 584 | action = "onChangeMusicVolume") |
||
| 585 | |||
| 586 | # dialog bottom line |
||
| 587 | ui.Title(self.win, layout = (0, rows - 1, cols - 10, 1)) |
||
| 588 | ui.TitleButton(self.win, layout = (cols - 10, rows - 1, 5, 1), text = _("Cancel"), action = 'onCancel') |
||
| 589 | ui.TitleButton(self.win, layout = (cols - 5, rows - 1, 5, 1), text = _("OK"), action = 'onOK') |
||
| 590 |