def reg_hot_keys(self):
"""
hotkeys:
Alt+e, show dialog, also extract tags
Alt+a, show dialog, without extracting tags
Alt+q, quit the program
Esc, minimize the dialog to system tray
Enter, add the tags
"""
self.hotkeys = {'extract_tag': (
wx.NewId(), wx.MOD_ALT, 0x45), # alt+e
'activate': (
wx.NewId(), wx.MOD_ALT, 0x41), # alt+a
'refresh': (
wx.NewId(), wx.MOD_ALT, 0x52), # alt+r
'quit': (
wx.NewId(), wx.MOD_ALT, 0x51), # alt+q
}
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309(v=vs.85).aspx
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
for _, key in self.hotkeys.items():
# print(_, key)
self.RegisterHotKey(*key)
python类NewId()的实例源码
def makeSettings(self, settingsSizer):
# Translators: This is the static text of the Quick Profile Wizard dialog.
msgIntro=_("Choose which options you want to reset to the default value for the Lambdas profile")
self.introStxt=wx.StaticText(self,-1,label=msgIntro)
settingsSizer.Add(self.introStxt,flag=wx.BOTTOM)
# Translators: This is the label for a checkbox in the
# Quick Profile Wizard dialog.
self.defaultTranslationTableCheckBox=wx.CheckBox(self,wx.NewId(),label=_("Keep the LAMBDA braille table for the current language (%s)") % TABLE_NAME)
self.defaultTranslationTableCheckBox.SetValue(True)
settingsSizer.Add(self.defaultTranslationTableCheckBox,border=10,flag=wx.BOTTOM)
# Translators: This is the label for a checkbox in the
# Quick Profile Wizard dialog.
self.brailleTetherToFocusCheckBox=wx.CheckBox(self,wx.NewId(),label=_("Set the braille cursor to tether the focus"))
self.brailleTetherToFocusCheckBox.SetValue(True)
settingsSizer.Add(self.brailleTetherToFocusCheckBox,border=10,flag=wx.BOTTOM)
# Translators: This is the label for a checkbox in the
# Quick Profile Wizard dialog.
self.disableReadByParagraphCheckBox=wx.CheckBox(self,wx.NewId(),label=_("Disable the Braille reading by paragraph"))
self.disableReadByParagraphCheckBox.SetValue(True)
settingsSizer.Add(self.disableReadByParagraphCheckBox,border=10,flag=wx.BOTTOM)
# Translators: This is the label for a checkbox in the
# Quick Profile Wizard dialog.
self.disableBrailleWordWrapCheckBox=wx.CheckBox(self,wx.NewId(),label=_("Disable word wrappping of the braille line"))
self.disableBrailleWordWrapCheckBox.SetValue(True)
settingsSizer.Add(self.disableBrailleWordWrapCheckBox,border=10,flag=wx.BOTTOM)
def init_settings_popup_menu(self):
menu = wx.Menu()
menu.Append(wx.NewId(), 'Show in GUI:').Enable(False)
wx_id = wx.NewId()
self.settings_menu_sky_item = menu.AppendCheckItem(wx_id, ' Sky')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_sky_item)
self.settings_menu_sky_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_flat_item = menu.AppendCheckItem(wx_id, ' Flat')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_flat_item)
self.settings_menu_flat_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_autoload_item = menu.AppendCheckItem(wx_id, ' Auto-load')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_autoload_item)
self.settings_menu_autoload_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_activemq_item = menu.AppendCheckItem(wx_id, ' ActiveMQ')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_activemq_item)
self.settings_menu_activemq_item.Check(True)
self.settings_popup_menu = menu
def init_settings_popup_menu(self):
menu = wx.Menu()
menu.Append(wx.NewId(), 'Show in GUI:').Enable(False)
wx_id = wx.NewId()
self.settings_menu_sky_item = menu.AppendCheckItem(wx_id, ' Sky')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_sky_item)
self.settings_menu_sky_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_flat_item = menu.AppendCheckItem(wx_id, ' Flat')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_flat_item)
self.settings_menu_flat_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_autoload_item = menu.AppendCheckItem(wx_id, ' Auto-load')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_autoload_item)
self.settings_menu_autoload_item.Check(True)
wx_id = wx.NewId()
self.settings_menu_activemq_item = menu.AppendCheckItem(wx_id, ' ActiveMQ')
wx.EVT_MENU(menu, wx_id, self.on_settings_menu_activemq_item)
self.settings_menu_activemq_item.Check(True)
self.settings_popup_menu = menu
def _init_coll_HelpMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_HELP,
kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor') + '\tF1')
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS,
# kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2')
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
# kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
def handler(event):
return wx.MessageBox(
version.GetCommunityHelpMsg(),
_(u'Community support'),
wx.OK | wx.ICON_INFORMATION)
id = wx.NewId()
parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
self.Bind(wx.EVT_MENU, handler, id=id)
AppendMenu(parent, help='', id=wx.ID_ABOUT,
kind=wx.ITEM_NORMAL, text=_(u'About'))
self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP)
# self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS)
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
for child_name, child_type, (child_tree, child_dimensions) in tree:
if base_path:
child_path = "%s.%s" % (base_path, child_name)
else:
child_path = child_name
if len(child_dimensions) > 0:
child_path += "[%s]" % ",".join([str(dimension[0]) for dimension in child_dimensions])
child_name += "[]"
new_id = wx.NewId()
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name)
self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id)
if len(child_tree) > 0:
new_id = wx.NewId()
child_menu = wx.Menu(title='')
self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree)
menu.AppendMenu(new_id, "%s." % child_name, child_menu)
def AddBlockPinMenuItems(self, menu, connector):
[ID_NO_MODIFIER, ID_NEGATED, ID_RISING_EDGE,
ID_FALLING_EDGE] = [wx.NewId() for i in xrange(4)]
# Create menu items
self.AddMenuItems(menu, [
(ID_NO_MODIFIER, wx.ITEM_RADIO, _(u'No Modifier'), '', self.OnNoModifierMenu),
(ID_NEGATED, wx.ITEM_RADIO, _(u'Negated'), '', self.OnNegatedMenu),
(ID_RISING_EDGE, wx.ITEM_RADIO, _(u'Rising Edge'), '', self.OnRisingEdgeMenu),
(ID_FALLING_EDGE, wx.ITEM_RADIO, _(u'Falling Edge'), '', self.OnFallingEdgeMenu)])
type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
menu.Enable(ID_RISING_EDGE, type != "function")
menu.Enable(ID_FALLING_EDGE, type != "function")
if connector.IsNegated():
menu.Check(ID_NEGATED, True)
elif connector.GetEdge() == "rising":
menu.Check(ID_RISING_EDGE, True)
elif connector.GetEdge() == "falling":
menu.Check(ID_FALLING_EDGE, True)
else:
menu.Check(ID_NO_MODIFIER, True)
# Add Alignment Menu items to the given menu
def PopupForceMenu(self):
iec_path = self.GetElementIECPath(self.SelectedElement)
if iec_path is not None:
menu = wx.Menu(title='')
new_id = wx.NewId()
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.SelectedElement), id=new_id)
new_id = wx.NewId()
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
if self.SelectedElement.IsForced():
menu.Enable(new_id, True)
else:
menu.Enable(new_id, False)
if self.Editor.HasCapture():
self.Editor.ReleaseMouse()
self.Editor.PopupMenu(menu)
menu.Destroy()
def OnVariablesGridEditorShown(self, event):
row, col = event.GetRow(), event.GetCol()
if self.Table.GetColLabelValue(col, False) == "Type":
type_menu = wx.Menu(title='')
base_menu = wx.Menu(title='')
for base_type in self.Controler.GetBaseTypes():
new_id = wx.NewId()
base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu)
datatype_menu = wx.Menu(title='')
for datatype in self.Controler.GetDataTypes():
new_id = wx.NewId()
datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu)
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
type_menu.Destroy()
event.Veto()
else:
event.Skip()
def GetConfNodeMenuItems(self):
if self.Editable:
add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_SLAVEEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
(wx.ITEM_NORMAL, (_('SDO Client'), ID_SLAVEEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
(wx.ITEM_NORMAL, (_('PDO Transmit'), ID_SLAVEEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
(wx.ITEM_NORMAL, (_('PDO Receive'), ID_SLAVEEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
(wx.ITEM_NORMAL, (_('Map Variable'), ID_SLAVEEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
(wx.ITEM_NORMAL, (_('User Type'), ID_SLAVEEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
profile = self.Controler.GetCurrentProfileName()
if profile not in ("None", "DS-301"):
other_profile_text = _("%s Profile") % profile
add_menu.append((wx.ITEM_SEPARATOR, None))
for text, indexes in self.Manager.GetCurrentSpecificMenu():
add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
else:
other_profile_text = _('Other Profile')
return [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_SLAVEEDITORCONFNODEMENUDS301PROFILE, '', self.OnCommunicationMenu)),
(wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
(wx.ITEM_NORMAL, (other_profile_text, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
(wx.ITEM_SEPARATOR, None),
(add_menu, (_('Add'), ID_SLAVEEDITORCONFNODEMENUADD))]
return []
def __init__(self):
wx.TaskBarIcon.__init__(self)
self.SetIcon(AppResource.TaskIcon.getIcon(), C_APP_NAME)
self.ID_NAME = wx.NewId()
self.ID_EXIT = wx.NewId()
self.ID_AUTHOR = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnExitEvent, id=self.ID_EXIT)
self.Bind(wx.EVT_MENU, self.OnHelpEvent, id=self.ID_AUTHOR)
def OnRightClick(self, event):
menu = wx.Menu()
tPopupID0 = wx.NewId()
tPopupID1 = wx.NewId()
tPopupID2 = wx.NewId()
tPopupID3 = wx.NewId()
tPopupID4 = wx.NewId()
tPopupID5 = wx.NewId()
menu.Append(tPopupID2, "Edit")
menu.Append(tPopupID0, "New")
menu.Append(tPopupID1, "Copy")
menu.AppendSeparator()
menu.Append(tPopupID3, "Delete")
menu.Append(tPopupID4, "Delete All")
wx.EVT_MENU(self, tPopupID2, self.OnPopupEdit)
wx.EVT_MENU(self, tPopupID0, self.OnPopupNew)
wx.EVT_MENU(self, tPopupID1, self.OnPopupCopy)
wx.EVT_MENU(self, tPopupID3, self.OnPopupDelete)
wx.EVT_MENU(self, tPopupID4, self.OnPopupDeleteAll)
if len(self.itemDataMap) == 0:
for m in menu.GetMenuItems():
m.Enable(False)
m = menu.FindItemById(tPopupID0)
m.Enable(True)
self.PopupMenu(menu, wx.Point(self.x, self.y))
menu.Destroy()
event.Skip()
def __init__(self, parent, name, number, minnamelen, maxnamelen):
wxskinDialog.__init__(self, parent, -1, "Phonebook edit entry")
self.SetAutoLayout(True)
self.name = None
self.number = None
nameTextId = wx.NewId()
# Main window resizer object
border = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "Enter the phonebook entry name, number and press OK.")
border.Add(label, 1, wx.ALL, 10)
#fgs = wx.FlexGridSizer(2,3,5,20)
fgs = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(self, -1, "Name (max %d): " % maxnamelen)
fgs.Add(label, 1, wx.ALIGN_LEFT | wx.LEFT, 10)
self.nameCtrl = wx.TextCtrl(self, nameTextId, name, validator = pySIMvalidator(None, minnamelen, maxnamelen))
fgs.Add(self.nameCtrl, 1, wx.ALIGN_RIGHT | wx.RIGHT, 10)
border.Add(fgs, 1, wx.ALL)
fgs = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(self, -1, "Number (max 20): ")
fgs.Add(label, 1, wx.ALIGN_LEFT | wx.LEFT, 10)
self.numberCtrl = wx.TextCtrl(self, -1, number, validator = pySIMvalidator("+*#pw0123456789", None, 20))
fgs.Add(self.numberCtrl, 1, wx.ALIGN_RIGHT | wx.RIGHT, 10)
border.Add(fgs, 1, wx.ALL)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, ID_BUTTON_OK, "Okay"), 1, wx.ALIGN_LEFT | wx.ALL, 20)
buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
border.Add(buttons, 1, wx.ALL)
wx.EVT_BUTTON(self, ID_BUTTON_OK, self.onOK)
wx.EVT_TEXT_ENTER(self, nameTextId, self.onOK)
self.SetAutoLayout(1);
self.SetSizer(border)
border.Fit(self)
self.Layout()
def OnRightClick(self, event):
menu = wx.Menu()
tPopupID0 = wx.NewId()
tPopupID1 = wx.NewId()
tPopupID2 = wx.NewId()
tPopupID3 = wx.NewId()
tPopupID4 = wx.NewId()
tPopupID5 = wx.NewId()
menu.Append(tPopupID2, "Edit")
menu.Append(tPopupID0, "New")
menu.Append(tPopupID1, "Copy")
menu.AppendSeparator()
menu.Append(tPopupID3, "Delete")
menu.Append(tPopupID4, "Delete All")
wx.EVT_MENU(self, tPopupID2, self.OnPopupEdit)
wx.EVT_MENU(self, tPopupID0, self.OnPopupNew)
wx.EVT_MENU(self, tPopupID1, self.OnPopupCopy)
wx.EVT_MENU(self, tPopupID3, self.OnPopupDelete)
wx.EVT_MENU(self, tPopupID4, self.OnPopupDeleteAll)
if len(self.itemDataMap) == 0:
for m in menu.GetMenuItems():
m.Enable(False)
m = menu.FindItemById(tPopupID0)
m.Enable(True)
self.PopupMenu(menu, wx.Point(self.x, self.y))
menu.Destroy()
event.Skip()
def __init__(self, parent, name, number, minnamelen, maxnamelen):
wxskinDialog.__init__(self, parent, -1, "Phonebook edit entry")
self.SetAutoLayout(True)
self.name = None
self.number = None
nameTextId = wx.NewId()
# Main window resizer object
border = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "Enter the phonebook entry name, number and press OK.")
border.Add(label, 1, wx.ALL, 10)
#fgs = wx.FlexGridSizer(2,3,5,20)
fgs = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(self, -1, "Name (max %d): " % maxnamelen)
fgs.Add(label, 1, wx.ALIGN_LEFT | wx.LEFT, 10)
self.nameCtrl = wx.TextCtrl(self, nameTextId, name, validator = pySIMvalidator(None, minnamelen, maxnamelen))
fgs.Add(self.nameCtrl, 1, wx.ALIGN_RIGHT | wx.RIGHT, 10)
border.Add(fgs, 1, wx.ALL)
fgs = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(self, -1, "Number (max 20): ")
fgs.Add(label, 1, wx.ALIGN_LEFT | wx.LEFT, 10)
self.numberCtrl = wx.TextCtrl(self, -1, number, validator = pySIMvalidator("+*#pw0123456789", None, 20))
fgs.Add(self.numberCtrl, 1, wx.ALIGN_RIGHT | wx.RIGHT, 10)
border.Add(fgs, 1, wx.ALL)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, ID_BUTTON_OK, "Okay"), 1, wx.ALIGN_LEFT | wx.ALL, 20)
buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
border.Add(buttons, 1, wx.ALL)
wx.EVT_BUTTON(self, ID_BUTTON_OK, self.onOK)
wx.EVT_TEXT_ENTER(self, nameTextId, self.onOK)
self.SetAutoLayout(1);
self.SetSizer(border)
border.Fit(self)
self.Layout()
def OnRightClick(self, event):
tsubPopupID1 = 10
tsubPopupID2 = 11
tsubPopupID3 = 12
submenu = wx.Menu()
submenu.Append(tsubPopupID1, "Read")
submenu.Append(tsubPopupID2, "Unread")
submenu.Append(tsubPopupID3, "Deleted")
wx.EVT_MENU(self, tsubPopupID1, self.OnPopupMarkRead)
wx.EVT_MENU(self, tsubPopupID2, self.OnPopupMarkUnread)
wx.EVT_MENU(self, tsubPopupID3, self.OnPopupMarkDeleted)
menu = wx.Menu()
tPopupID0 = wx.NewId()
tPopupID1 = wx.NewId()
tPopupID2 = wx.NewId()
tPopupID3 = wx.NewId()
tPopupID4 = wx.NewId()
tPopupID5 = wx.NewId()
menu.AppendMenu(tPopupID1, "Mark as", submenu)
menu.AppendSeparator()
menu.Append(tPopupID2, "Edit")
menu.Append(tPopupID0, "New")
menu.Append(tPopupID1, "Copy")
menu.AppendSeparator()
menu.Append(tPopupID3, "Delete")
menu.Append(tPopupID4, "Delete All")
wx.EVT_MENU(self, tPopupID2, self.OnPopupEdit)
wx.EVT_MENU(self, tPopupID0, self.OnPopupNew)
wx.EVT_MENU(self, tPopupID1, self.OnPopupCopy)
wx.EVT_MENU(self, tPopupID3, self.OnPopupDelete)
wx.EVT_MENU(self, tPopupID4, self.OnPopupDeleteAll)
self.PopupMenu(menu, wx.Point(self.x, self.y))
menu.Destroy()
event.Skip()
def _append_menu_item(self, menu, wx_id, title, fxn):
if wx_id is None:
wx_id = wx.NewId()
menu.Append(wx_id, title)
wx.EVT_MENU(menu, wx_id, fxn)
return wx_id
def init_popup_menu(self):
self.popup_menu_needs_rebuild = False
if self.popup_menu is not None:
self.popup_menu.Destroy()
menu = wx.Menu()
menu.Append(wx.NewId(), 'Cursor mode:').Enable(False)
self.cursor_mode_to_eventID = {}
cmd_num = 1
for cursor_mode in self.popup_menu_cursor_modes:
fxn = self.available_cursor_modes[cursor_mode]['set-to-mode']
wx_id = wx.NewId()
menu.AppendCheckItem(wx_id, ' ' + cursor_mode + '\tCtrl+' + str(cmd_num))
wx.EVT_MENU(menu, wx_id, fxn)
self.cursor_mode_to_eventID[cursor_mode] = wx_id
self.Bind(wx.EVT_MENU, fxn, id=wx_id)
self.accelerator_table.append((wx.ACCEL_CMD, ord(str(cmd_num)), wx_id))
cmd_num += 1
menu.AppendSeparator()
image_cmap_submenu = wx.Menu()
for cmap in self.ztv_frame.available_cmaps:
menu_item = image_cmap_submenu.AppendCheckItem(self.cmap_to_eventID[cmap], cmap)
wx.EVT_MENU(image_cmap_submenu, self.cmap_to_eventID[cmap], self.on_change_cmap_event)
menu_item.SetBitmap(self.cmap_bitmaps[cmap])
menu.AppendMenu(-1, 'Color Maps', image_cmap_submenu)
wx_id = wx.NewId()
self.menu_item_invert_map = menu.AppendCheckItem(wx_id, 'Invert Color Map')
wx.EVT_MENU(menu, wx_id, self.ztv_frame.invert_cmap)
self.menu_item_invert_map.Check(self.ztv_frame.is_cmap_inverted)
image_scaling_submenu = wx.Menu()
for scaling in self.ztv_frame.available_scalings:
menu_item = image_scaling_submenu.AppendCheckItem(self.scaling_to_eventID[scaling], scaling)
wx.EVT_MENU(image_scaling_submenu, self.scaling_to_eventID[scaling], self.on_change_scaling_event)
menu.AppendMenu(-1, 'Scaling', image_scaling_submenu)
menu.AppendSeparator()
self.popup_menu_cur_fits_header_eventID = wx.NewId()
self._append_menu_item(menu, self.popup_menu_cur_fits_header_eventID, 'FITS Header',
self.on_display_cur_fits_header)
self.popup_menu = menu
self.SetAcceleratorTable(wx.AcceleratorTable(self.accelerator_table))
def _append_menu_item(self, menu, wx_id, title, fxn):
if wx_id is None:
wx_id = wx.NewId()
menu.Append(wx_id, title)
wx.EVT_MENU(menu, wx_id, fxn)
return wx_id
def init_popup_menu(self):
self.popup_menu_needs_rebuild = False
if self.popup_menu is not None:
self.popup_menu.Destroy()
menu = wx.Menu()
menu.Append(wx.NewId(), 'Cursor mode:').Enable(False)
self.cursor_mode_to_eventID = {}
cmd_num = 1
for cursor_mode in self.popup_menu_cursor_modes:
fxn = self.available_cursor_modes[cursor_mode]['set-to-mode']
wx_id = wx.NewId()
menu.AppendCheckItem(wx_id, ' ' + cursor_mode + '\tCtrl+' + str(cmd_num))
wx.EVT_MENU(menu, wx_id, fxn)
self.cursor_mode_to_eventID[cursor_mode] = wx_id
self.Bind(wx.EVT_MENU, fxn, id=wx_id)
self.accelerator_table.append((wx.ACCEL_CMD, ord(str(cmd_num)), wx_id))
cmd_num += 1
menu.AppendSeparator()
image_cmap_submenu = wx.Menu()
for cmap in self.ztv_frame.available_cmaps:
menu_item = image_cmap_submenu.AppendCheckItem(self.cmap_to_eventID[cmap], cmap)
wx.EVT_MENU(image_cmap_submenu, self.cmap_to_eventID[cmap], self.on_change_cmap_event)
menu_item.SetBitmap(self.cmap_bitmaps[cmap])
menu.AppendMenu(-1, 'Color Maps', image_cmap_submenu)
wx_id = wx.NewId()
self.menu_item_invert_map = menu.AppendCheckItem(wx_id, 'Invert Color Map')
wx.EVT_MENU(menu, wx_id, self.ztv_frame.invert_cmap)
self.menu_item_invert_map.Check(self.ztv_frame.is_cmap_inverted)
image_scaling_submenu = wx.Menu()
for scaling in self.ztv_frame.available_scalings:
menu_item = image_scaling_submenu.AppendCheckItem(self.scaling_to_eventID[scaling], scaling)
wx.EVT_MENU(image_scaling_submenu, self.scaling_to_eventID[scaling], self.on_change_scaling_event)
menu.AppendMenu(-1, 'Scaling', image_scaling_submenu)
menu.AppendSeparator()
self.popup_menu_cur_fits_header_eventID = wx.NewId()
self._append_menu_item(menu, self.popup_menu_cur_fits_header_eventID, 'FITS Header',
self.on_display_cur_fits_header)
self.popup_menu = menu
self.SetAcceleratorTable(wx.AcceleratorTable(self.accelerator_table))
def _InitRecordPaneMenu(self):
# make a menu
self.record_pane_menu = wx.Menu()
# Create IDs #
self.record_pane_popup_id1 = wx.NewId()
# Create Binds #
self.Bind(wx.EVT_MENU, self.RecordPaneMenu_ExtractClick, id=self.record_pane_popup_id1)
# Create Items #
self.record_pane_menu.Append(self.record_pane_popup_id1, "Extract")
def OnInit(self):
frame = wx.Frame(None, -1, "Hello from wxPython")
id=wx.NewId()
self.list=wx.ListCtrl(frame,id,style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.list.Show(True)
self.list.InsertColumn(0,"Data #1")
self.list.InsertColumn(1,"Data #2")
self.list.InsertColumn(2,"Data #3")
# 0 will insert at the start of the list
pos = self.list.InsertStringItem(0,"hello")
# add values in the other columns on the same row
self.list.SetStringItem(pos,1,"world")
self.list.SetStringItem(pos,2,"!")
pos = self.list.InsertStringItem(0,"wat")
self.list.SetStringItem(pos,1,"um")
self.list.SetStringItem(pos,2,"wha")
self.itemDataMap = {
0: ("hello","world","!"),
1: ("wat","um","wha")
}
LCM.ColumnSorterMixin.__init__(self,3)
frame.Show(True)
self.SetTopWindow(frame)
return True
def _init_coll_DisplayMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_REFRESH,
kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R')
if self.EnableDebug:
AppendMenu(parent, help='', id=wx.ID_CLEAR,
kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
parent.AppendSeparator()
zoommenu = wx.Menu(title='')
parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
for idx, value in enumerate(ZOOM_FACTORS):
new_id = wx.NewId()
AppendMenu(zoommenu, help='', id=new_id,
kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), id=new_id)
parent.AppendSeparator()
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
kind=wx.ITEM_NORMAL, text=_(u'Switch perspective') + '\tF12')
self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
if self.EnableDebug:
self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
def OnMessagePanelRightUp(self, event):
message = self.GetMessageByScreenPos(*event.GetPosition())
if message is not None:
menu = wx.Menu(title='')
new_id = wx.NewId()
menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy"))
self.Bind(wx.EVT_MENU, self.GetCopyMessageToClipboardFunction(message), id=new_id)
self.MessagePanel.PopupMenu(menu)
menu.Destroy()
event.Skip()
def BuildStdIECTypesMenu(self, type_menu):
# build a submenu containing standard IEC types
base_menu = wx.Menu(title='')
for base_type in self.Controler.GetBaseTypes():
new_id = wx.NewId()
base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
def BuildUserTypesMenu(self, type_menu):
# build a submenu containing user-defined types
datatype_menu = wx.Menu(title='')
datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False)
for datatype in datatypes:
new_id = wx.NewId()
datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
def BuildProjectTypesMenu(self, type_menu, classtype):
# build a submenu containing function block types
bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
poutype != "function" and bodytype in ["ST", "IL"]:
functionblock_menu = wx.Menu(title='')
fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
for functionblock_type in fbtypes:
new_id = wx.NewId()
functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
def BuildArrayTypesMenu(self, type_menu):
new_id = wx.NewId()
type_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
def OnStructureElementsGridEditorShown(self, event):
row, col = event.GetRow(), event.GetCol()
if self.StructureElementsTable.GetColLabelValue(col, False) == "Type":
type_menu = wx.Menu(title='')
base_menu = wx.Menu(title='')
for base_type in self.Controler.GetBaseTypes():
new_id = wx.NewId()
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id)
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
datatype_menu = wx.Menu(title='')
for datatype in self.Controler.GetDataTypes(self.TagName, False):
new_id = wx.NewId()
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id)
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
new_id = wx.NewId()
AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
self.Bind(wx.EVT_MENU, self.ElementArrayTypeFunction, id=new_id)
# functionblock_menu = wx.Menu(title='')
# bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
# pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
# if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
# for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName):
# new_id = wx.NewId()
# AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
# self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
# type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col))
self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize())
type_menu.Destroy()
event.Veto()
else:
event.Skip()
def AddWireMenuItems(self, menu, delete=False, replace=False):
[ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE,
] = [wx.NewId() for i in xrange(3)]
# Create menu items
self.AddMenuItems(menu, [
(ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu),
(ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu),
(ID_REPLACE_WIRE, wx.ITEM_NORMAL, _(u'Replace Wire by connections'), '', self.OnReplaceWireMenu)])
menu.Enable(ID_DELETE_SEGMENT, delete)
menu.Enable(ID_REPLACE_WIRE, replace)
# Add Divergence Menu items to the given menu