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
|
#-----------------------------------------------------------------------------
# Name: CtrlAlign.py
# Purpose:
#
# Author: Riaan Booysen
#
# Created: 2000/09/11
# RCS-ID: $Id: CtrlAlign.py,v 1.4 2004/08/16 13:35:57 riaan Exp $
# Copyright: (c) 1999 - 2004 Riaan Booysen
# Licence: GPL
#-----------------------------------------------------------------------------
#Boa:Dialog:ControlAlignmentFrame
from wxPython.wx import *
# XXX Add 'Center in window' option
def create(parent):
return ControlAlignmentFrame(parent)
[wxID_CONTROLALIGNMENTFRAME, wxID_CONTROLALIGNMENTFRAMECANCELBTN,
wxID_CONTROLALIGNMENTFRAMEOKBTN, wxID_CONTROLALIGNMENTFRAMEPANEL1,
wxID_CONTROLALIGNMENTFRAMERADIOBOX1, wxID_CONTROLALIGNMENTFRAMERADIOBOX2,
] = map(lambda _init_ctrls: wxNewId(), range(6))
class ControlAlignmentFrame(wxDialog):
def _init_utils(self):
# generated method, don't edit
pass
def _init_ctrls(self, prnt):
# generated method, don't edit
wxDialog.__init__(self, id=wxID_CONTROLALIGNMENTFRAME,
name='ControlAlignmentFrame', parent=prnt, pos=wxPoint(341, 140),
size=wxSize(328, 219), style=wxDEFAULT_DIALOG_STYLE,
title='Alignment')
self._init_utils()
self.SetClientSize(wxSize(320, 192))
self.panel1 = wxPanel(id=wxID_CONTROLALIGNMENTFRAMEPANEL1,
name='panel1', parent=self, pos=wxPoint(0, 0), size=wxSize(320,
192), style=wxTAB_TRAVERSAL)
self.radioBox1 = wxRadioBox(choices=['No change', 'Left sides',
'Centers', 'Right sides', 'Space equally'],
id=wxID_CONTROLALIGNMENTFRAMERADIOBOX1, label='Horizontal',
majorDimension=1, name='radioBox1', parent=self.panel1,
point=wxPoint(8, 8), size=wxSize(144, 144),
style=wxRA_SPECIFY_COLS, validator=wxDefaultValidator)
self.okBtn = wxButton(id=wxID_CONTROLALIGNMENTFRAMEOKBTN, label='OK',
name='okBtn', parent=self.panel1, pos=wxPoint(160, 160),
size=wxSize(72, 24), style=0)
EVT_BUTTON(self.okBtn, wxID_CONTROLALIGNMENTFRAMEOKBTN,
self.OnOkbtnButton)
self.cancelBtn = wxButton(id=wxID_CONTROLALIGNMENTFRAMECANCELBTN,
label='Cancel', name='cancelBtn', parent=self.panel1,
pos=wxPoint(240, 160), size=wxSize(72, 24), style=0)
EVT_BUTTON(self.cancelBtn, wxID_CONTROLALIGNMENTFRAMECANCELBTN,
self.OnCancelbtnButton)
self.radioBox2 = wxRadioBox(choices=['No change', 'Tops', 'Centers',
'Bottoms', 'Space equally'],
id=wxID_CONTROLALIGNMENTFRAMERADIOBOX2, label='Vertical',
majorDimension=1, name='radioBox2', parent=self.panel1,
point=wxPoint(160, 8), size=wxSize(152, 144),
style=wxRA_SPECIFY_COLS, validator=wxDefaultValidator)
def __init__(self, parent, selection):
self._init_ctrls(parent)
self.choices = ('No change', 'No change')
self.selection = selection
self.Centre(wxBOTH)
def OnOkbtnButton(self, event):
hor = 0; ver = 1
self.choices = (self.radioBox1.GetStringSelection(), self.radioBox2.GetStringSelection())
selIdx = 0
if len(self.selection):
firstSel = self.selection[0]
lastSel = self.selection[-1]
firstSelPos = firstSel.position
lastSelPos = lastSel.position
selSize = len(self.selection)
for sel in self.selection:
domove = false
newX, newY = sel.position.x, sel.position.y
if self.choices[hor] == 'Left sides':
if sel != firstSel:
domove = true
newX = firstSelPos.x
elif self.choices[hor] == 'Centers':
if sel != firstSel:
domove = true
newX = firstSelPos.x + firstSel.size.x / 2 - sel.size.x / 2
elif self.choices[hor] == 'Right sides':
if sel != firstSel:
domove = true
newX = firstSelPos.x + firstSel.size.x - sel.size.x
elif self.choices[hor] == 'Space equally':
if sel != firstSel and sel != lastSel:
domove = true
newX = (lastSelPos.x - firstSelPos.x) / (selSize-1) * selIdx \
+ firstSelPos.x
# elif self.choices[hor] == 'Center in window': pass # not implemented
if self.choices[ver] == 'Tops':
if sel != firstSel:
domove = true
newY = firstSelPos.y
elif self.choices[ver] == 'Centers':
if sel != firstSel:
domove = true
newY = firstSelPos.y + firstSel.size.y / 2 - sel.size.y / 2
elif self.choices[ver] == 'Bottoms':
if sel != firstSel:
domove = true
newY = firstSelPos.y + firstSel.size.y - sel.size.y
elif self.choices[ver] == 'Space equally':
if sel != firstSel and sel != lastSel:
domove = true
newY = (lastSelPos.y - firstSelPos.y) / (selSize-1) * selIdx \
+ firstSelPos.y
# elif self.choices[ver] == 'Center in window': pass
if domove:
sel.position = wxPoint(newX, newY)
sel.dragging = true
sel.moveRelease()
sel.positionUpdate()
selIdx = selIdx + 1
self.EndModal(wxOK)
def OnCancelbtnButton(self, event):
self.EndModal(wxCANCEL)
if __name__ == '__main__':
app = wxPySimpleApp()
wxInitAllImageHandlers()
dlg = ControlAlignmentFrame(None, [])
try:
dlg.ShowModal()
finally:
dlg.Destroy()
app.MainLoop()
|