Module: RUtilAnts::GUI
- Defined in:
- lib/rUtilAnts/GUI.rb,
lib/rUtilAnts/GUI/BugReportDialog.rb
Defined Under Namespace
Classes: BitmapProgressDialog, BugReportDialog, ImageListManager, ProgressDialog, SafeTimersManager, TextProgressDialog
Class Method Summary collapse
-
.initializeGUI ⇒ Object
Initialize the GUI methods in the Object namespace.
Instance Method Summary collapse
-
#getBitmapFromURL(iFileName, iIconIndex = nil, iBitmapTypes = nil) ⇒ Object
Get a bitmap/icon from a URL.
-
#getResizedBitmap(iBitmap, iWidth, iHeight) ⇒ Object
Get a bitmap resized to a given size if it differs from it.
-
#safeTimerAfter(ioSafeTimersManager, iElapsedTime) ⇒ Object
Execute some code after some elapsed time.
-
#safeTimerEvery(ioSafeTimersManager, iElapsedTime) ⇒ Object
Execute some code every some elapsed time.
-
#setupBitmapProgress(iParentWindow, iBitmap, iParameters = {}, &iCodeToExecute) ⇒ Object
Setup a progress bar with some bitmap in it and call code around it.
-
#setupTextProgress(iParentWindow, iText, iParameters = {}, &iCodeToExecute) ⇒ Object
Setup a progress bar with some text in it and call code around it.
-
#showModal(iDialogClass, iParentWindow, *iParameters) {|lModalResult, lDialog| ... } ⇒ Object
Display a dialog in modal mode, ensuring it is destroyed afterwards.
Class Method Details
.initializeGUI ⇒ Object
Initialize the GUI methods in the Object namespace
381 382 383 |
# File 'lib/rUtilAnts/GUI.rb', line 381 def self.initializeGUI Object.module_eval('include RUtilAnts::GUI') end |
Instance Method Details
#getBitmapFromURL(iFileName, iIconIndex = nil, iBitmapTypes = nil) ⇒ Object
Get a bitmap/icon from a URL. If no type has been provided, it detects the type of icon based on the file extension. Use URL caching.
Parameters:
-
iFileName (String): The file name
-
iIconIndex (Integer): Specify the icon index (used by Windows for EXE/DLL/ICO…) [optional = nil]
-
iBitmapTypes (Integer or list<Integer>): Bitmap/Icon type. Can be nil for autodetection. Can be the list of types to try. [optional = nil]
Return:
-
Wx::Bitmap: The bitmap, or nil in case of failure
-
Exception: The exception containing details about the error, or nil in case of success
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/rUtilAnts/GUI.rb', line 446 def getBitmapFromURL(iFileName, iIconIndex = nil, iBitmapTypes = nil) rReadBitmap = nil rReadError = nil rReadBitmap, rReadError = getURLContent(iFileName, :LocalFileAccess => true) do |iRealFileName| rBitmap = nil rError = nil lBitmapTypesToTry = iBitmapTypes if (iBitmapTypes == nil) # Autodetect lBitmapTypesToTry = [ Wx::Bitmap::BITMAP_TYPE_GUESS[File.extname(iRealFileName).downcase[1..-1]] ] if (lBitmapTypesToTry == [ nil ]) # Here we handle extensions that wxruby is not aware of case File.extname(iRealFileName).upcase when '.CUR', '.ANI', '.EXE', '.DLL' lBitmapTypesToTry = [ Wx::BITMAP_TYPE_ICO ] else logErr "Unable to determine the bitmap type corresponding to extension #{File.extname(iRealFileName).upcase}. Assuming ICO." lBitmapTypesToTry = [ Wx::BITMAP_TYPE_ICO ] end end elsif (!iBitmapTypes.is_a?(Array)) lBitmapTypesToTry = [ iBitmapTypes ] end # Try each type lBitmapTypesToTry.each do |iBitmapType| # Special case for the ICO type if (iBitmapType == Wx::BITMAP_TYPE_ICO) lIconID = iRealFileName if ((iIconIndex != nil) and (iIconIndex != 0)) # TODO: Currently this implementation does not work. Uncomment when ok. #lIconID += ";#{iIconIndex}" end rBitmap = Wx::Bitmap.new begin rBitmap.copy_from_icon(Wx::Icon.new(lIconID, Wx::BITMAP_TYPE_ICO)) rescue Exception rError = $! rBitmap = nil end else rBitmap = Wx::Bitmap.new(iRealFileName, iBitmapType) end if (rBitmap != nil) if (rBitmap.is_ok) break else # File seems to be corrupted rError = RuntimeError.new("Bitmap #{iFileName} is corrupted.") rBitmap = nil end else rBitmap = nil end end return rBitmap, rError end # Check if it is ok and the error set correctly if ((rReadBitmap == nil) and (rReadError == nil)) rError = RuntimeError.new("Unable to get bitmap from #{iFileName}") end return rReadBitmap, rReadError end |
#getResizedBitmap(iBitmap, iWidth, iHeight) ⇒ Object
Get a bitmap resized to a given size if it differs from it
Parameters:
-
iBitmap (Wx::Bitmap): The original bitmap
-
iWidth (Integer): The width of the resized bitmap
-
iHeight (Integer): The height of the resized bitmap
Return:
-
Wx::Bitmap: The resized bitmap (can be the same object as iBitmap)
393 394 395 396 397 398 399 400 401 402 |
# File 'lib/rUtilAnts/GUI.rb', line 393 def getResizedBitmap(iBitmap, iWidth, iHeight) rResizedBitmap = iBitmap if ((iBitmap.width != iWidth) or (iBitmap.height != iHeight)) rResizedBitmap = Wx::Bitmap.new(iBitmap.convert_to_image.scale(iWidth, iHeight)) end return rResizedBitmap end |
#safeTimerAfter(ioSafeTimersManager, iElapsedTime) ⇒ Object
Execute some code after some elapsed time.
Parameters:
-
ioSafeTimersManager (SafeTimersManager): The manager that handles this SafeTimer
-
iElapsedTime (Integer): The elapsed time to wait before running the code
-
CodeBlock: The code to execute
550 551 552 553 554 555 556 557 558 559 |
# File 'lib/rUtilAnts/GUI.rb', line 550 def safeTimerAfter(ioSafeTimersManager, iElapsedTime) # Create the Timer and register it lTimer = nil lTimer = Wx::Timer.after(iElapsedTime) do yield # Now the Timer can be safely destroyed. ioSafeTimersManager.unregisterTimer(lTimer) end ioSafeTimersManager.registerTimer(lTimer) end |
#safeTimerEvery(ioSafeTimersManager, iElapsedTime) ⇒ Object
Execute some code every some elapsed time.
Parameters:
-
ioSafeTimersManager (SafeTimersManager): The manager that handles this SafeTimer
-
iElapsedTime (Integer): The elapsed time to wait before running the code
-
CodeBlock: The code to execute
567 568 569 570 571 572 573 |
# File 'lib/rUtilAnts/GUI.rb', line 567 def safeTimerEvery(ioSafeTimersManager, iElapsedTime) # Create the Timer and register it lTimer = Wx::Timer.every(iElapsedTime) do yield end ioSafeTimersManager.registerTimer(lTimer) end |
#setupBitmapProgress(iParentWindow, iBitmap, iParameters = {}, &iCodeToExecute) ⇒ Object
Setup a progress bar with some bitmap in it and call code around it
Parameters:
-
iParentWindow (Wx::Window): The parent window
-
iBitmap (Wx::Bitmap): The bitmap to display
-
iParameters (map<Symbol,Object>): Additional parameters (check RUtilAnts::GUI::ProgressDialog#initialize documentation):
-
CodeBlock: The code called with the progress bar created:
** ioProgressDlg (RUtilAnts::GUI::ProgressDialog): The progress dialog
538 539 540 541 542 |
# File 'lib/rUtilAnts/GUI.rb', line 538 def setupBitmapProgress(iParentWindow, iBitmap, iParameters = {}, &iCodeToExecute) showModal(BitmapProgressDialog, iParentWindow, iCodeToExecute, iBitmap, iParameters) do |iModalResult, iDialog| # Nothing to do end end |
#setupTextProgress(iParentWindow, iText, iParameters = {}, &iCodeToExecute) ⇒ Object
Setup a progress bar with some text in it and call code around it
Parameters:
-
iParentWindow (Wx::Window): The parent window
-
iText (String): The text to display
-
iParameters (map<Symbol,Object>): Additional parameters (check RUtilAnts::GUI::ProgressDialog#initialize documentation):
-
CodeBlock: The code called with the progress bar created:
** ioProgressDlg (RUtilAnts::GUI::ProgressDialog): The progress dialog
524 525 526 527 528 |
# File 'lib/rUtilAnts/GUI.rb', line 524 def setupTextProgress(iParentWindow, iText, iParameters = {}, &iCodeToExecute) showModal(TextProgressDialog, iParentWindow, iCodeToExecute, iText, iParameters) do |iModalResult, iDialog| # Nothing to do end end |
#showModal(iDialogClass, iParentWindow, *iParameters) {|lModalResult, lDialog| ... } ⇒ Object
Display a dialog in modal mode, ensuring it is destroyed afterwards.
Parameters:
-
iDialogClass (class): Class of the dialog to display
-
iParentWindow (Wx::Window): Parent window (can be nil)
-
iParameters (…): List of parameters to give the constructor
-
CodeBlock: The code called once the dialog has been displayed and modally closed
** iModalResult (Integer): Modal result ** iDialog (Wx::Dialog): The dialog
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/rUtilAnts/GUI.rb', line 413 def showModal(iDialogClass, iParentWindow, *iParameters) # If the parent is nil, we fall into a buggy behaviour in the case of GC enabled: # * If we destroy the window after show_modal, random core dumps occur in the application # * If not, the application can't exit normally # Therefore, in case of nil, we assign the top window as the parent. # Sometimes, there is no top_window. So we'll stick with nil. lParentWindow = iParentWindow if (lParentWindow == nil) lParentWindow = Wx.get_app.get_top_window end lDialog = iDialogClass.new(lParentWindow, *iParameters) lDialog.centre(Wx::CENTRE_ON_SCREEN|Wx::BOTH) lModalResult = lDialog.show_modal yield(lModalResult, lDialog) # If we destroy windows having parents, we get SegFaults during execution when mouse hovers some toolbar icons and moves (except if we disable GC: in this case it works perfectly fine, but consumes tons of memory). # If we don't destroy, we got ObjectPreviouslyDeleted exceptions on exit with wxRuby 2.0.0 (seems to have disappeared in 2.0.1). # TODO (wxRuby): Correct bug on Tray before enabling GC and find the good solution for modal destruction. if (lParentWindow == nil) lDialog.destroy end end |