Пример #1
0
 def modal_event_loop(self):
     """Loop reading and handling events for the given window until
     exit_event_loop() is called. Interaction with other windows is prevented
     (although enabled application-wide menu commands can be used)."""
     #  Implementations can override this together with exit_modal_event_loop()
     #  to implement modal event loops in a different way.
     application()._event_loop(self)
Пример #2
0
 def destroy(self):
     GComponent.destroy(self)
     wo = self._win
     if wo:
         wo.AttachObject(None)
         wo.ShowWindow(wc.SW_HIDE)
         application()._win_recycle(wo)
Пример #3
0
 def destroy(self):
     GComponent.destroy(self)
     wo = self._win
     if wo:
         wo.AttachObject(None)
         wo.ShowWindow(wc.SW_HIDE)
         application()._win_recycle(wo)
Пример #4
0
 def modal_event_loop(self):
     """Loop reading and handling events for the given window until
     exit_event_loop() is called. Interaction with other windows is prevented
     (although enabled application-wide menu commands can be used)."""
     #  Implementations can override this together with exit_modal_event_loop()
     #  to implement modal event loops in a different way.
     application()._event_loop(self)
Пример #5
0
 def _win_menu_command(self, id):
     command = win_id_to_command(id)
     if command:
         application().dispatch_menu_command(command)
         return True
     else:
         return False
Пример #6
0
def main():
    win = Window()
    view = PolyView(width=120, height=120)
    win.add(view)
    win.shrink_wrap()
    win.show()
    application().run()
Пример #7
0
def test():
    win = Window(title = "Exceptions", size = (200, 100))
    but1 = Button("ApplicationError", action = raise_application_error)
    but2 = Button("Exception", action = raise_exception)
    win.place_column([but1, but2], left = 20, top = 20)
    win.shrink_wrap(padding = (20, 20))
    win.show()
    application().run()
Пример #8
0
 def OnClose(self):
     #print "Window:", self, "OnClose"
     try:
         self.close_cmd()
     except Cancel:
         pass
     except:
         application().report_error()
Пример #9
0
 def OnClose(self):
     # print "Window:", self, "OnClose"
     try:
         self.close_cmd()
     except Cancel:
         pass
     except:
         application().report_error()
Пример #10
0
def test():
    view = GearsView(size = (300, 300))
    win = Window(title = "Gears")
    win.place(view, sticky = "nsew")
    view.become_target()
    win.shrink_wrap()
    win.show()
    application().run()
Пример #11
0
def test():
    win = Window(title="Exceptions", size=(200, 100))
    but1 = Button("ApplicationError", action=raise_application_error)
    but2 = Button("Exception", action=raise_exception)
    win.place_column([but1, but2], left=20, top=20)
    win.shrink_wrap(padding=(20, 20))
    win.show()
    application().run()
Пример #12
0
 def destroy(self):
     """Destroy any associated windows, then destroy document contents."""
     #print "Document.destroy:", self ###
     for win in self._windows[:]:
         win.destroy()
     application()._remove_document(self)
     self.destroy_contents()
     Model.destroy(self)
Пример #13
0
def test():
    view = GearsView(size=(300, 300))
    win = Window(title="Gears")
    win.place(view, sticky="nsew")
    view.become_target()
    win.shrink_wrap()
    win.show()
    application().run()
Пример #14
0
def test():
    starter = Button("Start", action = start_task)
    stopper = Button("Stop", action = stop_task)
    win = Window(title = "Tasks")
    win.place_column([starter, stopper], left = 20, top = 20, spacing = 20)
    win.shrink_wrap(padding = (20, 20))
    win.show()
    application().run()
Пример #15
0
def test():
    win = Window(title = "Targeting", size = (180, 100))
    patch1 = TestPatch("Red patch", red, position = (20, 20))
    patch2 = TestPatch("Green patch", green, position = (100, 20))
    win.add(patch1)
    win.add(patch2)
    win.show()
    application().run()
Пример #16
0
 def destroy(self):
     """Destroy any associated windows, then destroy document contents."""
     #print "Document.destroy:", self ###
     for win in self._windows[:]:
         win.destroy()
     application()._remove_document(self)
     self.destroy_contents()
     Model.destroy(self)
Пример #17
0
def test():
    starter = Button("Start", action=start_task)
    stopper = Button("Stop", action=stop_task)
    win = Window(title="Tasks")
    win.place_column([starter, stopper], left=20, top=20, spacing=20)
    win.shrink_wrap(padding=(20, 20))
    win.show()
    application().run()
Пример #18
0
def test():
    win = Window(title="Targeting", size=(180, 100))
    patch1 = TestPatch("Red patch", red, position=(20, 20))
    patch2 = TestPatch("Green patch", green, position=(100, 20))
    win.add(patch1)
    win.add(patch2)
    win.show()
    application().run()
Пример #19
0
 def __init__(self, style = 'standard', closable = None, **kwds):
     if closable is None:
         raise Exceptions.InternalError(
             "'closable' parameter unspecified in call to generic Window.__init__")
     Container.__init__(self, **kwds)
     self._style = style
     self._dialog_style = style.find('dialog') >= 0
     self._closable = closable
     application()._add_window(self)
Пример #20
0
 def track_mouse(self):
     self._win_tracking_mouse = True
     while 1:
         application().event_loop()
         event = self._win_mouse_event
         yield event
         if event.kind == 'mouse_up':
             break
     self._win_tracking_mouse = False
Пример #21
0
def test():
    doc = TestDoc(title = "Document")
    view = TestDocView(model = doc, size = (200, 200))
    win = Window(resizable = 0, size = (200, 200))
    win.add(view)
    win.document = doc
    #say(view.x, view.y, view.width, view.height)
    win.show()
    application().run()
Пример #22
0
	def __init__(self, style = 'standard', closable = None, **kwds):
		if closable is None:
			raise Exceptions.InternalError(
				"'closable' parameter unspecified in call to generic Window.__init__")
		Container.__init__(self, **kwds)
		self._style = style
		self._dialog_style = style.find('dialog') >= 0
		self._closable = closable
		application()._add_window(self)
Пример #23
0
 def track_mouse(self):
     self._win_tracking_mouse = True
     while 1:
         application().event_loop()
         event = self._win_mouse_event
         yield event
         if event.kind == 'mouse_up':
             break
     self._win_tracking_mouse = False
Пример #24
0
def test():
    doc = TestDoc(title="Document")
    view = TestDocView(model=doc, size=(200, 200))
    win = Window(resizable=0, size=(200, 200))
    win.add(view)
    win.document = doc
    #say(view.x, view.y, view.width, view.height)
    win.show()
    application().run()
Пример #25
0
 def OnTimer(self, event_id):
     #print "TimerWnd.OnTimer:", event_id
     task = self.tasks.get(event_id)
     if task:
         if not task._repeat:
             self.cancel(task)
         task._proc()
         #  We do this so that the application can't get starved of idle time
         #  by a repeatedly-firing Task:
         application()._win_idle()
Пример #26
0
 def OnTimer(self, event_id):
     #print "TimerWnd.OnTimer:", event_id
     task = self.tasks.get(event_id)
     if task:
         if not task._repeat:
             self.cancel(task)
         task._proc()
         #  We do this so that the application can't get starved of idle time
         #  by a repeatedly-firing Task:
         application()._win_idle()
Пример #27
0
 def copy_cmd(self):
     if self._password:
         return
     if self._multiline:
         gtk_textbuffer = self._gtk_textbuffer
         start_iter, end_iter = self._gtk_get_sel_iters()
         text = gtk_textbuffer.get_text(start_iter, end_iter, 1)
     else:
         start, end = self._gtk_get_sel_positions()
         text = self._gtk_entry.get_chars(start, end)
     if text:
         application().set_clipboard(text)
Пример #28
0
def win_command_to_id(name, index=None):
    if index is not None:
        key = (name, index)
    else:
        key = name
    id = win_command_map.get(key)
    if not id:
        id = len(win_command_list) + 1
        win_command_map[key] = id
        win_command_list.append(key)
        application()._win_app.HookCommandUpdate(win_command_update, id)
    return id
Пример #29
0
 def copy_cmd(self):
     if self._password:
         return
     if self._multiline:
         gtk_textbuffer = self._gtk_textbuffer
         start_iter, end_iter = self._gtk_get_sel_iters()
         text = gtk_textbuffer.get_text(start_iter, end_iter, 1)
     else:
         start, end = self._gtk_get_sel_positions()
         text = self._gtk_entry.get_chars(start, end)
     if text:
         application().set_clipboard(text)
Пример #30
0
def win_command_to_id(name, index=None):
    if index is not None:
        key = (name, index)
    else:
        key = name
    id = win_command_map.get(key)
    if not id:
        id = len(win_command_list) + 1
        win_command_map[key] = id
        win_command_list.append(key)
        application()._win_app.HookCommandUpdate(win_command_update, id)
    return id
Пример #31
0
def test():
	def bing():
		say("Bing!")
		#fld._win_dump_flags()
	win = Window(title = "Shrink Wrap", resizable = 0)
	but = Button("Bing!", action = bing)
	cbx = CheckBox("Spam")
	fld = TextField(width = 100)
	win.place(but, left = 20, top = 20)
	win.place(cbx, left = but + 20, top = 20)
	win.place(fld, left = 20, top = but + 20)
	win.shrink_wrap()
	win.show()
	application().run()
Пример #32
0
def test():
    def bing():
        say("Bing!")
        #fld._win_dump_flags()
    win = Window(title = "Shrink Wrap", resizable = 0)
    but = Button("Bing!", action = bing)
    cbx = CheckBox("Spam")
    fld = TextField(width = 100)
    win.place(but, left = 20, top = 20)
    win.place(cbx, left = but + 20, top = 20)
    win.place(fld, left = 20, top = but + 20)
    win.shrink_wrap()
    win.show()
    application().run()
Пример #33
0
 def OnCommand(self, wParam, lParam):
     #print "WinMessageReflector.OnCommand: code = 0x%04x 0x%04x lParam = 0x%08x" % (
     #	HIWORD(wParam), LOWORD(wParam), lParam)
     try:
         code = HIWORD(wParam)
         id = LOWORD(wParam)
         if id:
             if self._win_menu_command(id):
                 return
         name = win_command_map.get(code)
         if name:
             self._forward_reflected_message(lParam, name)
     except Cancel:
         pass
     except:
         application().report_error()
Пример #34
0
 def _gtk_update_menubar(self):
     #
     #  Update the contents of the menubar after either the application
     #  menu list or this window's menu list has changed. We only add
     #  the menu titles at this stage; the menus themselves are attached
     #  during menu setup. We also attach the accel groups associated
     #  with the new menus.
     #
     #  Things would be simpler if we could attach the menus here,
     #  but attempting to share menus between menubar items provokes
     #  a warning from Gtk, even though it otherwise appears to work.
     #
     gtk_menubar = self._gtk_menubar
     gtk_window = self._gtk_outer_widget
     #  Remove old accel groups
     for menu in self._all_menus:
         gtk_window.remove_accel_group(menu._gtk_accel_group)
     #  Detach any existing menus and remove old menu titles
     if gtk_menubar:
         for gtk_menubar_item in gtk_menubar.get_children():
             gtk_menubar_item.remove_submenu()
             gtk_menubar_item.destroy()
     #  Install new menu list
     #all_menus = application().menus + self.menus
     all_menus = application()._effective_menus_for_window(self)
     self._all_menus = all_menus
     #  Create new menu titles and attach accel groups
     for menu in all_menus:
         if gtk_menubar:
             gtk_menubar_item = gtk.MenuItem(menu._title)
             gtk_menubar_item.show()
             gtk_menubar.append(gtk_menubar_item)
         gtk_window.add_accel_group(menu._gtk_accel_group)
     self._need_menubar_update = 0
Пример #35
0
 def _tab_to(self, direction):
     print("GWindow._tab_to:", direction)  ###
     chain = self.tab_chain
     if chain:
         old_target = application().target
         new_target = None
         n = len(chain)
         try:
             i = chain.index(old_target)
         except ValueError:
             if direction > 0:
                 i = -1
             else:
                 i = n
         k = n
         while k:
             k -= 1
             i = (i + direction) % n
             comp = chain[i]
             if comp._is_targetable():
                 new_target = comp
                 break
         if new_target:
             if old_target:
                 old_target._tab_out()
             new_target._tab_in()
Пример #36
0
 def _tab_to(self, direction):
     #print "GWindow._tab_to:", direction ###
     chain = self.tab_chain
     if chain:
         old_target = application().target
         new_target = None
         n = len(chain)
         try:
             i = chain.index(old_target)
         except ValueError:
             if direction > 0:
                 i = -1
             else:
                 i = n
         k = n
         while k:
             k -= 1
             i = (i + direction) % n
             comp = chain[i]
             if comp._is_targetable():
                 new_target = comp
                 break
         if new_target:
             if old_target:
                 old_target._tab_out()
             new_target._tab_in()
Пример #37
0
 def OnCommand(self, wParam, lParam):
     #print "WinMessageReflector.OnCommand: code = 0x%04x 0x%04x lParam = 0x%08x" % (
     #	HIWORD(wParam), LOWORD(wParam), lParam)
     try:
         code = HIWORD(wParam)
         id = LOWORD(wParam)
         if id:
             self._win_menu_command(id)
         else:
             name = win_command_map.get(code)
             if name:
                 self._forward_reflected_message(lParam, name)
     except Cancel:
         pass
     except:
         application().report_error()
Пример #38
0
 def _gtk_update_menubar(self):
     #
     #  Update the contents of the menubar after either the application
     #  menu list or this window's menu list has changed. We only add
     #  the menu titles at this stage; the menus themselves are attached
     #  during menu setup. We also attach the accel groups associated
     #  with the new menus.
     #
     #  Things would be simpler if we could attach the menus here,
     #  but attempting to share menus between menubar items provokes
     #  a warning from Gtk, even though it otherwise appears to work.
     #
     gtk_menubar = self._gtk_menubar
     gtk_window = self._gtk_outer_widget
     #  Remove old accel groups
     for menu in self._all_menus:
         gtk_window.remove_accel_group(menu._gtk_accel_group)
     #  Detach any existing menus and remove old menu titles
     if gtk_menubar:
         for gtk_menubar_item in gtk_menubar.get_children():
             gtk_menubar_item.remove_submenu()
             gtk_menubar_item.destroy()
     #  Install new menu list
     #all_menus = application().menus + self.menus
     all_menus = application()._effective_menus_for_window(self)
     self._all_menus = all_menus
     #  Create new menu titles and attach accel groups
     for menu in all_menus:
         if gtk_menubar:
             gtk_menubar_item = gtk.MenuItem(menu._title)
             gtk_menubar_item.show()
             gtk_menubar.append(gtk_menubar_item)
         gtk_window.add_accel_group(menu._gtk_accel_group)
     self._need_menubar_update = 0
Пример #39
0
 def get_page_setup(self):
     result = None
     model = getattr(self, 'model', None)
     if model:
         result = getattr(model, 'page_setup', None)
     if not result:
         result = application().page_setup
     return result
Пример #40
0
 def get_page_setup(self):
     result = None
     model = getattr(self, 'model', None)
     if model:
         result = getattr(model, 'page_setup', None)
     if not result:
         result = application().page_setup
     return result
Пример #41
0
def test():
    def select():
        i = group.value
        name = cursor_names[i]
        say("Selecting cursor no. %d (%s)" % (i, name))
        cursor = getattr(StdCursors, name)
        say("...", cursor)
        view.cursor = cursor
    win = Window(title = "Std Cursors")
    view = TestArea(size = (100, 100))
    win.place(view, left = 20, top = 20)
    group = RadioGroup(action = select)
    for i, name in enumerate(cursor_names):
        group.add_item(RadioButton(title = name, value = i))
    win.place_column(group, left = view + 20, top = 20, spacing = 0)
    win.shrink_wrap((20, 20))
    win.show()
    application().run()
Пример #42
0
def main():
    view = CTV(size=(200, 300))
    win = Window(title="Canvas")
    win.add(view)
    win.shrink_wrap()
    view.become_target()
    win.show()
    app = application()
    app.menus = basic_menus() + [test_menu]
    app.run()
Пример #43
0
 def setup_menus(self, m):
     selbeg, selend = self.selection
     anysel = selbeg < selend
     anyscrap = application().query_clipboard()
     passwd = self._may_be_password and self.password
     m.cut_cmd.enabled = anysel and not passwd
     m.copy_cmd.enabled = anysel and not passwd
     m.paste_cmd.enabled = anyscrap
     m.clear_cmd.enabled = anysel
     m.select_all_cmd.enabled = True
Пример #44
0
 def paste_cmd(self):
     text = application().get_clipboard()
     self.clear_cmd()
     if self._multiline:
         self._gtk_textbuffer.insert_at_cursor(text)
     else:
         gtk_entry = self._gtk_entry
         pos = gtk_entry.get_position()
         gtk_entry.insert_text(text, pos)
         gtk_entry.set_position(pos + len(text))
Пример #45
0
 def paste_cmd(self):
     text = application().get_clipboard()
     self.clear_cmd()
     if self._multiline:
         self._gtk_textbuffer.insert_at_cursor(text)
     else:
         gtk_entry = self._gtk_entry
         pos = gtk_entry.get_position()
         gtk_entry.insert_text(text, pos)
         gtk_entry.set_position(pos + len(text))
Пример #46
0
 def _stagger(self):
     key_win = application()._ns_key_window
     if key_win:
         (x, y), (w, h) = key_win._ns_window.frame()
         p = self._ns_window.cascadeTopLeftFromPoint_(NSPoint(x, y + h))
         self._ns_window.setFrameTopLeftPoint_(p)
     else:
         (x, y), (w, h) = NSScreen.mainScreen().visibleFrame()
         ns_vis_topleft = NSPoint(x, y + h)
         self._ns_window.setFrameTopLeftPoint_(ns_vis_topleft)
 def setup_menus(self, m):
     selbeg, selend = self.selection
     anysel = selbeg < selend
     anyscrap = application().query_clipboard()
     passwd = self._may_be_password and self.password
     m.cut_cmd.enabled = anysel and not passwd
     m.copy_cmd.enabled = anysel and not passwd
     m.paste_cmd.enabled = anyscrap
     m.clear_cmd.enabled = anysel
     m.select_all_cmd.enabled = True
Пример #48
0
 def _stagger(self):
     key_win = application()._ns_key_window
     if key_win:
         (x, y), (w, h) = key_win._ns_window.frame()
         p = self._ns_window.cascadeTopLeftFromPoint_(NSPoint(x, y + h))
         self._ns_window.setFrameTopLeftPoint_(p)
     else:
         (x, y), (w, h) = NSScreen.mainScreen().visibleFrame()
         ns_vis_topleft = NSPoint(x, y + h)
         self._ns_window.setFrameTopLeftPoint_(ns_vis_topleft)
Пример #49
0
def main():
    view = CTV(size=(200, 300))
    win = Window(title="Canvas")
    win.add(view)
    win.shrink_wrap()
    view.become_target()
    win.show()
    app = application()
    app.menus = basic_menus() + [test_menu]
    app.run()
Пример #50
0
    def _remove_session_tab(self, win, view):
        selected_index = win.tabview.selected_index
        count = len(win.tabview.items)

        if selected_index < 0 or selected_index >= count:
            return

        win.tabview.remove_item(view)

        count = len(win.tabview.items)

        win.tabview.selected_index = -1

        if count == 0:
            win.close_cmd()
            application()._check_for_no_windows()
        elif selected_index < count and selected_index >= 0:
            win.tabview.selected_index = selected_index
        else:
            win.tabview.selected_index = count - 1
Пример #51
0
def test():
    app = application()
    pixmap = GLPixmap(50, 50, double_buffer=False, alpha=False)
    pixmap.with_context(draw_triangle, flush=True)
    #pixmap.with_canvas(draw_circle)
    view = PixmapTestView(pixmap, size=(180, 200))
    win = Window(title="GLPixmap", resizable=False)
    win.add(view)
    win.shrink_wrap()
    win.show()
    app.run()
 def present(self):
     self._result = None
     self._dismissed = 0
     self.show()
     app = application()
     try:
         while not self._dismissed:
             self.modal_event_loop()
     finally:
         self.hide()
     return self._result
Пример #53
0
 def setup_menus(self, m):
     if self.session and self.session.terminal:
         m.copy_cmd.enabled = self.session.terminal.has_selection()
         m.paste_cmd.enabled = self.session.terminal.has_selection() or application().query_clipboard()
         m.clear_cmd.enabled = self.session.terminal.has_selection()
         m.transfer_file_cmd.enabled = hasattr(self.session, "transfer_file")
     else:
         m.transfer_file_cmd.enabled = False
         m.copy_cmd.enabled = False
         m.paste_cmd.enabled = False
         m.clear_cmd.enabled = False
Пример #54
0
    def modal_event_loop(self):
        _ns_app = application()._ns_app

        _ns_app.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(
            self._ns_window,
            self._parent_window._ns_window if self._parent_window else None,
            None, None, None)

        _ns_app.runModalForWindow_(self._ns_window)

        _ns_app.endSheet_(self._ns_window)
Пример #55
0
    def _remove_session_tab(self, win, view):
        selected_index = win.tabview.selected_index
        count = len(win.tabview.items)

        if selected_index < 0 or selected_index >= count:
            return

        win.tabview.remove_item(view)

        count = len(win.tabview.items)

        win.tabview.selected_index = -1

        if count == 0:
            win.close_cmd()
            application()._check_for_no_windows()
        elif selected_index < count and selected_index >= 0:
            win.tabview.selected_index = selected_index
        else:
            win.tabview.selected_index = count - 1
Пример #56
0
def test():
    app = application()
    pixmap = GLPixmap(50, 50, double_buffer = False, alpha = False)
    pixmap.with_context(draw_triangle, flush = True)
    #pixmap.with_canvas(draw_circle)
    view = PixmapTestView(pixmap, size = (180, 200))
    win = Window(title = "GLPixmap", resizable = False)
    win.add(view)
    win.shrink_wrap()
    win.show()
    app.run()
Пример #57
0
 def present(self):
     self._result = None
     self._dismissed = 0
     self.show()
     app = application()
     try:
         while not self._dismissed:
             self.modal_event_loop()
     finally:
         self.hide()
     return self._result
Пример #58
0
 def setup_menus(self, m):
     if self.session and self.session.terminal:
         m.copy_cmd.enabled = self.session.terminal.has_selection()
         m.paste_cmd.enabled = self.session.terminal.has_selection() or application().query_clipboard()
         m.clear_cmd.enabled = self.session.terminal.has_selection()
         m.transfer_file_cmd.enabled = hasattr(self.session, "transfer_file")
     else:
         m.transfer_file_cmd.enabled = False
         m.copy_cmd.enabled = False
         m.paste_cmd.enabled = False
         m.clear_cmd.enabled = False
Пример #59
0
    def _win_event_message(self, message):
        try:
            if 0:
                from WinUtils import win_message_name ###
                print "Component._win_event_message: %s 0x%08x 0x%08x" % ( ###
                    win_message_name(message[1]),
                    message[2] & 0xffffffff,
                    message[3] & 0xffffffff) ###
            event = win_message_to_event(message, self)
            kind = event.kind
            if kind.startswith('key') and message[2] in win_virt_modifiers:
                #  Do not produce Events for modifier keys
                return True
            if kind == 'mouse_down' and self._win_captures_mouse:
                self._win.SetCapture()
            if self._win_tracking_mouse:
                if 'mouse' in kind:
                    self._win_mouse_event = event
                    api.PostQuitMessage(0)
                pass_message = False
            else:
                if kind == 'key_down' and event.control and event.char:
                    key = win_translate_virtual_menu_key(message[2])
                    top = self._win.GetTopLevelFrame()
                    if top._win_possible_menu_key(key, event.shift, event.option):
                        return False
                pass_message = not self._event_custom_handled(event)
            if kind == 'mouse_up' and self._win_captures_mouse:
                self._win.ReleaseCapture()
#			#<<<
#			if kind.startswith('key'):
#				if pass_message:
#					print "Component._win_event_message: passing", event ###
#				else:
#					print "Component._win_event_message: absorbing", event ###
#			#>>>
            return pass_message
        except Cancel:
            pass
        except:
            application().report_error()