class CeFrame(Frame): '''\ CeFrame is a frame designed to be a Windows CE compliant window. A CeFrame will track the SIP position and size and will automatically resize itself to always fit the screen. ''' _dispatchers = {"_activate" : (MSGEventDispatcher, WM_ACTIVATE), "_settingchanged" : (MSGEventDispatcher, WM_SETTINGCHANGE), } _dispatchers.update(Frame._dispatchers) def __init__(self, parent=None, title="PocketPyGui", action=None, menu=None, right_action=None, tab_traversal=True, visible=True, enabled=True, has_sip=True, has_toolbar=False): '''\ Arguments : - parent: the parent window of this CeFrame. - title: the title as appearing in the title bar. - action : a tuple ('Label', callback) . - menu : the title of the right menu as a string if not None, the menu can be filled via the cb_menu attribute after CeFrame initialization. ''' Frame.__init__(self, parent, title, tab_traversal=tab_traversal, visible=visible, enabled=enabled) self.bind(_activate=self._on_activate, _settingchanged=self._on_setting_changed, size=self._on_size) if has_toolbar : self.toolbar = ToolBar(self) else: self.toolbar = None self.__create_menubar(action, menu, right_action, has_sip) def _on_size(self, ev): if ev.wParam == 1: self.close() else: self.layout() ev.skip() def layout(self): if self.toolbar is None: return Frame.layout(self) if self._sizer is not None: rc = RECT() GetClientRect(self._w32_hWnd, byref(rc)) self._sizer.size(rc.left, rc.top, rc.right, rc.bottom-24*HIRES_MULT) self.toolbar.move(rc.left, rc.bottom-26*HIRES_MULT, rc.right-rc.left, 26*HIRES_MULT) def __create_menubar(self, action, menu, right_action, has_sip): mbi = SHMENUBARINFO() mbi.cbSize = sizeof(SHMENUBARINFO) mbi.hwndParent = self._w32_hWnd mbi.hInstRes = GetModuleHandle(0) slots = [] empty = True has_action = False has_menu = False has_right_action = False if (action is None) and (menu is None) : mbi.dwFlags = SHCMBF_EMPTYBAR else : empty = False temp_menu = Menu() i = 0 if action is not None: label, cb = action action_item = temp_menu.append(label, callback=cb) #self.action = CommandBarAction(item, 0) else: action_item = temp_menu.append("", enabled=False) if right_action is not None: label, cb = right_action right_action_item = temp_menu.append(label, callback=cb) has_right_action = True elif menu is not None: sub_menu = PopupMenu() temp_menu.append_menu(menu, sub_menu) has_menu = True mbi.dwFlags = SHCMBF_HMENU mbi.nToolBarId = temp_menu._hmenu if not has_sip: mbi.dwFlags |= SHCMBF_HIDESIPBUTTON SHCreateMenuBar(byref(mbi)) self._mb_hWnd = mbi.hwndMB if not empty: self.cb_action = CommandBarAction(mbi.hwndMB, 0, action_item) if has_right_action: self.cb_right_action = CommandBarAction(mbi.hwndMB, 1, right_action_item) elif has_menu: tbbi = TBBUTTONINFO() tbbi.cbSize = sizeof(tbbi) tbbi.dwMask = 0x10 | 0x80000000 SendMessage(mbi.hwndMB, WM_USER+63, 1, byref(tbbi)) hMenu = tbbi.lParam self.cb_menu = CommandBarMenu(mbi.hwndMB, 1, hMenu) rc = RECT() GetWindowRect(self._w32_hWnd, byref(rc)) rcmb = RECT() GetWindowRect(self._mb_hWnd, byref(rcmb)) rc.bottom -= (rcmb.bottom - rcmb.top) self.move(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top) def _on_activate(self, event): if not hasattr(self, '_shai'): self._shai = InitSHActivateInfo() SHHandleWMActivate(event.hWnd, event.wParam, event.lParam, byref(self._shai), 0) def _on_setting_changed(self, event): if not hasattr(self, '_shai'): self._shai = InitSHActivateInfo() SHHandleWMSettingChange(self._w32_hWnd, event.wParam, event.lParam, byref(self._shai)) def show_sipbutton(self, show=True): if show: SHFullScreen(self._w32_hWnd, SHFS_SHOWSIPBUTTON) else: SHFullScreen(self._w32_hWnd, SHFS_HIDESIPBUTTON) def hide_sipbutton(self): self.show_sipbutton(False)
class CeFrame(Frame): '''\ CeFrame is a frame designed to be a Windows CE compliant window. A CeFrame will track the SIP position and size and will automatically resize itself to always fit the screen. ''' _dispatchers = { "_activate": (MSGEventDispatcher, WM_ACTIVATE), "_settingchanged": (MSGEventDispatcher, WM_SETTINGCHANGE), } _dispatchers.update(Frame._dispatchers) def __init__(self, parent=None, title="PocketPyGui", action=None, menu=None, tab_traversal=True, visible=True, enabled=True, has_sip=True, has_toolbar=False): '''\ Arguments : - parent: the parent window of this CeFrame. - title: the title as appearing in the title bar. - action : a tuple ('Label', callback) . - menu : the title of the right menu as a string if not None, the menu can be filled via the cb_menu attribute after CeFrame initialization. ''' Frame.__init__(self, parent, title, tab_traversal=tab_traversal, visible=visible, enabled=enabled) self.bind(_activate=self._on_activate, _settingchanged=self._on_setting_changed) if has_toolbar: self.toolbar = ToolBar(self) else: self.toolbar = None self.__create_menubar(action, menu, has_sip) def layout(self): if self.toolbar is None: return Frame.layout(self) if self._sizer is not None: rc = RECT() GetClientRect(self._w32_hWnd, byref(rc)) self._sizer.size(rc.left, rc.top, rc.right, rc.bottom - 24 * HIRES_MULT) self.toolbar.move(rc.left, rc.bottom - 26 * HIRES_MULT, rc.right - rc.left, 26 * HIRES_MULT) def __create_menubar(self, action, menu, has_sip): mbi = SHMENUBARINFO() mbi.cbSize = sizeof(SHMENUBARINFO) mbi.hwndParent = self._w32_hWnd mbi.hInstRes = GetModuleHandle(0) slots = [] empty = True has_action = False has_menu = False if (action is None) and (menu is None): mbi.dwFlags = SHCMBF_EMPTYBAR else: empty = False temp_menu = Menu() i = 0 if action is not None: label, cb = action action_item = temp_menu.append(label, callback=cb) #self.action = CommandBarAction(item, 0) else: action_item = temp_menu.append("", enabled=False) if menu is not None: sub_menu = PopupMenu() temp_menu.append_menu(menu, sub_menu) has_menu = True mbi.dwFlags = SHCMBF_HMENU mbi.nToolBarId = temp_menu._hmenu if not has_sip: mbi.dwFlags |= SHCMBF_HIDESIPBUTTON SHCreateMenuBar(byref(mbi)) self._mb_hWnd = mbi.hwndMB if not empty: self.cb_action = CommandBarAction(mbi.hwndMB, 0, action_item) if has_menu: tbbi = TBBUTTONINFO() tbbi.cbSize = sizeof(tbbi) tbbi.dwMask = 0x10 | 0x80000000 SendMessage(mbi.hwndMB, WM_USER + 63, 1, byref(tbbi)) hMenu = tbbi.lParam self.cb_menu = CommandBarMenu(mbi.hwndMB, 0, hMenu) rc = RECT() GetWindowRect(self._w32_hWnd, byref(rc)) rcmb = RECT() GetWindowRect(self._mb_hWnd, byref(rcmb)) rc.bottom -= (rcmb.bottom - rcmb.top) self.move(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top) def _on_activate(self, event): if not hasattr(self, '_shai'): self._shai = InitSHActivateInfo() SHHandleWMActivate(event.hWnd, event.wParam, event.lParam, byref(self._shai), 0) def _on_setting_changed(self, event): SHHandleWMSettingChange(self._w32_hWnd, event.wParam, event.lParam, byref(self._shai)) def show_sipbutton(self, show=True): if show: SHFullScreen(self._w32_hWnd, SHFS_SHOWSIPBUTTON) else: SHFullScreen(self._w32_hWnd, SHFS_HIDESIPBUTTON) def hide_sipbutton(self): self.show_sipbutton(False)