Changeset 3385795 in sasview for guiframe


Ignore:
Timestamp:
Feb 2, 2011 2:18:35 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
2096e78
Parents:
1767884
Message:

add splascreen and resize the frame at init

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/gui_manager.py

    r7bc88bf r3385795  
    5151PLOPANEL_WIDTH = 400 
    5252PLOPANEL_HEIGTH = 400 
    53  
     53GUIFRAME_WIDTH = 1000 
     54GUIFRAME_HEIGHT = 800 
    5455 
    5556class ViewerFrame(wx.Frame): 
     
    5859    """ 
    5960     
    60     def __init__(self, parent, id, title,  
    61                  window_height=300, window_width=300, 
    62                  gui_style=GUIFRAME.DEFAULT_STYLE): 
     61    def __init__(self, parent, title,  
     62                 size=(GUIFRAME_WIDTH,GUIFRAME_HEIGHT), 
     63                 gui_style=GUIFRAME.DEFAULT_STYLE,  
     64                 pos=wx.DefaultPosition): 
    6365        """ 
    6466        Initialize the Frame object 
    6567        """ 
    6668         
    67         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
    68                           size=(window_width, window_height)) 
     69        wx.Frame.__init__(self, parent=parent, title=title, pos=pos,size=size) 
    6970        # Preferred window size 
    70         self._window_height = window_height 
    71         self._window_width  = window_width 
     71        self._window_width, self._window_height = size 
    7272        self.__gui_style = gui_style 
    7373         
     
    12361236    CENTER_PANE = True 
    12371237 
    1238    
     1238PROG_SPLASH_SCREEN = "images/danse_logo.png"  
    12391239# Toy application to test this Frame 
    12401240class ViewApp(wx.App): 
    12411241    """ 
    12421242    """ 
     1243    SIZE = (GUIFRAME_WIDTH,GUIFRAME_HEIGHT) 
     1244    TITLE = config.__appname__ 
     1245    PROG_SPLASH_PATH = PROG_SPLASH_SCREEN 
     1246    STYLE = GUIFRAME.DEFAULT_STYLE 
    12431247    def OnInit(self): 
    12441248        """ 
    12451249        """ 
    1246         self.frame = ViewerFrame(None, -1, config.__appname__)     
     1250        pos, size = self.window_placement(self.SIZE) 
     1251        self.frame = ViewerFrame(parent=None,  
     1252                                 title=self.TITLE,  
     1253                                 pos=pos,  
     1254                                 gui_style = self.STYLE, 
     1255                                 size=size)  
     1256         # Display a splash screen on top of the frame. 
     1257        if len(sys.argv) > 1 and '--time' in sys.argv[1:]: 
     1258            log_time("Starting to display the splash screen") 
     1259        if self.PROG_SPLASH_PATH is not None and \ 
     1260            os.path.isfile(self.PROG_SPLASH_PATH): 
     1261            try: 
     1262                self.display_splash_screen(parent=self.frame, path=self.PROG_SPLASH_PATH)    
     1263            except: 
     1264                msg = "Cannot display splash screen\n" 
     1265                msg += str (sys.exc_value) 
     1266                logging.error(msg) 
    12471267        self.frame.Show(True) 
    12481268 
     
    12801300        """ 
    12811301        self.frame.add_perspective(perspective) 
     1302     
     1303    def window_placement(self, size): 
     1304        """ 
     1305        Determines the position and size of the application frame such that it 
     1306        fits on the user's screen without obstructing (or being obstructed by) 
     1307        the Windows task bar.  The maximum initial size in pixels is bounded by 
     1308        WIDTH x HEIGHT.  For most monitors, the application 
     1309        will be centered on the screen; for very large monitors it will be 
     1310        placed on the left side of the screen. 
     1311        """ 
     1312        window_width, window_height = size 
     1313        screen_size = wx.GetDisplaySize() 
     1314        window_height = window_height if screen_size[1]>window_height else screen_size[1]-50 
     1315        window_width  = window_width if screen_size[0]> window_width else screen_size[0]-50 
     1316        xpos = ypos = 0 
     1317 
     1318        # Note that when running Linux and using an Xming (X11) server on a PC 
     1319        # with a dual  monitor configuration, the reported display size may be 
     1320        # that of both monitors combined with an incorrect display count of 1. 
     1321        # To avoid displaying this app across both monitors, we check for 
     1322        # screen 'too big'.  If so, we assume a smaller width which means the 
     1323        # application will be placed towards the left hand side of the screen. 
     1324 
     1325        _, _, x, y = wx.Display().GetClientArea() # size excludes task bar 
     1326        if len(sys.argv) > 1 and '--platform' in sys.argv[1:]: 
     1327            w, h = wx.DisplaySize()  # size includes task bar area 
     1328            print "*** Reported screen size including taskbar is %d x %d"%(w, h) 
     1329            print "*** Reported screen size excluding taskbar is %d x %d"%(x, y) 
     1330 
     1331        if x > 1920: x = 1280  # display on left side, not centered on screen 
     1332        if x > window_width:  xpos = (x - window_width)/2 
     1333        if y > window_height: ypos = (y - window_height)/2 
     1334 
     1335        # Return the suggested position and size for the application frame. 
     1336        return (xpos, ypos), (min(x, window_width), min(y, window_height)) 
     1337     
     1338    def display_splash_screen(self, parent, path=PROG_SPLASH_SCREEN): 
     1339        """Displays the splash screen.  It will exactly cover the main frame.""" 
     1340 
     1341        # Prepare the picture.  On a 2GHz intel cpu, this takes about a second. 
     1342        x, y = parent.GetSizeTuple() 
     1343        image = wx.Image(path, wx.BITMAP_TYPE_PNG) 
     1344        image.Rescale(x, y, wx.IMAGE_QUALITY_HIGH) 
     1345        bm = image.ConvertToBitmap() 
     1346 
     1347        # Create and show the splash screen.  It will disappear only when the 
     1348        # program has entered the event loop AND either the timeout has expired 
     1349        # or the user has left clicked on the screen.  Thus any processing 
     1350        # performed in this routine (including sleeping) or processing in the 
     1351        # calling routine (including doing imports) will prevent the splash 
     1352        # screen from disappearing. 
     1353        # 
     1354        # Note that on Linux, the timeout appears to occur immediately in which 
     1355        # case the splash screen disappears upon entering the event loop. 
     1356        wx.SplashScreen(bitmap=bm, 
     1357                        splashStyle=(wx.SPLASH_CENTRE_ON_PARENT| 
     1358                                     wx.SPLASH_TIMEOUT| 
     1359                                     wx.STAY_ON_TOP), 
     1360                        milliseconds=4000, 
     1361                        parent=parent, 
     1362                        id=wx.ID_ANY) 
     1363 
     1364        # Keep the splash screen up a minimum amount of time for non-Windows 
     1365        # systems.  This is a workaround for Linux and possibly MacOS that 
     1366        # appear to ignore the splash screen timeout option. 
     1367        if '__WXMSW__' not in wx.PlatformInfo: 
     1368            if len(sys.argv) > 1 and '--time' in sys.argv[1:]: 
     1369                log_time("Starting sleep of 2 secs") 
     1370            time.sleep(2) 
     1371 
     1372        # A call to wx.Yield does not appear to be required.  If used on 
     1373        # Windows, the cursor changes from 'busy' to 'ready' before the event 
     1374        # loop is reached which is not desirable.  On Linux it seems to have 
     1375        # no effect. 
     1376        #wx.Yield() 
     1377 
    12821378         
    12831379 
Note: See TracChangeset for help on using the changeset viewer.