Esempio n. 1
0
 def _update(self, value):
     maxval = self.maxval
     if maxval == 0:
         Ctl.IdleControls(self.w)
     else:
         if maxval > 32767:
             value = int(value / (maxval / 32767.0))
             maxval = 32767
         maxval = int(maxval)
         value = int(value)
         progbar = self.d.GetDialogItemAsControl(3)
         progbar.SetControlMaximum(maxval)
         progbar.SetControlValue(value)
     ready, ev = Evt.WaitNextEvent(Events.mDownMask, 1)
     if ready:
         what, msg, when, where, mod = ev
         part = Win.FindWindow(where)[0]
         if Dlg.IsDialogEvent(ev):
             ds = Dlg.DialogSelect(ev)
             if ds[0] and ds[1] == self.d and ds[-1] == 1:
                 self.w.HideWindow()
                 self.w = None
                 self.d = None
                 raise KeyboardInterrupt, ev
         elif part == 4:
             self.w.DragWindow(where, screenbounds)
         else:
             MacOS.HandleEvent(ev)
     return
Esempio n. 2
0
    def open(self):
        self.menu = menu = FrameWork.Menu(self._parentwindow.parent.menubar, 'Foo', -1)

        for i in range(len(self._items)):
            item = self._items[i]
            if type(item) == StringType:
                menuitemtext = object = item
            elif type(item) == TupleType and len(item) == 2:
                menuitemtext, object = item
                self._items[i] = object
            else:
                raise Wbase.WidgetsError, "illegal itemlist for popup menu"
            menuitem = FrameWork.MenuItem(menu, menuitemtext, None, None)

        self._calcbounds()
        self._control = Ctl.NewControl(self._parentwindow.wid,
                                        self._bounds,
                                        self._title,
                                        1,
                                        self._value,
                                        self.menu.id,
                                        self._max,
                                        self._procID,
                                        0)
        self.SetPort()
        self.enable(self._enabled)
Esempio n. 3
0
    def do_click(self, down, local, evt):
        (what, message, when, where, modifiers) = evt
        Qd.SetPort(self.wid)
        Qd.RGBBackColor(self.bg_color)
        if down:
            # Check for control
            ptype, ctl = Ctl.FindControl(local, self.wid)
            if ptype and ctl:
                if ptype in TRACKED_PARTS:
                    dummy = ctl.TrackControl(local, self._scrollbarcallback)
                else:
                    part = ctl.TrackControl(local)
                    if part:
                        self._scrollbarcallback(ctl, part)
                return
            # Remember, so we react to mouse-up next time
            self.last_mouse_was_down = 1
        else:
            if not self.last_mouse_was_down:
                # Two ups in a row,
                # probably due to window-raise or something
                return
            self.last_mouse_was_down = 0

            # Check for anchor
            if not self._cbanchor:
                return
            off, edge = self.ted.WEGetOffset(local)
            for i in range(len(self.anchor_offsets)):
                p0, p1 = self.anchor_offsets[i]
                if p0 <= off < p1:
                    href = self.anchor_hrefs[i]
                    self._cbanchor(href)
                    return
Esempio n. 4
0
 def _settext(self, text):
     text = _string2dialog(text)
     h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT)
     if self._is_passwd_dialog:
         ControlAccessor.SetControlData(
             h, Controls.kControlEditTextPart,
             Controls.kControlEditTextPasswordTag, text)
         Ctl.SetKeyboardFocus(self._onscreen_wid, h,
                              Controls.kControlEditTextPart)
     else:
         Dlg.SetDialogItemText(h, text)
         self._dlg.SelectDialogItemText(ITEM_INPUT_TEXT, 0, 32767)
Esempio n. 5
0
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
    """Display a PROMPT string and a text entry field with a DEFAULT string.
    The string is displayed as bullets only.
    
    Return the contents of the text entry field when the user clicks the
    OK button or presses Return.
    Return None when the user clicks the Cancel button.
    
    If omitted, DEFAULT is empty.
    
    The PROMPT and DEFAULT strings, as well as the return value,
    can be at most 255 characters long.
    """
    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)'
        return
    else:
        h = d.GetDialogItemAsControl(3)
        SetDialogItemText(h, lf2cr(prompt))
        pwd = d.GetDialogItemAsControl(4)
        bullets = '\xa5' * len(default)
        SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag,
                       default)
        d.SelectDialogItemText(4, 0, 999)
        Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(Dialogs.ok)
        d.SetDialogCancelItem(Dialogs.cancel)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(
                    GetControlData(pwd, kControlEditTextPart,
                                   kControlEditTextPasswordTag))
            if n == 2:
                return

        return
Esempio n. 6
0
 def _createscrollbars(self, reset=0):
     #
     # See if we need them.
     #
     if self.bary:
         self.bary.DisposeControl()
         if self.controlhandler:
             self.controlhandler._del_control(self.bary)
     self.bary = None
     l, t, r, b = self.rect
     if reset:
         self.ted.WECalText()
         self.ted.WESelView()
     vr = self.ted.WEGetViewRect()
     dr = self.ted.WEGetDestRect()
     need_bary = ((dr[3] - dr[1]) >= (vr[3] - vr[1]))
     if need_bary:
         vr = l + LEFTMARGIN, t + TOPMARGIN, r - (
             RIGHTMARGIN + SCROLLBARWIDTH - 1), b - BOTTOMMARGIN
         dr = dr[0], dr[1], dr[0] + vr[2] - vr[0], dr[3]
         self.ted.WESetViewRect(vr)
         self.ted.WESetDestRect(dr)
         self.ted.WECalText()
         vr = self.ted.WEGetViewRect()
         dr = self.ted.WEGetDestRect()
         rect = r - (SCROLLBARWIDTH - 1), t - 1, r + 1, b + 1
         vy = self._getybarvalue()
         self.bary = Ctl.NewControl(self.wid, rect, "", 1, vy, 0,
                                    dr[3] - dr[1] - (vr[3] - vr[1]), 16, 0)
         if not self.activated: self.bary.DeactivateControl()
         self._updatedocview()
         if self.controlhandler:
             self.controlhandler._add_control(self.bary,
                                              self._scrollbarcallback,
                                              self._scrollbarcallback)
     else:
         vr = l + LEFTMARGIN, t + TOPMARGIN, r - RIGHTMARGIN, b - BOTTOMMARGIN
         dr = dr[0], dr[1], dr[0] + vr[2] - vr[0], dr[3]
         self.ted.WESetViewRect(vr)
         self.ted.WESetDestRect(dr)
         self.ted.WECalText()
         self.ted.WEScroll(vr[0] - dr[0], vr[1] - dr[1])  # Test....
Esempio n. 7
0
    def open(self):
        self._calcbounds()

        # NewControl doesn't accept 32-bit value, min, or max, so for consistency
        # with the new 32-bit set/get methods, out-of-range values are initially
        # set as zero, followed by a 32-bit set of the actual value.
        # Values not representable in 16 bits will fail on MacOS 8.1, however
        # the vast majority of control usage should still be compatible.
        _value, _min, _max = self._value, self._min, self._max
        if -32768 <= _value <= 32767:
            bigvalue = None
        else:
            bigvalue = _value
            _value = 0
        if -32768 <= _min <= 32767:
            bigmin = None
        else:
            bigmin = _min
            _min = 0
        if -32768 <= _max <= 32767:
            bigmax = None
        else:
            bigmax = _max
            _max = 0
        self._control = Ctl.NewControl(self._parentwindow.wid, self._bounds,
                                       self._title, 1, _value, _min, _max,
                                       self._procID, 0)
        if bigvalue:
            self._control.SetControl32BitValue(bigvalue)
        if bigmin:
            self._control.SetControl32BitMinimum(bigmin)
        if bigmax:
            self._control.SetControl32BitMaximum(bigmax)
        if self._viewsize:
            try:
                self._control.SetControlViewSize(self._viewsize)
                # Not available in MacOS 8.1, but that's OK since it only affects
                # proportional scrollbars which weren't available in 8.1 either.
            except NotImplementedError:
                pass
        self.enable(self._enabled)
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)'
        return
    else:
        h = d.GetDialogItemAsControl(3)
        SetDialogItemText(h, lf2cr(prompt))
        pwd = d.GetDialogItemAsControl(4)
        bullets = '\xa5' * len(default)
        SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag,
                       default)
        d.SelectDialogItemText(4, 0, 999)
        Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(Dialogs.ok)
        d.SetDialogCancelItem(Dialogs.cancel)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(
                    GetControlData(pwd, kControlEditTextPart,
                                   kControlEditTextPasswordTag))
            if n == 2:
                return

        return
Esempio n. 9
0
"""Easy to use dialogs.
Esempio n. 10
0
 def setkeyboardfocus(self):
     Ctl.SetKeyboardFocus(self.wid, self.control,
                          Controls.kControlListBoxPart)