File: separatorDialog.py

package info (click to toggle)
spe 0.8.2a%2Brepack-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,812 kB
  • ctags: 6,555
  • sloc: python: 45,491; makefile: 146; sh: 2
file content (119 lines) | stat: -rwxr-xr-x 4,629 bytes parent folder | download | duplicates (5)
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
#Boa:Dialog:wxDialog1

#(c)www.stani.be                                                                
import _spe.info,sm
INFO=_spe.info.copy()

INFO['description']=\
"""Dialog to insert a coloured separator for the class explorer in the sidebar."""

__doc__=INFO['doc']%INFO
#_______________________________________________________________________________

import wx
import string

def create(parent):
    return wxDialog1(parent)

[wxID_WXDIALOG1, wxID_WXDIALOG1BUTTON1, wxID_WXDIALOG1BUTTON2, 
 wxID_WXDIALOG1BUTTON3, wxID_WXDIALOG1BUTTON4, wxID_WXDIALOG1CHECKBOX1, 
 wxID_WXDIALOG1TEXTCTRL1, 
] = map(lambda _init_ctrls: wx.NewId(), range(7))

class wxDialog1(wx.Dialog):
    def _init_utils(self):
        # generated method, don't edit
        pass

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_WXDIALOG1, name='', parent=prnt,
              pos=wx.Point(639, 463), size=wx.Size(360, 136),
              style=wx.DEFAULT_DIALOG_STYLE, title='Spe - Insert separator')
        self._init_utils()
        self.SetClientSize(wx.Size(352, 109))

        self.textCtrl1 = wx.TextCtrl(id=wxID_WXDIALOG1TEXTCTRL1, name='label',
              parent=self, pos=wx.Point(8, 9), size=wx.Size(256, 21), style=0,
              value='Label')

        self.button1 = wx.Button(id=wxID_WXDIALOG1BUTTON1, label='Background',
              name='button1', parent=self, pos=wx.Point(272, 35), size=wx.Size(75,
              23), style=0)
        wx.EVT_BUTTON(self.button1, wxID_WXDIALOG1BUTTON1, self.OnBackgroundChoose)

        self.button2 = wx.Button(id=wxID_WXDIALOG1BUTTON2, label='Foreground',
              name='button2', parent=self, pos=wx.Point(272, 8), size=wx.Size(75,
              23), style=0)
        wx.EVT_BUTTON(self.button2, wxID_WXDIALOG1BUTTON2, self.OnForegroundChoose)

        self.button3 = wx.Button(id=wxID_WXDIALOG1BUTTON3, label='Insert',
              name='button3', parent=self, pos=wx.Point(192, 80), size=wx.Size(75,
              23), style=0)
        wx.EVT_BUTTON(self.button3, wxID_WXDIALOG1BUTTON3, self.OnInsert)

        self.button4 = wx.Button(id=wxID_WXDIALOG1BUTTON4, label='Cancel',
              name='button4', parent=self, pos=wx.Point(272, 80), size=wx.Size(75,
              23), style=0)
        wx.EVT_BUTTON(self.button4, wxID_WXDIALOG1BUTTON4, self.OnCancel)

        self.checkBox1 = wx.CheckBox(id=wxID_WXDIALOG1CHECKBOX1,
              label='Use background color', name='checkBox1', parent=self,
              pos=wx.Point(8, 40), size=wx.Size(256, 13), style=0)
        self.checkBox1.SetValue(0)
        wx.EVT_CHECKBOX(self.checkBox1, wxID_WXDIALOG1CHECKBOX1,
              self.OnBackgroundUse)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.foregroundColour=wx.Colour(0,0,0)
        self.backgroundColour=wx.Colour(255,255,255)
        self.button1.Disable()

    def OnCancel(self,event):
        self.Close()
        
    def OnBackgroundChoose(self, event):
        backgroundColour=self.selectColour(self.backgroundColour)
        if backgroundColour:
            self.backgroundColour=backgroundColour
            self.textCtrl1.SetBackgroundColour(self.backgroundColour)

    def OnForegroundChoose(self, event):
        foregroundColour=self.selectColour(self.foregroundColour)
        if foregroundColour:
            self.foregroundColour=foregroundColour
            self.textCtrl1.SetForegroundColour(self.foregroundColour)

    def selectColour(self,colour):
        dlg = wx.ColourDialog(self)
        dlg.GetColourData().SetChooseFull(1)
        dlg.GetColourData().SetColour(colour)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData().GetColour()
        else:return None
        dlg.Destroy()
        return data

    def OnBackgroundUse(self, event):
        checked=event.IsChecked()
        if checked:colour=self.backgroundColour
        else:colour=wx.Colour(255,255,255)
        self.textCtrl1.SetBackgroundColour(colour)
        self.button1.Enable(checked)

    def OnInsert(self, event):
        if not self.checkBox1.GetValue():self.backgroundColour=wx.Colour(255,255,255)
        label=self.textCtrl1.GetValue()
        separator='#---%s---%s%s%s'%(\
            label,
            wxColour2html(self.foregroundColour),
            wxColour2html(self.backgroundColour),
            sm.zfill('-',(59-len(label))).replace('0','-'))
        self.GetParent().source.ReplaceSelection(separator)
        self.Close()


def wxColour2html(c):
    return ('#%s%s%s'%tuple(map(lambda x:sm.zfill(hex(x)[2:],2),c.Get()))).upper()