Afficher la date ...

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Simon
Messages : 25
Inscription : jeu. 24/févr./2005 20:30

Afficher la date ...

Message par Simon »

Bonjour tout le monde !!!

Voila moi je voudrais afficher la date. Je sai le faire mais je voudrais quelle change avec l'heure actuel : quelles soient syncro... :P

c'est tous :oops: mais j'y arrive pas .... :(

Merci ++ à tous
fweil
Messages : 505
Inscription : dim. 16/mai/2004 17:50
Localisation : Bayonne (64)
Contact :

Message par fweil »

Voici une version texte :

Code : Tout sélectionner

Enumeration
  #Window_Main
  #Gadget_String
EndEnumeration

Dim Days.s(6)

Procedure.s DateToString()
  ProcedureReturn "Nous sommes le " + Days(DayOfWeek(Date())) + " " + FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss", Date())
EndProcedure

  For i = 0 To 6
    Read Days(i)
  Next
  WindowWidth = 280
  WindowHeight = 120
  If OpenWindow(#Window_Main, 0, 0, WindowWidth, WindowHeight, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
      AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      If CreateGadgetList(WindowID(#Window_Main))
          StringGadget(#Gadget_String, 10, 10, 260, 20, DateToString())
      EndIf
      Quit = #FALSE
      Repeat
        SetGadgetText(#Gadget_String, DateToString())
        Delay(10)
      Until WindowEvent() = #PB_Event_CloseWindow Or EventMenuID() = #PB_Shortcut_Escape
  EndIf
End

DataSection
  Data.s "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"
EndDataSection
et une version graphique

Code : Tout sélectionner

  TwoPi.f = 2 * 3.14159265
  kPi.f = TwoPi / 360
  PiTwo.f = TwoPi / 4
  Width.f = 200.0
  Height.f = 200.0
  XC.f = Width / 2
  YC.f = Height / 2
  Coeff.f = 1.01
  If OpenWindow(0, 0, 0, Width, Height, #PB_Window_BorderLess | #PB_Window_ScreenCentered, "Clock")
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      AddKeyboardShortcut(0, #PB_Shortcut_Left, #PB_Shortcut_Left)
      AddKeyboardShortcut(0, #PB_Shortcut_Right, #PB_Shortcut_Right)
      If CreateGadgetList(WindowID(0))
          ImageGadget(0, 0, 0, Width, Height, ImageID)
      EndIf
      Quit = #FALSE
      Repeat
        ImageID = CreateImage(0, Width, Height)
        StartDrawing(ImageOutput())
          Box(0, 0, Width, Height, $400000)
          DrawingMode(4)
          Circle(XC, YC, Width / 2, #White)
          DrawingMode(1)
          For i = 0 To 360 Step 6
            LineXY(XC + Width * 0.47 * Cos(kPi * i), YC + Height * 0.47 * Sin(kPi * i), XC + Width * 0.49 * Cos(kPi * i), YC + Height * 0.49 * Sin(kPi * i), #White)
          Next
          For i = 0 To 360 Step 30
            LineXY(XC + Width * 0.43 * Cos(kPi * i), YC + Height * 0.43 * Sin(kPi * i), XC + Width * 0.49 * Cos(kPi * i), YC + Height * 0.49 * Sin(kPi * i), #White)
          Next
          ThisSeco.f = Second(Date())
          ASeco.f = TwoPi * ThisSeco / 60 - PiTwo
          ThisMinu.f = Minute(Date()) + ThisSeco / 60
          AMinu.f = TwoPi * ThisMinu / 60 - PiTwo
          ThisHour.f = Hour(Date()) + ThisMinu / 60
          If ThisHour > 12
              ThisHour = ThisHour - 12
          EndIf
          AHour.f = TwoPi * ThisHour / 12 - PiTwo
          LineXY(XC, YC, XC + Width * 0.30 * Cos(AHour), YC + Height * 0.30 * Sin(AHour), #Green)
          LineXY(XC, YC, XC + Width * 0.40 * Cos(AMinu), YC + Height * 0.40 * Sin(AMinu), #Blue)
          LineXY(XC, YC, XC + Width * 0.35 * Cos(ASeco), YC + Height * 0.35 * Sin(ASeco), #Red)
        StopDrawing()
        SetGadgetState(0, ImageID)
        Delay(20)
        Select WindowEvent()
          Case #PB_Event_CloseWindow
            Quit = #TRUE
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
              Case #PB_Shortcut_Left
                Width / Coeff
                Height / Coeff
                If Width < 25 Or Height < 25
                    Width = 25 : Height = 25
                EndIf
                XC = Width / 2
                YC = Height / 2
                ResizeWindow(Width, Height)
                MoveWindow((GetSystemMetrics_(#SM_CXSCREEN) - Width) / 2, (GetSystemMetrics_(#SM_CYSCREEN) - Height) / 2)
                ImageGadget(0, 0, 0, Width, Height, ImageID)
              Case #PB_Shortcut_Right
                Width * Coeff
                Height * Coeff
                If Width > 800 Or Height > 800
                    Width = 800 : Height = 800
                EndIf
                XC = Width / 2
                YC = Height / 2
                ResizeWindow(Width, Height)
                MoveWindow((GetSystemMetrics_(#SM_CXSCREEN) - Width) / 2, (GetSystemMetrics_(#SM_CYSCREEN) - Height) / 2)
                ImageGadget(0, 0, 0, Width, Height, ImageID)
            EndSelect
        EndSelect
      Until Quit
  EndIf
End
Mon avatar reproduit l'image de 4x1.8m présentée au 'Salon international du meuble de Paris' en janvier 2004, dans l'exposition 'Shades' réunisant 22 créateurs autour de Matt Sindall. L'original est un stratifié en 150 dpi.
fweil
Messages : 505
Inscription : dim. 16/mai/2004 17:50
Localisation : Bayonne (64)
Contact :

Message par fweil »

J'avais a aussi qui est mignon

Code : Tout sélectionner

;
; 7 segments LED clock (see 7 segments LED.pb for more comments)
; F.Weil 20050329
;

Enumeration
  #Window_Main
EndEnumeration

Dim LED7Code.l(31)

Procedure Digit(Number.l, Rank.l, Base.l)
  Divide.l = Pow(Base, Rank)
  ProcedureReturn (Number / Divide)% Base
EndProcedure

Procedure LEDSegment(x1.l, y1.l, x2.l, y2.l, Color.l)
  If x2 => y2
      Circle(x1, y1 + y2 / 2, y2 / 2, Color) : Circle(x1 + x2, y1 + y2 / 2, y2 / 2, Color) : Box(x1, y1, x2, y2, Color)
    Else
      Circle(x1 + x2 / 2, y1, x2 / 2, Color) : Circle(x1 + x2 / 2, y1 + y2, x2 / 2, Color) : Box(x1, y1, x2, y2, Color)
  EndIf
EndProcedure

Procedure LED7(Digit.l, Color.l, ImageNumber.l, Width.l, Height.l)
  ImageID = CreateImage(ImageNumber, Width, Height)
  StartDrawing(ImageOutput())
    Box(0, 0, Width, Height, $400000)
    Value = LED7Code(Digit)
    If Value & 1 : LEDSegment(10 * Width / 100, 0 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
    If Value & 2 : LEDSegment(90 * Width / 100, 7 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
    If Value & 4 : LEDSegment(90 * Width / 100, 52 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
    If Value & 8 : LEDSegment(10 * Width / 100, 95 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
    If Value & 16 : LEDSegment(0 * Width / 100, 52 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
    If Value & 32 : LEDSegment(0 * Width / 100, 7 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
    If Value & 64 : LEDSegment(10 * Width / 100, 48 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
    If Value & 128 : Circle(105 * Width / 100, 185 * Height / 200, 5 * Height / 200, Color) : EndIf
  StopDrawing()
  ProcedureReturn ImageID
EndProcedure

  Dim ImageIDs(20)
  
  MaxRank = 18
  DigitWidth = 50
  DigitHeight = 100
  For i = 0 To 15
    Read LED7Code(i)
  Next
  If OpenWindow(#Window_Main, 0, 0, (DigitWidth + 2) * (MaxRank + 1), DigitHeight, 0, "")
      AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      Quit = #FALSE
      Repeat
        Select WindowEvent()
          Case #PB_Event_CloseWindow
            Quit = #TRUE
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
        EndSelect
        Now.s = FormatDate("%yyyy %mm %dd %hh %ii %ss", Date())
        For i = 1 To Len(Now)
          If Mid(Now, i, 1) => "0" And Mid(Now, i, 1) <= "9"
              ImageIDs(i) = LED7(Digit(Val(Mid(Now, i, 1)), 0, 10), $4040FF, i, DigitWidth, DigitHeight)
            Else
              ImageIDs(i) = CreateImage(i, DigitWidth, DigitHeight)
          EndIf
        Next
        ImageID = CreateImage(485, WindowWidth(), WindowHeight())
        StartDrawing(ImageOutput())
          Box(0, 0, WindowWidth(), WindowHeight(), $400000)
          For i = 1 To Len(Now)
            DrawImage(ImageIDs(i), (i - 1) * (DigitWidth + 2), 0)
          Next
        StopDrawing()
        StartDrawing(WindowOutput())
          DrawImage(ImageID, 0, 0)
        StopDrawing()
        Delay(1)
      Until Quit
      CloseWindow(0)
  EndIf
End

DataSection
LED7CodeData:
  Data.l 63, 6, 91, 79, 102, 109, 125, 7, 127, 111, 119, 124, 57, 94, 121, 113, 63, 6, 91, 79, 102, 109, 125, 7, 127, 111, 119, 124, 57, 94, 121, 113
EndDataSection
Mon avatar reproduit l'image de 4x1.8m présentée au 'Salon international du meuble de Paris' en janvier 2004, dans l'exposition 'Shades' réunisant 22 créateurs autour de Matt Sindall. L'original est un stratifié en 150 dpi.
Simon
Messages : 25
Inscription : jeu. 24/févr./2005 20:30

Message par Simon »

Merci mais il n'y a que la version texte qui m'intéresse .
Mais un détail me chagrine : j'ai remplacé ton stirnggadget par un textgadget
et lorce que le date change : elle n'est pas très net .
C'est comme des clignotements très rapides, très brefs .( une sorte le ligne qui vient couper la date tout vite ).

Code : Tout sélectionner

Enumeration
  #Window_Main
  #Gadget_String
EndEnumeration

Dim Days.s(6)

Procedure.s DateToString()
  ProcedureReturn "Nous sommes le " + Days(DayOfWeek(Date())) + " " + FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss", Date())
EndProcedure

  For i = 0 To 6
    Read Days(i)
  Next
  WindowWidth = 280
  WindowHeight = 120
  If OpenWindow(#Window_Main, 0, 0, WindowWidth, WindowHeight, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
      AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      If CreateGadgetList(WindowID(#Window_Main))
          TextGadget(#Gadget_String, 10, 10, 260, 20, DateToString()) 
      EndIf
      Quit = #FALSE
      Repeat
        SetGadgetText(#Gadget_String, DateToString())
        Delay(10)
      Until WindowEvent() = #PB_Event_CloseWindow Or EventMenuID() = #PB_Shortcut_Escape
  EndIf
End

DataSection
  Data.s "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"
EndDataSection 
Regarde plus :P ...
fweil
Messages : 505
Inscription : dim. 16/mai/2004 17:50
Localisation : Bayonne (64)
Contact :

Message par fweil »

Sur mon PC je n'ai pas cet effet de scintillement.

Celà peut être du aux performances de la machine sur laquelle tu exécutes le programme.

Peut être qu'en mettant un delai plus long l'effet diminue (en laissant plus de temps à la CPU pour faire son travail) ?
Mon avatar reproduit l'image de 4x1.8m présentée au 'Salon international du meuble de Paris' en janvier 2004, dans l'exposition 'Shades' réunisant 22 créateurs autour de Matt Sindall. L'original est un stratifié en 150 dpi.
Simon
Messages : 25
Inscription : jeu. 24/févr./2005 20:30

Message par Simon »

en effet cela change "un peu selement".

Mais moi qui débute je comprend pas tous les trucs que tu fais pour afficher la date ..... :?

Pourais tu m'écrairé un peu .... stp :lol:

Merc i ++ fweil :D
Simon
Messages : 25
Inscription : jeu. 24/févr./2005 20:30

Message par Simon »

Simon a écrit :en effet cela change "un peu selement".

Mais moi qui débute je comprend pas tous les trucs que tu fais pour afficher la date ..... :?

Pourais tu m'écrairé un peu .... stp :lol:

Merc i ++ fweil :D

PS:mais tu as bien remplacé le string par un textgadget ?
et pourais tu me donner les config de ton pc stp . merci .
Simon
Messages : 25
Inscription : jeu. 24/févr./2005 20:30

Message par Simon »

Je c pas se que j'ai fait au dessus mais c'est un bon merdier

pardon :lol:
Répondre