コード例 #1
0
def SetBgImageAndSize(fileName, Shape=None):
    try:
        import clr
        #from globals import *
        clr.AddReference("System.Drawing")
        from System.Drawing import Image
        from System.Drawing import SizeF

        im = Image.FromFile(fileName)
        sizePx = im.Size
        vertDPI = im.VerticalResolution
        horzDPI = im.HorizontalResolution
        im.Dispose()

        # calculate the actual size of the image in points as this is the unit that
        # PowerPoint uses
        size = SizeF(72.0 * float(sizePx.Width) / horzDPI,
                     72 * float(sizePx.Height) / horzDPI)
        SetBgImage(fileName, Shape)
        Shape.Width = size.Width
        Shape.Height = size.Height
        Shape.TextFrame.TextRange.Text = ""
        return True
    except:
        raise
コード例 #2
0
def _get_ppt_image_size(_image_file_path, Shape=None):
    r"""Return the Width and Height in points of the image passed in.

    Used by set_bg_image_and_size().

    Example:

    | _image_file_path = "transformations\\utils\\images\\greenarrow.png"
    | size=_get_ppt_image_size(_image_file_path)
    | print size.Width, size.Height

    """

    import clr
    clr.AddReference("System.Drawing")
    from System.Drawing import Image
    from System.Drawing import SizeF

    _im = Image.FromFile(_image_file_path)

    _size_px = _im.Size
    _vert_dpi = _im.VerticalResolution
    _horz_dpi = _im.HorizontalResolution
    _im.Dispose()

    # calculate the actual size of the image in points as this is the unit
    # that PowerPoint uses
    _width = 72 * float(_size_px.Width) / _horz_dpi
    _height = 72 * float(_size_px.Height) / _vert_dpi

    _size = SizeF(_width, _height)
    return _size
コード例 #3
0
        def __init__(self, window):
            self.uid = window.uid
            self.pywebview_window = window
            self.url = None
            self.Text = window.title
            self.Size = Size(window.initial_width, window.initial_height)
            self.MinimumSize = Size(window.min_size[0], window.min_size[1])
            self.BackColor = ColorTranslator.FromHtml(window.background_color)

            if window.initial_x is not None and window.initial_y is not None:
                self.move(window.initial_x, window.initial_y)
            else:
                self.StartPosition = WinForms.FormStartPosition.CenterScreen

            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not window.resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            if window.minimized:
                self.WindowState = WinForms.FormWindowState.Minimized

            # Application icon
            handle = windll.kernel32.GetModuleHandleW(None)
            icon_path = os.path.join(os.path.dirname(os.path.realpath(importlib.util.find_spec("bcml").origin)), "data", "bcml.ico")
            icon_handle = windll.shell32.ExtractIconW(handle, icon_path, 0)

            if icon_handle != 0:
                self.Icon = Icon.FromHandle(
                    IntPtr.op_Explicit(Int32(icon_handle))
                ).Clone()

            windll.user32.DestroyIcon(icon_handle)

            self.closed = window.closed
            self.closing = window.closing
            self.shown = window.shown
            self.loaded = window.loaded
            self.url = window.url
            self.text_select = window.text_select
            self.on_top = window.on_top

            self.is_fullscreen = False
            if window.fullscreen:
                self.toggle_fullscreen()

            if window.frameless:
                self.frameless = window.frameless
                self.FormBorderStyle = 0
            CEF.create_browser(window, self.Handle.ToInt32(), BrowserView.alert)

            self.Shown += self.on_shown
            self.FormClosed += self.on_close
            self.FormClosing += self.on_closing

            self.Resize += self.on_resize
コード例 #4
0
        def __init__(self, window):
            self.uid = window.uid
            self.pywebview_window = window
            self.real_url = None
            self.Text = window.title
            self.ClientSize = Size(window.width, window.height)
            self.MinimumSize = Size(window.min_size[0], window.min_size[1])
            self.BackColor = ColorTranslator.FromHtml(window.background_color)

            if window.x is not None and window.y is not None:
                self.move(window.x, window.y)
            else:
                self.StartPosition = WinForms.FormStartPosition.CenterScreen

            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not window.resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            # Application icon
            handle = windll.kernel32.GetModuleHandleW(None)
            icon_handle = windll.shell32.ExtractIconW(handle, sys.executable, 0)

            if icon_handle != 0:
                self.Icon = Icon.FromHandle(IntPtr.op_Explicit(Int32(icon_handle))).Clone()

            windll.user32.DestroyIcon(icon_handle)

            self.shown = window.shown
            self.loaded = window.loaded
            self.url = window.url
            self.text_select = window.text_select

            self.is_fullscreen = False
            if window.fullscreen:
                self.toggle_fullscreen()

            if window.frameless:
                self.frameless = window.frameless
                self.FormBorderStyle = 0

            if is_cef:
                CEF.create_browser(window, self.Handle.ToInt32(), BrowserView.alert)
            elif is_edge:
                self.browser = BrowserView.EdgeHTML(self, window)
            else:
                self.browser = BrowserView.MSHTML(self, window)

            self.Shown += self.on_shown
            self.FormClosed += self.on_close

            if is_cef:
                self.Resize += self.on_resize

            if window.confirm_close:
                self.FormClosing += self.on_closing
コード例 #5
0
ファイル: ZgForm.py プロジェクト: DHI/MIKECore-Examples
    def __init__(self):
        self.zgControl = ZgControl()

        self.AutoScaleDimensions = SizeF(6.0, 13.0)
        self.AutoScaleMode = AutoScaleMode.Font
        self.ClientSize = Size(523, 357)
        self.Controls.Add(self.zgControl)
        self.Name = 'ScatterPlot'
        self.Text = 'Scatter Plot'
        self.Resize += self.Form1_Resize
        self.Load += self.Form1_Load
コード例 #6
0
        def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_size,
                     confirm_quit, background_color, debug, js_api, text_select, frameless, webview_ready):
            self.uid = uid
            self.Text = title
            self.ClientSize = Size(width, height)
            self.MinimumSize = Size(min_size[0], min_size[1])
            self.BackColor = ColorTranslator.FromHtml(background_color)

            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            # Application icon
            handle = windll.kernel32.GetModuleHandleW(None)
            icon_handle = windll.shell32.ExtractIconW(handle, sys.executable, 0)

            if icon_handle != 0:
                self.Icon = Icon.FromHandle(IntPtr.op_Explicit(Int32(icon_handle))).Clone()

            windll.user32.DestroyIcon(icon_handle)

            self.webview_ready = webview_ready
            self.load_event = Event()
            self.background_color = background_color
            self.url = url

            self.is_fullscreen = False
            if fullscreen:
                self.toggle_fullscreen()

            if frameless:
                self.frameless = frameless
                self.FormBorderStyle = 0

            if is_cef:
                CEF.create_browser(self.uid, self.Handle.ToInt32(), BrowserView.alert, url, js_api)
            else:
                self._create_mshtml_browser(url, js_api, debug)

            self.text_select = text_select
            self.Shown += self.on_shown
            self.FormClosed += self.on_close

            if is_cef:
                self.Resize += self.on_resize

            if confirm_quit:
                self.FormClosing += self.on_closing
コード例 #7
0
def GetPptImageSize(fileName):
    import clr
    clr.AddReference("System.Drawing")
    from System.Drawing import Image
    from System.Drawing import SizeF

    im = Image.FromFile(fileName)
    sizePx = im.Size
    vertDPI = im.VerticalResolution
    horzDPI = im.HorizontalResolution
    im.Dispose()

    # calculate the actual size of the image in points as this is the unit that
    # PowerPoint uses
    size = SizeF(72.0 * float(sizePx.Width) / horzDPI,
                 72 * float(sizePx.Height) / horzDPI)
    return size
コード例 #8
0
def GetCompositorChainInfo():
    global _debugRttAtlases
    DisposeCompositorChainInfo()
    vp = Client.Instance.Viewport
    chain = CompositorManager.Instance.GetCompositorChain(vp)
    rv = []
    for inst in chain.Instances:
        if inst.Enabled:
            entry = [inst.Name, []]
            for texDef in inst.Technique.TextureDefinitions:
                instName = inst.GetTextureInstanceName(texDef.Name)
                tex = TextureManager.Instance.GetByName(instName)
                atlas = AtlasManager.Instance.CreateAtlas(tex.Name, tex)
                _debugRttAtlases.append(atlas)
                atlas.DefineImage("RttImage", PointF(0, 0),
                                  SizeF(tex.Width, tex.Height))
                entry[1].append([texDef.Name, tex.Name])
            rv.append(entry)
    return rv
コード例 #9
0
        def __init__(self, title, url, width, height, resizable, fullscreen,
                     min_size, confirm_quit, webview_ready):
            self.Text = title
            self.ClientSize = Size(width, height)
            self.MinimumSize = Size(min_size[0], min_size[1])
            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            # Application icon
            try:  # Try loading an icon embedded in the exe file. This will crash when frozen with PyInstaller
                handler = windll.kernel32.GetModuleHandleW(None)
                icon_handler = windll.user32.LoadIconW(handler, 1)
                self.Icon = Icon.FromHandle(
                    IntPtr.op_Explicit(Int32(icon_handler)))
            except:
                pass

            self.webview_ready = webview_ready

            self.web_browser = WinForms.WebBrowser()
            self.web_browser.Dock = WinForms.DockStyle.Fill
            self.web_browser.ScriptErrorsSuppressed = True
            self.web_browser.IsWebBrowserContextMenuEnabled = False

            if url:
                self.web_browser.Navigate(url)

            self.Controls.Add(self.web_browser)
            self.is_fullscreen = False
            self.Shown += self.on_shown

            if confirm_quit:
                self.FormClosing += self.on_closing

            if fullscreen:
                self.toggle_fullscreen()
コード例 #10
0
    def test_sys_drawing(self):
        from IronPythonTest import DaysInt, DaysShort, DaysLong, DaysSByte, DaysByte, DaysUShort, DaysUInt, DaysULong
        from System.Drawing import Point, Size, PointF, SizeF, Rectangle, RectangleF
        x = Point()
        self.assertTrue(x == Point(0, 0))
        x = Size()
        self.assertTrue(x == Size(0, 0))
        x = PointF()
        self.assertTrue(x == PointF(0, 0))
        x = SizeF()
        self.assertTrue(x == SizeF(0, 0))
        x = Rectangle()
        self.assertTrue(x == Rectangle(0, 0, 0, 0))
        x = RectangleF()
        self.assertTrue(x == RectangleF(0, 0, 0, 0))

        p = Point(3, 4)
        s = Size(2, 9)

        q = p + s
        self.assertTrue(q == Point(5, 13))
        self.assertTrue(q != Point(13, 5))
        q = p - s
        self.assertTrue(q == Point(1, -5))
        self.assertTrue(q != Point(0, 4))
        q += s
        self.assertTrue(q == Point(3, 4))
        self.assertTrue(q != Point(2, 4))
        q -= Size(1, 2)
        self.assertTrue(q == Point(2, 2))
        self.assertTrue(q != Point(1))

        t = s
        self.assertTrue(t == s)
        self.assertTrue(t != s - Size(1, 0))
        t += Size(3, 1)
        self.assertTrue(t == Size(5, 10))
        self.assertTrue(t != Size(5, 0))
        t -= Size(2, 8)
        self.assertTrue(t == Size(3, 2))
        self.assertTrue(t != Size(0, 2))
        t = s + Size(-1, -2)
        self.assertTrue(t == Size(1, 7))
        self.assertTrue(t != Size(1, 5))
        t = s - Size(1, 2)
        self.assertTrue(t == Size(1, 7))
        self.assertTrue(t != Size(1, 3))

        def weekdays(enum):
            return enum.Mon | enum.Tue | enum.Wed | enum.Thu | enum.Fri

        def weekend(enum):
            return enum.Sat | enum.Sun

        def enum_helper(enum):
            days = [
                enum.Mon, enum.Tue, enum.Wed, enum.Thu, enum.Fri, enum.Sat,
                enum.Sun
            ]
            x = enum.Mon | enum.Tue | enum.Wed | enum.Thu | enum.Fri | enum.Sat | enum.Sun
            y = enum.Mon
            for day in days:
                y |= day
            self.assertTrue(x == y)
            self.assertFalse(x != y)
            if x == y:  # EqualRetBool
                b = True
            else:
                b = False
            self.assertTrue(b)

            self.assertTrue(x == weekdays(enum) | weekend(enum))
            self.assertTrue(x == (weekdays(enum) ^ weekend(enum)))
            self.assertTrue((weekdays(enum) & weekend(enum)) == enum["None"])
            self.assertTrue(weekdays(enum) == enum.Weekdays)
            self.assertTrue(weekend(enum) == enum.Weekend)
            self.assertTrue(weekdays(enum) != enum.Weekend)
            self.assertTrue(weekdays(enum) != weekend(enum))

        for e in [
                DaysInt, DaysShort, DaysLong, DaysSByte, DaysByte, DaysUShort,
                DaysUInt, DaysULong
        ]:
            enum_helper(e)

        for e in [DaysInt, DaysShort, DaysLong, DaysSByte]:
            z = operator.inv(e.Mon)
            self.assertEqual(type(z), e)
            self.assertEqual(z.ToString(), "-2")

        for (e, v) in [(DaysByte, 254), (DaysUShort, 65534),
                       (DaysUInt, 4294967294),
                       (DaysULong, 18446744073709551614)]:
            z = operator.inv(e.Mon)
            self.assertEqual(type(z), e)
            self.assertEqual(z.ToString(), str(v))

        self.assertRaises(ValueError, lambda: DaysInt.Mon & DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon | DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon ^ DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon & 1)
        self.assertRaises(ValueError, lambda: DaysInt.Mon | 1)
        self.assertRaises(ValueError, lambda: DaysInt.Mon ^ 1)

        def f():
            if DaysInt.Mon == DaysShort.Mon: return True
            return False

        self.assertEqual(f(), False)

        self.assertTrue(not DaysInt.Mon == None)
        self.assertTrue(DaysInt.Mon != None)
コード例 #11
0
        def __init__(self, uid, title, url, width, height, resizable,
                     fullscreen, min_size, confirm_quit, background_color,
                     debug, js_api, text_select, webview_ready):
            self.uid = uid
            self.Text = title
            self.ClientSize = Size(width, height)
            self.MinimumSize = Size(min_size[0], min_size[1])
            self.BackColor = ColorTranslator.FromHtml(background_color)

            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            # Application icon
            handle = windll.kernel32.GetModuleHandleW(None)
            icon_handle = windll.shell32.ExtractIconW(handle, sys.executable,
                                                      0)

            if icon_handle != 0:
                self.Icon = Icon.FromHandle(
                    IntPtr.op_Explicit(Int32(icon_handle))).Clone()

            windll.user32.DestroyIcon(icon_handle)

            self.webview_ready = webview_ready
            self.load_event = Event()

            self.web_browser = WebBrowserEx()
            self.web_browser.Dock = WinForms.DockStyle.Fill
            self.web_browser.ScriptErrorsSuppressed = not debug
            self.web_browser.IsWebBrowserContextMenuEnabled = debug
            self.web_browser.WebBrowserShortcutsEnabled = False
            self.web_browser.DpiAware = True

            self.web_browser.ScriptErrorsSuppressed = not debug
            self.web_browser.IsWebBrowserContextMenuEnabled = debug

            self.js_result_semaphore = Semaphore(0)
            self.js_bridge = BrowserView.JSBridge()
            self.js_bridge.parent_uid = uid
            self.web_browser.ObjectForScripting = self.js_bridge

            self.text_select = text_select

            if js_api:
                self.js_bridge.api = js_api

            # HACK. Hiding the WebBrowser is needed in order to show a non-default background color. Tweaking the Visible property
            # results in showing a non-responsive control, until it is loaded fully. To avoid this, we need to disable this behaviour
            # for the default background color.
            if background_color != '#FFFFFF':
                self.web_browser.Visible = False
                self.first_load = True
            else:
                self.first_load = False

            self.cancel_back = False
            self.web_browser.PreviewKeyDown += self.on_preview_keydown
            self.web_browser.Navigating += self.on_navigating
            self.web_browser.NewWindow3 += self.on_new_window
            self.web_browser.DownloadComplete += self.on_download_complete
            self.web_browser.DocumentCompleted += self.on_document_completed

            if url:
                self.web_browser.Navigate(url)
            else:
                self.web_browser.DocumentText = default_html

            self.url = url

            self.Controls.Add(self.web_browser)
            self.is_fullscreen = False
            self.Shown += self.on_shown
            self.FormClosed += self.on_close

            if confirm_quit:
                self.FormClosing += self.on_closing

            if fullscreen:
                self.toggle_fullscreen()
コード例 #12
0
ファイル: winforms.py プロジェクト: sourabhscd/pywebview
        def __init__(self, window):
            self.uid = window.uid
            self.pywebview_window = window
            self.real_url = None
            self.Text = window.title
            self.Size = Size(window.initial_width, window.initial_height)
            self.MinimumSize = Size(window.min_size[0], window.min_size[1])

            if window.transparent:  # window transparency is not supported, as webviews are not transparent.
                self.BackColor = Color.LimeGreen
                self.TransparencyKey = Color.LimeGreen
                self.SetStyle(
                    WinForms.ControlStyles.SupportsTransparentBackColor, True)
            else:
                self.BackColor = ColorTranslator.FromHtml(
                    window.background_color)

            if window.initial_x is not None and window.initial_y is not None:
                self.move(window.initial_x, window.initial_y)
            else:
                self.StartPosition = WinForms.FormStartPosition.CenterScreen

            self.AutoScaleDimensions = SizeF(96.0, 96.0)
            self.AutoScaleMode = WinForms.AutoScaleMode.Dpi

            if not window.resizable:
                self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
                self.MaximizeBox = False

            if window.minimized:
                self.WindowState = WinForms.FormWindowState.Minimized

            # Application icon
            handle = kernel32.GetModuleHandleW(None)
            icon_handle = windll.shell32.ExtractIconW(handle, sys.executable,
                                                      0)

            if icon_handle != 0:
                self.Icon = Icon.FromHandle(
                    IntPtr.op_Explicit(Int32(icon_handle))).Clone()

            windll.user32.DestroyIcon(icon_handle)

            self.closed = window.closed
            self.closing = window.closing
            self.shown = window.shown
            self.loaded = window.loaded
            self.url = window.real_url
            self.text_select = window.text_select
            self.on_top = window.on_top

            self.is_fullscreen = False
            if window.fullscreen:
                self.toggle_fullscreen()

            if window.frameless:
                self.frameless = window.frameless
                self.FormBorderStyle = 0
            if is_cef:
                CEF.create_browser(window, self.Handle.ToInt32(),
                                   BrowserView.alert)
            elif is_chromium:
                self.browser = Chromium.EdgeChrome(self, window)
            elif is_edge:
                self.browser = Edge.EdgeHTML(self, window)
            else:
                self.browser = IE.MSHTML(self, window)

            self.Shown += self.on_shown
            self.FormClosed += self.on_close
            self.FormClosing += self.on_closing

            if is_cef:
                self.Resize += self.on_resize