Mike Wrote;:
Tim,
<div class="moz-text-flowed" style="font-family: -moz-fixed">
Mike > Driscoll wrote:
Tim,
FT wrote:
I am learning how to make my first spin control and wondering
how I can
do it inside a menu item?
(SOLVED!)
This is simply not an appropriate thing to do in a menu. Menus are
for commands, and simple true/false selections. Anything more
complicated than that needs to be done in a dialog.
I agree...if you want wowee stuff in your menus, you should probably
switch to IronPython and use its abilities to interface with the
various GUI libraries that .NET provides. In the IronPython in Action
book, the author mentions this capability.
Well, I'm not just saying "it isn't easy to do it" or "there's no way
to do it". I'm saying "even if you CAN, you SHOULDN'T do this." User
interface guidelines exist for a reason. Users expect their
applications to behave in certain ways, and when an application does
something radically different, users are surprised, and that leads to
mistakes. Putting a spin control in a menu items requires additional
button clicks, and that's not something a user should ever have to do
inside a menu. Essentially, he would be turning a menu into a
dialog. That's simply not good design.
I knew what you meant and I agree with you that it's not really a good
idea. I just chose my words poorly and mis-communicated.
Mike
Hi Guys!
I did it and it works for me. Below is the reason and where it was put.
It is in the first function call when the menu item is selected. There are
no extra button clicks for it comes up and you do the slider or spin control
and then when you hit the enter key, your done, the slider/spin control
destroyed.
Note that the slider and spin have some of the same parms in them but
not quite. The wx.SpinCtgrl( has the same first 2, the parent and it's own
ID, then the difference next is the spin wants the present value in text
form only, or just leave it blank, or ""
Then after the the slider wants the present, min, and max values before
going into the location and size. Then there like I did you just use all -1
for the use of the present form.
Then the flags are entirely different, only 2 in the spin control and 7
or so in the slider.
Since I can not see what it does, my need is for all voice controls, it
works perfectly and allows you to slide up and down, or left to right, and
once the selection is made by hitting the return key, you are out, the
slider/spin destroyed, and the adjustments made.
I guess you could use this example, place instead of the tts engine I
have, use the pyTTS and see how it works for you. Or just change it to fit
what you want.
All I can say is it works perfectly for me and others may benefit from
it. I am using the slider and it is after the menu item selected. I make the
slider, then bind to functions to it, and place focus on to it.
# VOICE SETTINGS!
def OnSettings(self, e):
"SETTINGS MENU BUTTONS, WHEN ENTERING SAY LABEL OF BUTTON!"
eventType = e.GetEventType()
eventName = e.GetClassName()
self.menuId = e.GetId()
label4btn = self.setting_menu.GetLabelText( self.menuId)
set_value = " Error In Label!"
min = 0
max = 100
steps = 10
tics = 5
if label4btn == "Speaker":
present = TTS2[ self.ttsp].getVoiceNum()
set_value = TTS2[ self.ttsp].getVoiceName()
max = TTS2[ self.ttsp].getVoiceCount()-1
if self.ttsp==4: min = 1; max+=1 #SAPI 4 RANGE 1 TO MAX
steps = 1
tics = 1
elif label4btn == "Rate":
present = TTS2[ self.ttsp].getRate()
set_value = str( present) +"%"
elif label4btn == "Pitch":
present = TTS2[ self.ttsp].getPitch()
set_value = str( present) +"%"
elif label4btn == "Volume":
present = TTS2[ self.ttsp].getVolume()
set_value = str( present) +"%"
TTS2[ self.ttsp].Speak( " %s %s" % (label4btn, set_value), async,
purge)
#SET UP SPIN CTRL FOR THE SETTING SELECTED!!
self.sldr_ctrl = wx.Slider(
self, 999, present, min, max, (-1, -1), (-1, -1),
wx.SL_AUTOTICKS|wx.SL_HORIZONTAL|wx.SL_LABELS
) #END OF CTRL DEFINITION!
self.sldr_ctrl.Bind( wx.EVT_SLIDER, self.SetVoice, self.sldr_ctrl)
self.sldr_ctrl.Bind( wx.EVT_KEY_UP, self.KillSlider, self.sldr_ctrl)
self.sldr_ctrl.SetFocus()
def KillSlider(self, e):
"KILL THE SPIN CONTROL IF ENTER KEY PRESSED!"
k = e.GetKeyCode()
if k == wx.WXK_RETURN:
TTS2[ self.ttsp].Speak(" %s Set " %
self.setting_menu.GetLabelText( self.menuId))
self.Do_Edit( e) #OR PLACE HERE THE DESTROY AND NEW FOCUS
def SetVoice(self,e):
"SET VOICE PARAMETER ADJUSTED!"
spin_Id = e.GetId()
value = self.sldr_ctrl.GetValue()
max = self.sldr_ctrl.GetMax()
min = self.sldr_ctrl.GetMin()
label4btn = self.setting_menu.GetLabelText( self.menuId)
TTS2[ self.ttsp].Speak( " %s %s" % (label4btn, str(value)), async,
purge)
if label4btn == "Speaker":
rt = TTS2[ self.ttsp].getRate()
pt = TTS2[ self.ttsp].getPitch()
TTS2[ self.ttsp].setVoice( value)
if self.ttsp==TS5:
TTS2[ self.ttsp].setRate( rt)
TTS2[ self.ttsp].setPitch( pt)
set_value = TTS2[ self.ttsp].getVoiceName()
elif label4btn == "Rate":
TTS2[ self.ttsp].setRate( value)
set_value = str( value)+"%"
elif label4btn == "Pitch":
TTS2[ self.ttsp].setPitch( value)
set_value = str( value)+"%"
elif label4btn == "Volume":
if value < min+5:
TTS2[ self.ttsp].setVolume( 50)
TTS2[ self.ttsp].Speak( "Volume Minimum!")
value = 0
TTS2[ self.ttsp].setVolume( value)
set_value = str( value)+"%"
TTS2[ self.ttsp].Speak(" %s %s" % (label4btn, set_value), async,
purge)
def Do_Edit(self,e):
""" Edit the file"""
if self.sldr_ctrl:
self.sldr_ctrl.Destroy()
self.control.SetFocus()
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Voice Editor")
app.MainLoop()