示例#1
0
文件: DlgHelp.py 项目: hasii2011/PyUt
    def __init__(self, parent, ID, title):
        """
        Constructor.

        @since 1.0
        @author C.Dutoit
        """
        # dialog box
        super().__init__(parent, ID, title, DefaultPosition, Size(720, 520))

        self.Center(BOTH)

        self.html = HtmlWindow(self, -1, DefaultPosition, Size(720, 520))

        htmlFileName = resource_filename(DlgHelp.HELP_PKG_NAME, 'index.html')
        self.html.LoadPage(htmlFileName)

        self.printer = HtmlEasyPrinting()

        self.box = BoxSizer(VERTICAL)
        self.box.Add(self.html, 1, GROW)
        subbox = BoxSizer(HORIZONTAL)

        btn = Button(self, ID_BACK, _("Back"))
        self.Bind(EVT_BUTTON, self.__OnBack, id=ID_BACK)
        subbox.Add(btn, 1, GROW | ALL, 2)

        btn = Button(self, ID_FORWARD, _("Forward"))
        self.Bind(EVT_BUTTON, self.__OnForward, id=ID_FORWARD)
        subbox.Add(btn, 1, GROW | ALL, 2)

        btn = Button(self, ID_PRINT, _("Print"))
        self.Bind(EVT_BUTTON, self.__OnPrint, id=ID_PRINT)
        subbox.Add(btn, 1, GROW | ALL, 2)

        btn = Button(self, ID_VIEW_SOURCE, _("View Source"))
        self.Bind(EVT_BUTTON, self.__OnViewSource, id=ID_VIEW_SOURCE)
        subbox.Add(btn, 1, GROW | ALL, 2)

        btn = Button(self, ID_OK, _("Exit"))
        subbox.Add(btn, 1, GROW | ALL, 2)

        self.box.Add(subbox, 0, GROW | BOTTOM)
        self.SetSizer(self.box)
        self.SetAutoLayout(True)
        subbox.Fit(self)
        self.box.Fit(self)

        self.OnShowDefault(None)

        self.Show(True)
示例#2
0
    def __setupProgressDialog(self):

        self._dlgGauge = Dialog(None,
                                ID_ANY,
                                "Loading...",
                                style=STAY_ON_TOP | ICON_INFORMATION
                                | RESIZE_BORDER,
                                size=Size(250, 70))
        self._gauge: Gauge = Gauge(self._dlgGauge,
                                   ID_ANY,
                                   5,
                                   pos=Point(2, 5),
                                   size=Size(200, 30))
        self._dlgGauge.Show(True)
        wxYield()
示例#3
0
 def GetBitmapSize(self):
     if self.bitmapSize is not None:
         return self.bitmapSize
     elif self.bitmap is not None:
         return Size(self.bitmap.Width, self.bitmap.Height)
     else:
         return None
示例#4
0
    def __init__(self, parent: Window, wxID: int, title: str):

        self._preferences: Preferences = Preferences()
        appSize: Size = Size(self._preferences.startupWidth,
                             self._preferences.startupHeight)

        super().__init__(parent=parent,
                         id=wxID,
                         title=title,
                         size=appSize,
                         style=DEFAULT_FRAME_STYLE | FRAME_EX_METAL)

        self.logger: Logger = getLogger(__name__)

        self._status = self.CreateStatusBar()
        self._status.SetStatusText('Ready!')

        self._createApplicationMenuBar()
        self._githubPanel, self._todoistPanel = self._createApplicationContentArea(
        )
        # self.SetThemeEnabled(True)

        x, y = self._preferences.appStartupPosition

        if x == str(Preferences.NO_DEFAULT_X) or y == str(
                Preferences.NO_DEFAULT_Y):
            self.Center(BOTH)  # Center on the screen
        else:
            appPosition: Tuple[int, int] = self._preferences.appStartupPosition
            self.SetPosition(pt=appPosition)

        self.Bind(EVT_CLOSE, self.Close)
        self.Bind(EVT_REPOSITORY_SELECTED, self._onRepositorySelected)
        self.Bind(EVT_ISSUES_SELECTED, self._onIssuesSelected)
示例#5
0
    def __init__(self, parentWindow, toolboxOwner):
        """

        Args:
            parentWindow:   wxWindow parentWindow
            toolboxOwner:   ToolboxOwner
        """
        self.logger: Logger = getLogger(__name__)

        windowStyle = STATIC_BORDER | SYSTEM_MENU | CAPTION | FRAME_FLOAT_ON_PARENT
        super().__init__(parentWindow,
                         -1,
                         "toolbox",
                         DefaultPosition,
                         Size(100, 200),
                         style=windowStyle)

        self._tools = []
        self._category = ""
        self._clickedButton = None
        self._parentWindow = parentWindow
        self._toolboxOwner = toolboxOwner

        # Events
        self.Bind(EVT_PAINT, self.OnRefresh)
        self.Bind(EVT_CLOSE, self.evtClose)
        self.Bind(EVT_LEFT_UP, self.evtLeftUp)
        self.Bind(EVT_LEFT_DOWN, self.evtLeftDown)

        # Display myself
        self.Show(True)
示例#6
0
文件: DlgTips.py 项目: hasii2011/PyUt
    def __init__(self, parent):
        """
        """
        dialogStyle: int = RESIZE_BORDER | SYSTEM_MENU | CAPTION | FRAME_FLOAT_ON_PARENT | STAY_ON_TOP
        dialogSize: Size = Size(DEFAULT_WIDTH, DEFAULT_HEIGHT)
        super().__init__(parent, ID_ANY, _("Tips"), DefaultPosition,
                         dialogSize, dialogStyle)

        self._prefs: PyutPreferences = PyutPreferences()
        self._tipsFileName: str = PyutUtils.retrieveResourcePath(
            f'{DlgTips.TIPS_FILENAME}')

        self._tipHandler = TipHandler(fqFileName=self._tipsFileName)

        upSizer: BoxSizer = self._buildUpperDialog(
            self._tipHandler.getCurrentTipText())
        loSizer: BoxSizer = self._buildLowerDialog()

        self.SetAutoLayout(True)

        mainSizer: BoxSizer = BoxSizer(VERTICAL)

        mainSizer.Add(upSizer, WX_SIZER_NOT_CHANGEABLE, ALL | ALIGN_CENTER, 5)
        mainSizer.Add(self._chkShowTips, WX_SIZER_NOT_CHANGEABLE,
                      ALL | ALIGN_CENTER, 5)
        mainSizer.Add(loSizer, WX_SIZER_NOT_CHANGEABLE, ALL | ALIGN_CENTER, 5)

        mainSizer.Fit(self)

        self.Center(dir=VERTICAL)
        self.AcceptsFocus()
        self.SetSizer(mainSizer)

        self._bindEventHandlers()
示例#7
0
def main():
    from tests.testapp import testapp
    a = testapp('../../..')
    from gui.skin.skinparse import makeImage

    b = makeImage('popupshadow.png 12 12 25 25')
    #slices = (12, 12, 25, 25)

    f = Popup(b)

    def onbutton(e):
        #f.Fit()
        f2 = Popup(b)
        f2.Size = (300, 100)
        f2.DesiredSize = Size(300, 100)
        stack.Add(f2)

    f.button.Bind(wx.EVT_BUTTON, onbutton)

    stack = PopupStack(1, BOTTOM | LEFT)
    f.DesiredSize = Size(300, 100)
    stack.Add(f)

    ctrl = wx.Frame(None)
    #slider = wx.Slider(ctrl, value = 255, minValue = 0, maxValue = 255)
    #def onslide(e):
    #    setalpha(f, slider.Value)
    #    f.border.Refresh()

    #f.SetTransparent(slider.Value)
    #slider.Bind(wx.EVT_SLIDER, onslide)
    ctrl.Show()

    a.MainLoop()
示例#8
0
    def save(self, project):
        """
        Aave diagram in XML file.

        @param project

        @author Deve Roux
        @modified Laurent Burgbacher <*****@*****.**> : add version support
        @modified C.Dutoit 20021122 : added document container tag
        """
        dlg:    Dialog   = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70))
        xmlDoc: Document = Document()
        try:
            # xmlDoc: Document  = Document()
            top     = xmlDoc.createElement("PyutProject")
            top.setAttribute('version', str(self._this_version))
            top.setAttribute('CodePath', project.getCodePath())

            xmlDoc.appendChild(top)

            # dlg   = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70))
            gauge = Gauge(dlg, -1, 100, pos=Point(2, 5), size=Size(200, 30))
            dlg.Show(True)

            # Save all documents in the project
            for document in project.getDocuments():
                documentNode = xmlDoc.createElement("PyutDocument")
                documentNode.setAttribute('type', PyutConstants.diagramTypeAsString(document.getType()))
                top.appendChild(documentNode)

                oglObjects = document.getFrame().getUmlObjects()
                for i in range(len(oglObjects)):
                    gauge.SetValue(i * 100 / len(oglObjects))
                    oglObject = oglObjects[i]
                    if isinstance(oglObject, OglClass):
                        documentNode.appendChild(self._OglClass2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglNote):
                        documentNode.appendChild(self._OglNote2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglActor):
                        documentNode.appendChild(self._OglActor2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglUseCase):
                        documentNode.appendChild(self._OglUseCase2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglLink):
                        documentNode.appendChild(self._OglLink2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglSDInstance):
                        documentNode.appendChild(self._OglSDInstance2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglSDMessage):
                        documentNode.appendChild(self._OglSDMessage2xml(oglObject, xmlDoc))
        except (ValueError, Exception) as e:
            try:
                dlg.Destroy()
                self.logger.error(f'{e}')
            except (ValueError, Exception) as e:
                self.logger.error(f'{e}')
            PyutUtils.displayError(_("Can't save file"))
            return xmlDoc

        dlg.Destroy()

        return xmlDoc
示例#9
0
    def __init__(self, parent: Window, wxID: int = wxNewIdRef()):

        super().__init__(parent,
                         wxID,
                         'About',
                         DefaultPosition,
                         size=Size(width=390, height=250))

        self._versionFont: Font = self.GetFont()

        self._versionFont.SetFamily(FONTFAMILY_DEFAULT)

        self._version: Version = Version()  # Get the singleton

        dlgButtonsContainer: Sizer = self._createDialogButtonsContainer()

        # Main sizer
        mainSizer: BoxSizer = BoxSizer(VERTICAL)
        dialogSizer: BoxSizer = self._createUpperDialog()

        mainSizer.Add(dialogSizer, 0, ALL | ALIGN_LEFT, 5)
        mainSizer.Add(dlgButtonsContainer, 0, ALL | ALIGN_CENTER, 5)

        # noinspection PyUnresolvedReferences
        self.SetAutoLayout(True)
        # noinspection PyUnresolvedReferences
        self.SetSizer(mainSizer)
        self.Center(BOTH)
        self.SetBackgroundColour(WHITE)

        self.Bind(EVT_BUTTON, self._onOk, id=ID_OK)
        self.Bind(EVT_CLOSE, self._onOk)
示例#10
0
文件: Toolbox.py 项目: hasii2011/PyUt
    def __init__(self, parentWindow: Window, toolboxOwner):
        """

        Args:
            parentWindow:   wxWindow parentWindow
            toolboxOwner:   ToolboxOwner
        """

        from org.pyut.ui.tools.ToolboxOwner import ToolboxOwner

        self.logger: Logger = getLogger(__name__)

        windowStyle = STATIC_BORDER | SYSTEM_MENU | CAPTION | FRAME_FLOAT_ON_PARENT
        super().__init__(parentWindow,
                         ID_ANY,
                         "Tool Box",
                         DefaultPosition,
                         Size(100, 200),
                         style=windowStyle)

        self._tools: Tools = Tools([])
        self._category: Category = Category("")

        self._parentWindow: Window = parentWindow
        self._toolboxOwner: ToolboxOwner = toolboxOwner
        self._preferences: PyutPreferences = PyutPreferences()

        self.Bind(EVT_CLOSE, self.eventClose)
示例#11
0
    def testComputeSizeBasedOnRowColumnsLargeIcons(self):

        iconSize:   int = int(ToolBarIconSize.SIZE_32.value)
        actualSize: Size = Toolbox.computeSizeBasedOnRowColumns(numColumns=3, numRows=6, iconSize=iconSize)
        expectedSize: Size = Size(102, 204)
        self.logger.debug(f'Large Icons Window Size: {actualSize}')

        self.assertEqual(expectedSize, actualSize, 'Size computation changed for large icons')
示例#12
0
def main():
    glutInit()
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
    app = PySimpleApp()
    frame = Frame(None, -1, 'OpenGL Test', DefaultPosition, Size(400, 400))
    canvas = TestCanvas(frame)
    frame.Show()
    app.MainLoop()
示例#13
0
    def on_slider(self, e=None, high_quality=True):
        n = self.resize_func(self.slider.Value, high_quality=high_quality)
        self.picksize = Size(n, n)
        self.Refresh()

        if e is not None:
            self._image_changed = True
            self._image_bytes = None
示例#14
0
    def testComputeSizeBasedOnRowColumnsSmallIcons(self):

        iconSize:     int = int(ToolBarIconSize.SIZE_16.value)
        actualSize:   Size = Toolbox.computeSizeBasedOnRowColumns(numColumns=3, numRows=6, iconSize=iconSize)
        expectedSize: Size = Size(54, 108)
        self.logger.debug(f'Small Icons Window Size: {actualSize}')

        self.assertEqual(expectedSize, actualSize, 'Size computation changed for small icons')
示例#15
0
 def __init__(self, pos: Point = DefaultPosition, size: Size = Size(850, 700),
              config=None, crust_locals: dict = None):
     self._frame: ViewInspectionFrame = None
     self._pos: Point = pos
     self._size: Size = size
     self._config = config
     self._crust_locals: dict = crust_locals
     if not hasattr(self, '_app'):
         self._app: WxNode = get_root()
示例#16
0
文件: Toolbox.py 项目: hasii2011/PyUt
    def computeSizeBasedOnRowColumns(cls, numColumns: int, numRows: int,
                                     iconSize: int):

        width: int = round(
            iconSize * numColumns) + (numColumns * Toolbox.TOOLBOX_H_GAP)
        height: int = round(
            iconSize * numRows) + (numRows * Toolbox.TOOLBOX_V_GAP)

        return Size(width, height)
示例#17
0
    def __init__(self, parent, ID, pyutModel: Union[PyutClass, PyutInterface]):
        """

        Args:
            parent:
            ID:
            pyutModel:
        """

        super().__init__(parent, ID, _("Description Edit"))

        # Associated PyutLink
        self._pyutModel: Union[PyutClass, PyutInterface] = pyutModel

        self.SetSize(Size(416, 200))

        # init members vars
        self._text = self._pyutModel.description
        self._returnAction = OK  # describe how the user exited the dialog box

        # labels
        StaticText(self, ID_ANY, _("Class description"), Point(8, 8))

        # text
        self._txtCtrl: TextCtrl = TextCtrl(self, TXT_COMMENT, self._text,
                                           Point(8, 24), Size(392, 100),
                                           TE_MULTILINE)

        # Set the focus
        self._txtCtrl.SetFocus()

        # text events
        self.Bind(EVT_TEXT, self._onTxtNoteChange, id=TXT_COMMENT)

        # Ok/Cancel
        Button(self, OK, _("&Ok"), Point(120, 140))
        Button(self, CANCEL, _("&Cancel"), Point(208, 140))

        # button events
        self.Bind(EVT_BUTTON, self._onCmdOk, id=OK)
        self.Bind(EVT_BUTTON, self._onCmdCancel, id=CANCEL)

        self.Centre()
        self.ShowModal()
示例#18
0
    def __init__(self, parent, ID, title):
        Frame.__init__(self, parent, ID, title, DefaultPosition, Size(300, 200))
        menu = Menu()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = MenuBar()
        menuBar.Append(menu, "&File")
        self.SetMenuBar(menuBar)
        EVT_MENU(self, ID_EXIT, self.DoExit)

        # make sure reactor.stop() is used to stop event loop:
        EVT_CLOSE(self, lambda evt: reactor.stop())
示例#19
0
    def __init__(self,
                 parent: wx.Window,
                 id: int = wx.ID_ANY,
                 pos: wx.Point = wx.DefaultPosition,
                 size: wx.Size = wx.DefaultSize,
                 style: int = wx.NO_BORDER,
                 validator: wx.Validator = wx.DefaultValidator,
                 name: str = "DoublePassword",
                 value: str = ""):
        super().__init__(parent=parent,
                         id=id,
                         pos=pos,
                         size=size,
                         style=style,
                         validator=validator,
                         name=name)

        sizer = wx.BoxSizer(wx.VERTICAL)
        halfheight = size.GetHeight()
        if halfheight > 0:
            halfheight = halfheight / 2
        self.password1 = wx.TextCtrl(parent=self,
                                     name=name + '1',
                                     value=value if value is not None else "",
                                     size=wx.Size(size.GetWidth(), halfheight),
                                     style=style | wx.TE_PASSWORD)
        self.password1.Bind(wx.EVT_TEXT, self.text1_changed)
        sizer.Add(self.password1)

        self.password2 = wx.TextCtrl(parent=self,
                                     name=name + '2',
                                     value=value if value is not None else "",
                                     size=wx.Size(size.GetWidth(), halfheight),
                                     style=style | wx.TE_PASSWORD)
        self.password2.Bind(wx.EVT_TEXT, self.text2_changed)
        sizer.Add(self.password2)
        self.SetSizerAndFit(sizer)
示例#20
0
    def RescaleBitmap(bmp: wx.Bitmap, sizeNeeded: wx.Size):
        """

		:param bmp:
		:type bmp: wx.Bitmap
		:param sizeNeeded:
		:type sizeNeeded: wx.Size
		"""

        if not sizeNeeded.IsFullySpecified():
            raise ValueError("New size must be given")

        img = bmp.ConvertToImage()
        img.Rescale(sizeNeeded.x, sizeNeeded.y)
        bmp = wx.Bitmap(img)
示例#21
0
文件: DlgTips.py 项目: hasii2011/PyUt
    def _buildUpperDialog(self, tip: str) -> BoxSizer:

        bmp: Bitmap = TipsLogo.GetBitmap()
        self._picture: StaticBitmap = StaticBitmap(self, ID_ANY, bmp)
        self._label: StaticText = StaticText(self,
                                             ID_ANY,
                                             tip,
                                             size=Size(DEFAULT_WIDTH * 0.8,
                                                       DEFAULT_HEIGHT * 0.8),
                                             style=ST_NO_AUTORESIZE)

        upSizer: BoxSizer = BoxSizer(HORIZONTAL)
        upSizer.Add(self._picture, WX_SIZER_NOT_CHANGEABLE, ALL | ALIGN_CENTER,
                    5)
        upSizer.Add(self._label, WX_SIZER_CHANGEABLE, ALL | ALIGN_CENTER, 5)

        return upSizer
示例#22
0
    def _createHTMLPanel(self, sizedPanel: SizedPanel):

        htmlPanel: SizedPanel = SizedPanel(parent=sizedPanel, id=ID_ANY)
        htmlPanel.SetSizerType('horizontal')

        # noinspection PyUnresolvedReferences
        htmlPanel.SetSizerProps(expand=True)

        htmlSize: Size = Size(width=440, height=128)
        self._html = HtmlWindow(parent=htmlPanel,
                                id=ID_ANY,
                                size=htmlSize,
                                style=NO_FULL_REPAINT_ON_RESIZE)

        helpText: str = Resources.retrieveResourceText(
            ResourceTextType.SIMPLE_HELP)
        self._html.SetPage(helpText)
示例#23
0
    def __init__(self, parent, dpi=(1, 1)):
        Dialog.__init__(self,
                        parent,
                        id=ID_ANY,
                        title=u" 关于 mHosts - v%s" % Settings.version(),
                        pos=DefaultPosition,
                        style=DEFAULT_DIALOG_STYLE | FRAME_FLOAT_ON_PARENT,
                        size=Size(400 * dpi[0], 300 * dpi[1]))
        self.SetSizeHints(DefaultSize, DefaultSize)
        self.SetIcon(Icon(iconPath, BITMAP_TYPE_ICO))
        bSizer2 = BoxSizer(VERTICAL)

        self.aboutDialog = AboutView(self, self.GetSize())
        bSizer2.Add(self.aboutDialog, 0, EXPAND, 0)

        self.SetSizer(bSizer2)
        self.Layout()

        self.Centre(BOTH)
示例#24
0
    def __init__(self, dpi=(1, 1)):
        width = 300 * dpi[0]
        height = 80 * dpi[1]
        screenSize = DisplaySize()
        x = screenSize[0] - width - 10 * dpi[0],
        y = screenSize[1] - height - 100 * dpi[1]
        Frame.__init__(self,
                       parent=None,
                       id=ID_ANY,
                       pos=Point(x[0], y),
                       size=Size(width, height),
                       style=SIMPLE_BORDER | TRANSPARENT_WINDOW | STAY_ON_TOP
                       | FRAME_NO_TASKBAR,
                       name=EmptyString)

        bSizer4 = BoxSizer(VERTICAL)

        self.msgTitle = StaticText(self, ID_ANY, u"MyLabel", DefaultPosition,
                                   DefaultSize, 0)
        self.msgTitle.Wrap(-1)

        self.msgTitle.SetFont(
            Font(13, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_BOLD,
                 False, EmptyString))

        bSizer4.Add(self.msgTitle, 0, ALL, 5)

        self.msgContent = StaticText(self, ID_ANY, u"MyLabel", DefaultPosition,
                                     DefaultSize, 0)
        self.msgContent.Wrap(-1)

        self.msgContent.SetFont(
            Font(12, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL,
                 False, EmptyString))

        bSizer4.Add(self.msgContent, 0, EXPAND, 5)

        self.SetSizer(bSizer4)
        self.Layout()
        # colorWhite = Colour(255, 255, 255)
        self.SetBackgroundColour(Colour(240, 240, 240))
示例#25
0
 def __init__(self):
     """Constructor"""
     Dialog.__init__(self, None, title="Bad Cop", size=Size(500, 100))
     ico = Icon('logo.ico', BITMAP_TYPE_ICO)
     self.SetIcon(ico)
     self.message = StaticText(
         self, label="Click Profile, then insert device and click Test")
     self.profile = Button(self, label="Profile")
     self.test = Button(self, label="Test")
     self.test.Disable()
     self.profile.Bind(EVT_BUTTON, self.profileusb)
     self.test.Bind(EVT_BUTTON, self.testusb)
     self.Bind(EVT_CLOSE, self.onclose)
     main_sizer = BoxSizer(VERTICAL)
     t_sizer = BoxSizer(HORIZONTAL)
     p_sizer = BoxSizer(HORIZONTAL)
     t_sizer.Add(self.message, 0, ALL | CENTER, 5)
     p_sizer.Add(self.profile, 0, ALL | CENTER, 5)
     p_sizer.Add(self.test, 0, ALL | CENTER, 5)
     main_sizer.Add(p_sizer, 0, ALL | CENTER, 5)
     main_sizer.Add(t_sizer, 0, ALL | EXPAND | CENTER, 5)
     self.SetSizer(main_sizer)
示例#26
0
    def set_image(self, image, first=False):
        self.Parent.set_screen_button_mode()

        if isinstance(image, str):
            log.info('set_image received bytes')
            self._image_bytes = image
            image = ImageFromString(image)

        if not first:
            self._image_changed = True

        self._set_imageorbitmap(image)

        self.dim = max(self.image.Width, self.image.Height)
        if self.dim > max(MAX_BICON_SIZE):
            self._image_changed = True

        self.adjustment = (0, 0)

        # first: is it the normal size? if so, disable the slider
        if self.image.Width == self.normal and self.image.Height == self.normal:
            self.slider.Enable(False)
            self.picksize = Size(self.normal, self.normal)
        else:
            self.slider.Enable(True)

            if self.dim < self.normal: f = self.f1  # case 1: small
            elif self.dim < self.maxpick:
                f = self.f2  # case 2: smaller than max
            else:
                f = self.f3  # case 3: bigger than max
            self.resize_func = f

            self.on_slider()

        self.Refresh()
示例#27
0
文件: UberBar.py 项目: sgricci/digsby
    def UpdateSkin(self):
        """
            Update local skin references
            and updates skins for buttons
        """

        key = self.skinkey
        self.native = not key
        if self.native:
            if self.uxthemeable:
                self.OpenNativeTheme()
                self.bg = None
            else:
                self.bg = SkinColor(
                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))

            self.padding = Point(2, 2)
            self.margins = Margins([0, 0, 0, 0])

            self.buttonskin = None
            self.menuskin = None

        else:

            self.CloseNativeTheme()

            self.padding = skin.get(key + '.padding', Point(2, 2))
            self.margins = skin.get(key + '.margins', Margins([0, 0, 0, 0]))

            self.bg = skin.get(
                key + '.background', lambda: SkinColor(
                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)))
            self.buttonskin = skin.get(key + '.buttonskin', None)
            self.menuskin = skin.get(key + '.menuskin', None)

        s = self.Sizer
        if s:
            s.Detach(1)
            s.Detach(1)
            s.Add(Size(self.margins.left, self.margins.top), (0, 0))
            s.Add(Size(self.margins.right, self.margins.bottom), (2, 2))
            s.Children[0].SetBorder(self.padding.y)
            for child in self.content.Children:
                child.SetBorder(self.padding.x)

        for object in self.children + self.staticchildren:
            if isinstance(object, UberButton):
                object.SetSkinKey(self.buttonskin, True)
                if object.menu:
                    object.menu.SetSkinKey(self.buttonskin)

            elif isinstance(object, FontDropDown):
                object.SetSkinKey(self.buttonskin)
                object.SetMenuSkinKey(self.menuskin)

        if hasattr(self, 'overflowbutton'):
            self.overflowbutton.SetSkinKey(self.buttonskin)
            self.overflowmenu.SetSkinKey(self.menuskin)

        if not self.overflowmode and hasattr(self, 'content'):
            spacersizer = self.spacersizer
            spacersizer.Detach(0)
            spacersizer.Add((self.padding.x, 1), 0, EXPAND)

        wx.CallAfter(self.Layout)
示例#28
0
文件: UberBar.py 项目: sgricci/digsby
    def __init__(self,
                 parent,
                 id=wx.ID_ANY,
                 skinkey=None,
                 overflowmode=False,
                 name='UberBar',
                 alignment=None):

        SimplePanel.__init__(self, parent, FULL_REPAINT_ON_RESIZE)
        UberWidget.__init__(self, 'toolbar')

        self.ChildPaints = Delegate()

        # Initing variables
        self.alignment = alignment if alignment and not overflowmode else ALIGN_LEFT
        self.overflowmode = overflowmode
        self.navimode = False
        self.active = None
        self.children = []
        self.staticchildren = []
        self.overflowed = []
        self.focus = None
        self.lastheight = 0

        Bind = self.Bind
        Bind(wx.EVT_PAINT, self.OnBGPaint)
        Bind(wx.EVT_SIZE, self.OnReSize)

        self.keyletters = {}

        self.tlmargins = Size()
        self.brmargins = Size()

        #Start setting up an alternaitve Native Menubar for native mode

        self.SetSkinKey(skinkey, True)

        self.content = wx.BoxSizer(HORIZONTAL)
        sizer = self.Sizer = wx.GridBagSizer()
        sizer.SetEmptyCellSize(wx.Size(0, 0))

        contentFlag = TOP | BOTTOM | (self.alignment | EXPAND if self.alignment
                                      == ALIGN_LEFT else self.alignment)

        sizer.Add(self.content, (1, 1),
                  flag=contentFlag,
                  border=self.padding.y)
        sizer.Add(Size(self.margins.left, self.margins.top), (0, 0))
        sizer.Add(Size(self.margins.right, self.margins.bottom), (2, 2))
        sizer.AddGrowableCol(1, 1)
        sizer.AddGrowableRow(1, 1)
        #

        #Set up the menu for the overflowed items if overflow mode
        if overflowmode:
            self.overflowmenu = SimpleMenu(self, self.menuskin)
            self.overflowbutton = UberButton(self,
                                             skin=self.buttonskin,
                                             type='menu',
                                             menu=self.overflowmenu)
            self.content.Add((self.padding.x, 1), 1, EXPAND)
            self.content.Add(self.overflowbutton, 0, RIGHT | EXPAND,
                             self.padding.x)
            self.staticchildren.append(self.overflowbutton)
        else:
            spacersizer = self.spacersizer = wx.BoxSizer(wx.HORIZONTAL)
            spacersizer.Add((self.padding.x, 1), 0, EXPAND)
            self.content.Add(spacersizer, 0, EXPAND)

        self.GenWidthRestriction()
示例#29
0
    def DoZoomOut(self, ax: int, ay: int):
        """
        Do the 'zoom out' in the way to have the clicked point (ax, ay) as
        the central point of new view.
        If one or many 'zoom in' where performed before, then we just suppress the
        last one from the zoom stack. Else, we add the default inverted zoom factor
        to the stack.

        @param ax  abscissa of the clicked point
        @param ay  ordinate of the clicked point
        """

        # number of pixels per unit of scrolling
        xUnit, yUnit = self.GetScrollPixelsPerUnit()

        # position of the upper left corner of the client area
        # (work area that is visible) in scroll units.
        viewStartX, viewStartY = self.GetViewStart()

        # Get the client and virtual size of the work area, where
        # the client size is the size of the work area that is
        # visible and the virtual is the whole work area's size.
        clientWidth, clientHeight = self.GetClientSize()
        virtualWidth, virtualHeight = self.GetVirtualSize()

        # transform event coordinates to get them relative to the upper left corner of
        # the virtual screen (avoid the case where that corner is on a shape and
        # get its coordinates relative to the shape).
        if ax >= viewStartX * xUnit and ay >= viewStartY * yUnit:
            x = ax
            y = ay
        else:
            x = ax + viewStartX * xUnit
            y = ay + viewStartY * yUnit

        # calculation of the upper-left corner of a zoom area whose
        # size is the half of the diagram frame and which is centred
        # on the clicked point. This calculation is done in the way to
        # get the zoom area centred in the middle of the virtual screen.
        dx = virtualWidth / 2 - x
        dy = virtualHeight / 2 - y

        minZoomFactor = self.GetMinZoomFactor()
        # minZoomReached = False        not used

        # if the view is enlarged, then we just remove the last
        # zoom in factor that has been applied. Else, we apply
        # the default one in inverted.
        if self._zoomLevel > 0:
            zoomFactor = 1 / self._zoomStack.pop()
            self._zoomLevel -= 1
        else:
            zoomFactor = 1 / self.GetDefaultZoomFactor()
            # check if minimal zoom has been reached
            minZoomReached = minZoomFactor >= (self.GetCurrentZoom() *
                                               zoomFactor)
            if not minZoomReached:
                self._zoomStack.append(zoomFactor)
                self._zoomLevel -= 1
            else:
                zoomFactor = minZoomFactor / self.GetCurrentZoom()
                if zoomFactor != 1:
                    self._zoomStack.append(zoomFactor)
                    self._zoomLevel -= 1

        # set the offsets between the view and the model for
        # each shape on this diagram frame.
        self.SetXOffset((self.GetXOffset() + dx) * zoomFactor)
        self.SetYOffset((self.GetYOffset() + dy) * zoomFactor)

        # updates the shapes (view) position and dimensions from
        # their model in the light of the new zoom factor and offsets.
        for shape in self.GetDiagram().GetShapes():
            shape.UpdateFromModel()

        # resize the virtual screen in order to match with the zoom
        virtualWidth = virtualWidth * zoomFactor
        virtualHeight = virtualHeight * zoomFactor
        virtualSize = Size(virtualWidth, virtualHeight)
        self.SetVirtualSize(virtualSize)

        # perform the scrolling in the way to have the zoom area visible
        # and centred on the virtual screen.
        scrollX = (virtualWidth - clientWidth) // 2 // xUnit
        scrollY = (virtualHeight - clientHeight) // 2 // yUnit
        self.Scroll(scrollX, scrollY)
示例#30
0
    def DoZoomIn(self, ax, ay, width=0, height=0):
        """
        added by P. Dabrowski <*****@*****.**> (11.11.2005)

        Do the "zoom in" fitted on the selected area or with a default factor
        and the clicked point as central point of the zoom.
        The maximal zoom that can be reached is :

            self.GetMaxLevelZoom() * self.GetDefaultZoomFactor()

        If the maximal zoom level is reached, then the shapes are just centered
        on the selected area or on the clicked point.

        @param ax        :  abscissa of the upper left corner of the selected
                            area or abscissa of the central point of the zoom

        @param ay        :  ordinate of the upper left corner of the selected
                            area or ordinate of the central point of the zoom

        @param width    :   width of the selected area for the zoom

        @param height   :   height of the selected area for the zoom
        """

        # number of pixels per unit of scrolling
        xUnit, yUnit = self.GetScrollPixelsPerUnit()

        # position of the upper left corner of the client area
        # (work area that is visible) in scroll units.
        viewStartX, viewStartY = self.GetViewStart()

        # Get the client and virtual size of the work area, where
        # the client size is the size of the work area that is
        # visible and the virtual is the whole work area's size.
        clientWidth, clientHeight = self.GetClientSize()
        virtualWidth, virtualHeight = self.GetVirtualSize()

        # maximal zoom factor that can be applied
        # maxZoomFactor = self.GetMaxLevelZoom() * self.GetDefaultZoomFactor()
        maxZoomFactor = self.GetMaxZoomFactor()

        # transform event coordinates to get them relative to the upper left corner of
        # the virtual screen (avoid the case where that corner is on a shape and
        # get its coordinates relative to the client view).
        if ax >= viewStartX * xUnit and ay >= viewStartY * yUnit:
            x = ax
            y = ay
        else:
            x = ax + viewStartX * xUnit
            y = ay + viewStartY * yUnit

        # to get the upper left corner of the zoom selected area in the
        # case where we select first the bottom right corner.
        if width < 0:
            x = x - width
        if height < 0:
            y = y - height

        # init the zoom's offsets and factor
        # zoomFactor = 1
        # dx = 0
        # dy = 0

        # if there is no selected area but a clicked point, a default
        # zoom is performed with the clicked point as center.
        if width == 0 or height == 0:
            zoomFactor = self.GetDefaultZoomFactor()
            # check if the zoom factor that we are to apply combined with the
            # previous ones won't be beyond the maximal zoom. If it's the case,
            # we proceed to the calculation of the zoom factor that allows to
            # exactly reach the maximal zoom.
            maxZoomReached = maxZoomFactor <= (self.GetCurrentZoom() *
                                               zoomFactor)
            if maxZoomReached:
                zoomFactor = maxZoomFactor / self.GetCurrentZoom()
            # if the view is reduced, we just eliminate the
            # last zoom out performed
            if self._zoomLevel < 0:
                self._zoomStack.pop()
                self._zoomLevel += 1
            else:
                if zoomFactor > 1.0:
                    self._zoomStack.append(zoomFactor)
                    self._zoomLevel += 1

            # calculation of the upper-left corner of a zoom area whose
            # size is the half of the diagram frame and which is centred
            # on the clicked point. This calculation is done in the way to
            # get the zoom area centred in the middle of the virtual screen.
            dx = virtualWidth / 2 - x
            dy = virtualHeight / 2 - y

        else:
            # to be sure to get all the shapes in the selected zoom area
            if width > height:
                zoomFactor = clientWidth / abs(width)
            else:
                zoomFactor = clientHeight / abs(height)

            # check if the zoom factor that we are to apply combined with the
            # previous ones won't be beyond the maximal zoom. If it's the case,
            # we proceed to the calculation of the zoom factor that allows to
            # exactly reach the maximal zoom.
            maxZoomReached = maxZoomFactor <= self.GetCurrentZoom(
            ) * zoomFactor
            if maxZoomReached:
                zoomFactor = maxZoomFactor / self.GetCurrentZoom()

            # calculation of the upper-left corner of a zoom area whose
            # size is the half of the diagram frame and which is centred
            # on the clicked point. This calculation is done in the way to
            # get the zoom area centred in the middle of the virtual screen.
            dx = virtualWidth / 2 - x - (clientWidth / zoomFactor / 2.0)
            dy = virtualHeight / 2 - y - (clientHeight / zoomFactor / 2.0)

            # we have to check if the "zoom in" on a reduced view produces
            # another less reduced view or an enlarged view. For this, we
            # get the global current zoom, multiply by the zoom factor to
            # obtain only one zoom factor.
            if self._zoomLevel < 0:

                globalFactor = zoomFactor * self.GetCurrentZoom()
                self._zoomStack = []
                self._zoomStack.append(globalFactor)

                if globalFactor < 1.0:
                    self._zoomLevel = -1  # the view is still reduced
                elif globalFactor > 1.0:
                    self._zoomLevel = 1  # the view is enlarged
                else:
                    self._zoomLevel = 0  # the zoom in is just equal to all the zoom out previously applied
            else:
                if zoomFactor > 1.0:
                    self._zoomStack.append(zoomFactor)
                    self._zoomLevel += 1

        # set the offsets between the model and the view
        self.SetXOffset((self.GetXOffset() + dx) * zoomFactor)
        self.SetYOffset((self.GetYOffset() + dy) * zoomFactor)

        # updates the shapes (view) position and dimensions from
        # their models in the light of the new zoom factor and offsets.
        for shape in self.GetDiagram().GetShapes():
            shape.UpdateFromModel()

        # resize the virtual screen in order to match with the zoom
        virtualWidth = virtualWidth * zoomFactor
        virtualHeight = virtualHeight * zoomFactor
        virtualSize = Size(virtualWidth, virtualHeight)
        self.SetVirtualSize(virtualSize)

        # perform the scrolling in the way to have the zoom area visible
        # and centred on the virtual screen.
        scrollX = (virtualWidth - clientWidth) // 2 // xUnit
        scrollY = (virtualHeight - clientHeight) // 2 // yUnit
        self.Scroll(scrollX, scrollY)